diff --git a/README.md b/README.md index e0a994c..db490d2 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,13 @@ Compte rendu html des tâches réalisées dans des fichiers Orgmode * avoir Nodejs version stable # Utilisation +## compiler les fichiers org et les convertir en json +```bash + make convert + ``` +la sortie est générée dans "outputAbsolutePath" définie dans "parse_orgmode_to_json.mjs" + +## voir le rendu Lancer l'exécution du fichier app avec node, et consulter l'output html. ```bash npm start diff --git a/json_orgmode_sort_by_dates.mjs b/json_orgmode_sort_by_dates.mjs new file mode 100644 index 0000000..8cf7552 --- /dev/null +++ b/json_orgmode_sort_by_dates.mjs @@ -0,0 +1,25 @@ +import fs from "node-fs"; + +/** + convertir un json représentant toutes les tâches orgmode en un json rangé par dates + **/ +const sourceFileName = 'all_tasks.org' +const sourceFilePath = './sources/' + sourceFileName; +const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/'; +const outputFileNameJson = 'export_' + sourceFileName + '_parsed.json'; + +function openJsonFile(){ + + fs.readFile(outputAbsolutePath+outputFileNameJson, 'utf8', function (err, data) { + + + if (err) { + return console.log(err); + } + const json_content = JSON.parse(data); + + console.log(outputAbsolutePath+outputFileNameJson, json_content.tasks_list.length) + }) +} + +openJsonFile() diff --git a/parse_orgmode_to_json.mjs b/parse_orgmode_to_json.mjs index f71d9e5..3a55432 100644 --- a/parse_orgmode_to_json.mjs +++ b/parse_orgmode_to_json.mjs @@ -13,6 +13,7 @@ import moment from 'moment'; const sourceFileName = 'all_tasks.org' const sourceFilePath = './sources/' + sourceFileName; const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/'; +const outputFileNameJson = 'export_' + sourceFileName + '_parsed.json'; let headers = [] let tasksObjectsForJsonExport = [] @@ -24,7 +25,7 @@ writeJsonAfterParse = true; * fetch the source orgmode file to read its contents *************************************************************/ -console.log('parse some org file', sourceFilePath) +console.log('---------- parse some org file', sourceFilePath) if (!sourceFilePath) { console.error('pas de fichier à ouvrir') } @@ -52,7 +53,17 @@ let logBookSection = {} // TODO logbook listing let statistics = { tags: {}, - words: {} + words: {}, + dates: { + havingDate: 0, + havingNoDate: 0, + oldEst: 0, + mostRecent: 0, + years:{}, + weeks:{}, + months:{}, + days:{} + } } let headerKeywordSearch = '[' + stateKeywordList.join('|') + ']' @@ -103,6 +114,68 @@ function makeWordsStatistics(sentence) { } } + +/** + * pour chaque période de temps, compter les tâches créées et fermées + * @param keyword + * @param dateFoundElement + */ +function statisticDateFill(keyword, dateFoundElement) { + + // décompte par années + + let convertedDate = new Date(dateFoundElement ) + let yearOfDate = convertedDate.getFullYear() + let monthOfDate = convertedDate.getFullYear()+ '-'+ convertedDate.getMonth() + let convertedMonth = convertedDate.getMonth() < 10 ? '0'+convertedDate.getMonth(): convertedDate.getMonth() + let convertedDay = convertedDate.getDay() < 10 ? '0'+convertedDate.getDay(): convertedDate.getDay() + let dayOfDate = convertedDate.getFullYear()+ '-'+ convertedMonth+ '-' + convertedDay + + console.log('convertedDate', convertedDate,yearOfDate) + if(!statistics.dates.years[yearOfDate]){ + statistics.dates.years[yearOfDate] = { + created:0, + closed:0, + } + } + if(keyword=== 'CLOSED'){ + statistics.dates.years[yearOfDate].closed++; + } + if(keyword=== 'CREATED'){ + statistics.dates.years[yearOfDate].created++; + } + + // décompte par mois + if(!statistics.dates.months[monthOfDate]){ + statistics.dates.months[monthOfDate] = { + created:0, + closed:0, + } + } + if(keyword=== 'CLOSED'){ + statistics.dates.months[monthOfDate].closed++; + } + if(keyword=== 'CREATED'){ + statistics.dates.months[monthOfDate].created++; + } + + // décompte par jours + + if(!statistics.dates.days[dayOfDate]){ + statistics.dates.days[dayOfDate] = { + created:0, + closed:0, + } + } + if(keyword=== 'CLOSED'){ + statistics.dates.days[dayOfDate].closed++; + } + if(keyword=== 'CREATED'){ + statistics.dates.days[dayOfDate].created++; + } + +} + /********************** * loop to parse all *********************/ @@ -184,19 +257,43 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) { // classer les dates de création, cloture, et de logbook let dateFound = searchDate(line) if (dateFound) { + /** + * we have found a date in the current line + */ + + statistics.dates.havingDate += 1; dateKeywordList.forEach(keyword => { if (lineHasSubstring(line, keyword)) { if (!currentTask.dates[keyword]) { currentTask.dates[keyword] = ''; } - currentTask.dates[keyword] = new Date(dateFound[0]); + + let convertedDate = dateFound[0].substring(0, 10) + let formattedDate = moment(convertedDate).format() + + statisticDateFill(keyword,convertedDate) + + currentTask.dates[keyword] = formattedDate; + + console.log('formattedDate', keyword, formattedDate) + + // trouver la plus ancienne date + if (!statistics.dates.oldEst) { + statistics.dates.oldEst = formattedDate; + } else { + var beginningTime = moment(statistics.dates.oldEst); + var endTime = moment(convertedDate); + if (!beginningTime.isBefore(endTime)) { + statistics.dates.oldEst = formattedDate; + } + } } else { // console.log('keyword', keyword) } }) } else { - + statistics.dates.havingNoDate += 1; if (line.indexOf(dateKeywordList) !== -1 && line.indexOf(stateKeywordList) !== -1 && line.indexOf(sectionKeywordList) !== -1) { makeWordsStatistics(line) @@ -216,17 +313,20 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) { addAndRefreshCurrentTask(); console.log(" parsing fini") - // stateKeywordList.forEach(keyword => console.log('nombre de headers', keyword, headersByKind[keyword]?.length)) + + // ranger par valeur décroissante les tags + + let sorted_stats = []; + sorted_stats = Object.fromEntries( + Object.entries(statistics).sort(([, a], [, b]) => a - b) + ); const jsonContent = { statistics: { lines_count: everyline.length, headers_count: headers.length, - statistics: Object.keys(statistics).sort(function (a, b) { - return statistics[a] - statistics[b] - }) - + statistics: sorted_stats }, meta_data: { author: '@tykayn@mastodon.Cipherbliss.com', @@ -237,11 +337,10 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) { tasks_list: tasksObjectsForJsonExport } - console.log('statistics', statistics) - // console.log('tasksObjectsForJsonExport', jsonContent) if (writeJsonAfterParse) { - writeFileInOuputFolder('export_' + sourceFileName + '_parsed.json', JSON.stringify(jsonContent)); + + writeFileInOuputFolder(outputFileNameJson, JSON.stringify(jsonContent)); } }) @@ -330,7 +429,8 @@ function cleanHeader(line) { } export async function writeFileInOuputFolder(fileName, fileContent) { - console.log('write file ', fileName); + console.log('write file ', outputAbsolutePath, fileName); + console.log('date statistics ', statistics.dates); return await fs.writeFile( `${outputAbsolutePath}${fileName}`, diff --git a/scripts/concat_org.sh b/scripts/concat_org.sh index e084652..4c56b95 100644 --- a/scripts/concat_org.sh +++ b/scripts/concat_org.sh @@ -1,10 +1,12 @@ #!/usr/bin/bash touch all_tasks.org echo "" > all_tasks.org + + cat ~/Nextcloud/textes/orgmode/tasks.org >> all_tasks.org cat ~/Nextcloud/textes/orgmode/tasks.org_archive >> all_tasks.org cp all_tasks.org ~/Nextcloud/textes/orgmode/stats -echo "concaténation des fichiers tasks.org et tasks.org_archive faite dans all_tasks.org" +echo "concaténation des fichiers tasks.org et tasks.org_archive faite dans all_tasks.org \n" touch stats.org date >> stats.org