report by day ok

This commit is contained in:
Tykayn 2022-07-20 16:56:17 +02:00 committed by tykayn
parent aeed94e3dc
commit d2d3f32c8a
2 changed files with 127 additions and 12 deletions

135
app.js
View File

@ -1,7 +1,8 @@
const fs = require('node-fs') const fs = require('node-fs')
const sourceFilePath = 'source/tasks.json'; const sourceFilePath = 'source/tasks.json';
const statsMonth = { const stats = {
count: 0 countAllTasks: 0,
tasksByDay: {}
} }
// prendre le json source représentant les tâches DONE // prendre le json source représentant les tâches DONE
console.log(' ### lecture de source/emacs_json.json'); console.log(' ### lecture de source/emacs_json.json');
@ -19,22 +20,61 @@ fs.stat(sourceFilePath, function (err, stat) {
}); });
// parcourir les tâches // parcourir les tâches
function sortTasksFromJson(statObject){ function sortTasksFromJson(statObject) {
console.log('sortTasksFromJson') console.log('sortTasksFromJson')
fs.readFile(sourceFilePath, 'utf8', function (err,data) { fs.readFile(sourceFilePath, 'utf8', function (err, data) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
let dataTransformed = JSON.parse(data); let dataTransformed = JSON.parse(data);
console.log('data keys ', Object.keys(dataTransformed)) console.log('data keys ', Object.keys(dataTransformed))
if(dataTransformed["contents"]){ if (dataTransformed["contents"]) {
countTasks = dataTransformed["contents"].length countTasks = dataTransformed["contents"].length
console.log('yes data !' , countTasks) stats.countAllTasks = countTasks;
console.log('element' , dataTransformed["contents"]["0"])
console.log('yes data !', countTasks)
console.log('first', dataTransformed["contents"][0])
dataTransformed["contents"].forEach((elem) => {
if (elem['title'] && elem['title'][0]) {
console.log(' - ', elem['title'][0])
}
if (elem['properties'] && elem['properties']['closed']) {
let title = elem['properties']['raw-value'];
let tags = elem['tags'] ? elem['tags'] : [];
let closeDate = elem['properties']['closed']['end'];
let todoKeyword = elem['drawer']['ARCHIVE_TODO'];
let itags = elem['drawer']['ARCHIVE_ITAGS'];
// jour, 11 premiers caractères
let day = closeDate.substring(0, 10);
if (!stats.tasksByDay[day]) {
stats.tasksByDay[day] = []
}
stats.tasksByDay[day].push({
title,
closeDate,
tags,
todoKeyword,
day,
itags
})
// console.log(' ' + title)
} else {
console.log('no' , elem['properties']['raw-value'])
}
})
// console.log('element', dataTransformed["contents"]["0"])
} else {
console.log('no content')
} }
// console.log(data); // console.log(data);
writeHtmlOutput()
}); });
@ -43,6 +83,81 @@ function sortTasksFromJson(statObject){
// sortir un html présentant les périodes de temps et les tâches réalisées // sortir un html présentant les périodes de temps et les tâches réalisées
function writeHtmlOutput(){ function writeHtmlOutput() {
console.log('writeHtmlOutput') console.log('writeHtmlOutput', stats.countAllTasks)
let daysListRef = Object.keys(stats.tasksByDay).sort()
let htmlOut = `
<html>
<head>
<title>
Rapport d'activité
</title>
<meta charset="UTF-8" />
<style>
@import "https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css";
</style>
</head>
<body>
<div id="report_days" class="container content">
`
daysListRef.forEach((dayRefString) => {
let tasksOfTheDay = '';
stats.tasksByDay[dayRefString].forEach((dayObj) => {
tasksOfTheDay += ` <li>
<h2 class="subtitle is-1">
<span class="keyword"> ${dayObj.todoKeyword}</span>
<span class="title"> ${dayObj.title} </span>
</h2>
<p class="tags">
${dayObj.itags}
</p>
</li>`
})
htmlOut += `
<h1 class="title is-1">
<span class="day-ref">
${dayRefString}
</span>
<span class="counter pull-right badge">
${stats.tasksByDay[dayRefString].length}
</span>
</h1>
<div class="day-detail">
<ul>
${tasksOfTheDay}
</ul>
</div>
`
})
htmlOut += `
</div>
</body>
</html>
`
fs.writeFile('output/output.json', JSON.stringify(stats), function (err, data) {
if (err) {
return console.log(err);
}
console.log('wrote output json', data)
})
fs.writeFile('output/output.html', htmlOut, function (err, data) {
if (err) {
return console.log(err);
}
console.log('wrote output html', data)
})
}
function sortObj(obj) {
return Object.keys(obj).sort().reduce(function (result, key) {
result[key] = obj[key];
return result;
}, {});
} }

View File

@ -4,6 +4,6 @@
"nodemon": "^2.0.19" "nodemon": "^2.0.19"
}, },
"scripts" : { "scripts" : {
"start" : "nodemon app.js" "start" : "node app.js"
} }
} }