From a6d82ba652c80cac25e1d0b06c60afcb61005307 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 20 Jul 2022 18:45:29 +0200 Subject: [PATCH] hop --- app.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 65b5d4c..6ff27cc 100644 --- a/app.js +++ b/app.js @@ -4,6 +4,15 @@ const stats = { countAllTasks: 0, tasksByDay: {} } + +// const enableFilterByTag = true; +const enableFilterByTag = false; +const filterByTag = "work"; +// const outputFileName = "work_report"; +const outputFileName = "all_tasks_report"; +let countExcluded = 0; +let countIncluded = 0; + // prendre le json source représentant les tâches DONE console.log(' ### lecture de source/emacs_json.json'); @@ -27,26 +36,63 @@ function sortTasksFromJson(statObject) { return console.log(err); } let dataTransformed = JSON.parse(data); - console.log('data keys ', Object.keys(dataTransformed)) + // console.log('data keys ', Object.keys(dataTransformed)) if (dataTransformed["contents"]) { countTasks = dataTransformed["contents"].length stats.countAllTasks = countTasks; - console.log('yes data !', countTasks) - console.log('first', dataTransformed["contents"][0]) + console.log('yes data ! tasks:', countTasks) - dataTransformed["contents"].forEach((elem) => { - if (elem['title'] && elem['title'][0]) { - console.log(' - ', elem['title'][0]) + dataTransformed["contents"].forEach((elem, index) => { + + // console.log('tâche ', index) + // évacuer les sous tâches + // if (elem['contents']) { + // console.log('content ception, on évacue') + // countExcluded++; + // return; + // } + // filtrer par tag les tâches + if (enableFilterByTag) { + console.log('filtre activé', filterByTag) + if (!elem['drawer'] || !elem['properties']['tags']) { + + + console.log('on vire cette tâche n\'ayant pas de drawer :', elem) + countExcluded++; + return; + } else if ( + elem['properties'] && + typeof elem['properties']['tags'] !== "undefined" && + elem['properties']['tags'].indexOf(filterByTag) === -1 + ) { + console.log('on vire cette tâche ayant les itags :', elem['drawer']['ARCHIVE_ITAGS']) + countExcluded++; + return; + } + } else { + console.log(' - filtre désactivé') } - if (elem['properties'] && elem['properties']['closed']) { + // après le filtre, on range les tâches + + if (elem['properties']) { + console.log(' - ref ', elem['ref']) 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']; + let closeDate = 'Indéfini'; + let todoKeyword = 'DONE'; + if (elem['properties']['closed']) { + closeDate = elem['properties']['closed']['end']; + + } else if (elem['drawer'] && elem['drawer']['ARCHIVE_TIME']) { + closeDate = elem['drawer']['ARCHIVE_TIME']; + } + if (elem['drawer'] && elem['drawer']['ARCHIVE_TODO']) { + + todoKeyword = elem['drawer']['ARCHIVE_TODO']; + } // jour, 11 premiers caractères @@ -55,25 +101,24 @@ function sortTasksFromJson(statObject) { stats.tasksByDay[day] = [] } stats.tasksByDay[day].push({ + todoKeyword, title, + day, closeDate, tags, - todoKeyword, - day, - itags }) // console.log(' ' + title) + countIncluded++; } else { console.log('no', elem['properties']['raw-value']) } }) - // console.log('element', dataTransformed["contents"]["0"]) - } else { console.log('no content') } // console.log(data); + console.log('tâches inclues:', countIncluded) writeHtmlOutput() }); @@ -87,6 +132,11 @@ function writeHtmlOutput() { console.log('writeHtmlOutput', stats.countAllTasks) let daysListRef = Object.keys(stats.tasksByDay).sort() + let filterInfo = `` + if (enableFilterByTag) { + filterInfo = `

Contenu filtré sur le tag: ${filterByTag}. ${countExcluded} tâches exclues, ${countIncluded} tâches inclues sur le total de ${countExcluded + countIncluded}

` + } + let htmlOut = ` @@ -99,9 +149,14 @@ function writeHtmlOutput() { +
+

Feuille de rapport d'activité

+

par Tykayn

+ ${filterInfo} + ` - daysListRef.forEach((dayRefString) => { + daysListRef.reverse().forEach((dayRefString) => { let tasksOfTheDay = ''; @@ -110,14 +165,21 @@ function writeHtmlOutput() { if ('DONE' !== dayObj.todoKeyword) { graphicKeyword = dayObj.todoKeyword; } + + let tagDisplay = ''; + if (dayObj.tags.length) { + tagDisplay = `

+ ${dayObj.tags.join(' ')} +

+ ` + } + tasksOfTheDay += `
  • -

    +

    ${graphicKeyword} ${dayObj.title}

    -

    - ${dayObj.itags} -

    + ${tagDisplay}
  • ` }) htmlOut += ` @@ -127,7 +189,7 @@ function writeHtmlOutput() { ${dayRefString} - + ${stats.tasksByDay[dayRefString].length} @@ -141,8 +203,20 @@ function writeHtmlOutput() {
    ` }) htmlOut += ` +
    +

    +Tadam, c'est tout! +

    +

    + +Source: org-report-stats +
    +Contactez-moi: par un de ces moyens +

    + + ` @@ -153,12 +227,16 @@ function writeHtmlOutput() { } console.log('wrote output json', data) }) - fs.writeFile('output/output.html', htmlOut, function (err, data) { + fs.writeFile('output/output_' + outputFileName + '.html', htmlOut, function (err, data) { if (err) { return console.log(err); } - console.log('wrote output html', data) + console.log('wrote output html ' + outputFileName, data) + }) + if (enableFilterByTag) { + console.log('excluded tasks by tag filter ', countExcluded) + } }