improve stats date
This commit is contained in:
parent
24f590d7e5
commit
aff36ac2da
|
@ -97,14 +97,19 @@ let currentTask = Object.create(task);
|
|||
* add to tasks to export and refresh current task
|
||||
*/
|
||||
function addAndRefreshCurrentTask() {
|
||||
|
||||
makeWordsStatistics(currentTask.header.trim())
|
||||
makeWordsStatistics(currentTask.corpus.trim())
|
||||
|
||||
tasksObjectsForJsonExport.push(currentTask)
|
||||
// réinitialisation de tâche pour remplir de nouveau
|
||||
currentTask = Object.create(task);
|
||||
currentTask.dates = {};
|
||||
currentTask.tags = [];
|
||||
};
|
||||
}
|
||||
|
||||
function makeWordsStatistics(sentence) {
|
||||
console.log('sentence', sentence)
|
||||
let split = sentence.split(' ');
|
||||
if (split && split.length) {
|
||||
|
||||
|
@ -117,6 +122,36 @@ function makeWordsStatistics(sentence) {
|
|||
}
|
||||
}
|
||||
|
||||
const dateStats = {
|
||||
created: 0,
|
||||
refiled: 0,
|
||||
closed: 0,
|
||||
cancelled: 0,
|
||||
scheduled: 0,
|
||||
deadline: 0,
|
||||
}
|
||||
|
||||
function fillPeriodTime(periodStat, keyword){
|
||||
|
||||
if (keyword === 'CLOSED') {
|
||||
periodStat.closed++;
|
||||
}
|
||||
if (keyword === 'CREATED') {
|
||||
periodStat.created++;
|
||||
}
|
||||
if (keyword === 'Refiled') {
|
||||
periodStat.refiled++;
|
||||
}
|
||||
if (keyword === 'CANCELLED') {
|
||||
periodStat.cancelled++;
|
||||
}
|
||||
if (keyword === 'SCHEDULED') {
|
||||
periodStat.scheduled++;
|
||||
}
|
||||
if (keyword === 'DEADLINE') {
|
||||
periodStat.deadline++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pour chaque période de temps, compter les tâches créées et fermées
|
||||
|
@ -139,59 +174,27 @@ function statisticDateFill(keyword, dateFoundElement) {
|
|||
let dayOfDate = convertedDate.getFullYear() + '-' + convertedMonth + '-' + convertedDay
|
||||
|
||||
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++;
|
||||
statistics.dates.years[yearOfDate] = Object.create(dateStats)
|
||||
}
|
||||
fillPeriodTime(statistics.dates.years[yearOfDate], keyword)
|
||||
|
||||
// par année-semaine
|
||||
if (!statistics.dates.weeks[weekOfDate]) {
|
||||
statistics.dates.weeks[weekOfDate] = {
|
||||
created: 0,
|
||||
closed: 0,
|
||||
statistics.dates.weeks[weekOfDate] = Object.create(dateStats)
|
||||
}
|
||||
}
|
||||
if (keyword === 'CLOSED') {
|
||||
statistics.dates.weeks[weekOfDate].closed++;
|
||||
}
|
||||
if (keyword === 'CREATED') {
|
||||
statistics.dates.weeks[weekOfDate].created++;
|
||||
}
|
||||
|
||||
fillPeriodTime(statistics.dates.weeks[weekOfDate], keyword)
|
||||
// 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++;
|
||||
statistics.dates.months[monthOfDate] = Object.create(dateStats)
|
||||
}
|
||||
fillPeriodTime(statistics.dates.months[monthOfDate], keyword)
|
||||
|
||||
// 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++;
|
||||
statistics.dates.days[dayOfDate] = Object.create(dateStats)
|
||||
}
|
||||
fillPeriodTime(statistics.dates.days[dayOfDate], keyword)
|
||||
|
||||
}
|
||||
|
||||
|
@ -251,7 +254,6 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
|||
|
||||
headers.push(cleanHeader(line))
|
||||
currentTask.header = cleanHeader(line);
|
||||
// makeWordsStatistics(cleanHeader(line));
|
||||
stateKeywordList.forEach(keyword => {
|
||||
let keywordIsFound = lineHasKeyword(line, keyword)
|
||||
|
||||
|
@ -332,20 +334,22 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
|||
line.indexOf(sectionKeywordList) !== -1
|
||||
) {
|
||||
|
||||
|
||||
// ajouter le corps complet de la section après le header
|
||||
if (line.length && !isHeader) {
|
||||
|
||||
let cleanedLine = line.replace(/\s\s/g, ' ');
|
||||
cleanedLine = line.replace(/ {2,}/g, ' ')
|
||||
|
||||
cleanedLine = cleanedLine.trim()
|
||||
|
||||
currentTask.corpus += `${cleanedLine}
|
||||
`
|
||||
makeWordsStatistics(cleanedLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// ajouter la dernière tâche parsée
|
||||
addAndRefreshCurrentTask();
|
||||
|
||||
|
@ -361,17 +365,14 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
|||
statistics.dates.months = sortByKey(statistics.dates.months)
|
||||
statistics.dates.days = sortByKey(statistics.dates.days)
|
||||
|
||||
statistics.tags = sortByValue(statistics.tags)
|
||||
statistics.words = sortByValue(statistics.tags)
|
||||
|
||||
sorted_stats = sortByKey(statistics)
|
||||
statistics = sortByKey(statistics)
|
||||
|
||||
|
||||
const jsonContent = {
|
||||
statistics: {
|
||||
lines_count: everyline.length,
|
||||
headers_count: headers.length,
|
||||
statistics: sorted_stats
|
||||
statistics
|
||||
},
|
||||
meta_data: {
|
||||
author: '@tykayn@mastodon.Cipherbliss.com',
|
||||
|
@ -390,16 +391,6 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
|||
|
||||
})
|
||||
|
||||
/**
|
||||
* ranger un objet littéral selon la valeur décroissante de ses paires
|
||||
* @param literalobject
|
||||
* @returns {any}
|
||||
*/
|
||||
function sortByValue(literalobject) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(literalobject).sort(([, a], [, b]) => b - a)
|
||||
);
|
||||
}
|
||||
|
||||
function lineHasKeyword(line, keyword = 'TODO') {
|
||||
|
||||
|
@ -489,10 +480,26 @@ function sortByKey(objectStuff) {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ranger un objet littéral selon la valeur décroissante de ses paires
|
||||
* @param literalobject
|
||||
* @returns {any}
|
||||
*/
|
||||
function sortByValue(literalobject) {
|
||||
|
||||
let sortable = [];
|
||||
for (var keyName in literalobject) {
|
||||
sortable[keyName] = literalobject[keyName];
|
||||
}
|
||||
// return literalobject
|
||||
return sortable.sort(function (a, b) {
|
||||
return b[1] - a[1];
|
||||
});
|
||||
}
|
||||
|
||||
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
|
||||
|
||||
console.log('statistics.words', statistics.words)
|
||||
console.log('statistics.dates', statistics.dates)
|
||||
|
||||
return await fs.writeFile(
|
||||
`${outputAbsolutePath}${fileName}`,
|
||||
|
|
Loading…
Reference in New Issue