From d2d3f32c8ad694ca5a8d69fe6a586ff5f2f0a806 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 20 Jul 2022 16:56:17 +0200 Subject: [PATCH] report by day ok --- app.js | 137 ++++++++++++++++++++++++++++++++++++++++++++++----- package.json | 2 +- 2 files changed, 127 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 80f18e5..a61c53d 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,8 @@ const fs = require('node-fs') const sourceFilePath = 'source/tasks.json'; -const statsMonth = { - count: 0 +const stats = { + countAllTasks: 0, + tasksByDay: {} } // prendre le json source représentant les tâches DONE console.log(' ### lecture de source/emacs_json.json'); @@ -19,22 +20,61 @@ fs.stat(sourceFilePath, function (err, stat) { }); // parcourir les tâches -function sortTasksFromJson(statObject){ +function sortTasksFromJson(statObject) { console.log('sortTasksFromJson') - fs.readFile(sourceFilePath, 'utf8', function (err,data) { + fs.readFile(sourceFilePath, 'utf8', function (err, data) { if (err) { return console.log(err); } let dataTransformed = JSON.parse(data); console.log('data keys ', Object.keys(dataTransformed)) - if(dataTransformed["contents"]){ + if (dataTransformed["contents"]) { - countTasks = dataTransformed["contents"].length - console.log('yes data !' , countTasks) - console.log('element' , dataTransformed["contents"]["0"]) + countTasks = dataTransformed["contents"].length + stats.countAllTasks = countTasks; + + 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); + 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 -function writeHtmlOutput(){ - console.log('writeHtmlOutput') -} \ No newline at end of file +function writeHtmlOutput() { + console.log('writeHtmlOutput', stats.countAllTasks) + + let daysListRef = Object.keys(stats.tasksByDay).sort() + let htmlOut = ` + + + + Rapport d'activité + + + + + +
+ ` + daysListRef.forEach((dayRefString) => { + + let tasksOfTheDay = ''; + + stats.tasksByDay[dayRefString].forEach((dayObj) => { + tasksOfTheDay += `
  • +

    + ${dayObj.todoKeyword} + ${dayObj.title} +

    +

    + ${dayObj.itags} +

    +
  • ` + }) + htmlOut += ` +

    + + + ${dayRefString} + + + ${stats.tasksByDay[dayRefString].length} + + +

    +
    +
      + ${tasksOfTheDay} +
    +
    + ` + }) + htmlOut += ` +
    + + + ` + + 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; + }, {}); +} diff --git a/package.json b/package.json index bcf0d5a..e591a3b 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,6 @@ "nodemon": "^2.0.19" }, "scripts" : { - "start" : "nodemon app.js" + "start" : "node app.js" } }