base parser from json to tsv added
This commit is contained in:
parent
aff36ac2da
commit
48420bb7fe
|
@ -0,0 +1,64 @@
|
||||||
|
import fs from "node-fs";
|
||||||
|
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
convertir un json représentant toutes les tâches orgmode en un json rangé par dates
|
||||||
|
**/
|
||||||
|
const sourceFileName = 'export_all_tasks.org_parsed'
|
||||||
|
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/';
|
||||||
|
const outputFileNameJson = sourceFileName + '.json';
|
||||||
|
|
||||||
|
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
|
||||||
|
const outputFileName = sourceFileName + '.tsv';
|
||||||
|
|
||||||
|
const events = [headersTsv];
|
||||||
|
let counter = 0;
|
||||||
|
let max_count = 10000
|
||||||
|
|
||||||
|
function parseJsonFile() {
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
// do parse json content and add to tsv lines
|
||||||
|
data.forEach(item => {
|
||||||
|
|
||||||
|
if (counter < max_count) {
|
||||||
|
counter++;
|
||||||
|
console.log('item', item)
|
||||||
|
|
||||||
|
// TODO ajust lines
|
||||||
|
let newLine =
|
||||||
|
// item.visit_count + '\t' +
|
||||||
|
// item.title + '\t' +
|
||||||
|
// item.description + '\t' +
|
||||||
|
// item.preview_image_url + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
// 'firefox_place' + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
// mydate + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
'' + '\t'
|
||||||
|
url + '\t' +
|
||||||
|
''
|
||||||
|
// console.log('mydate',stamp, mydate)
|
||||||
|
events.push(newLine)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('events', events.length)
|
||||||
|
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n")).then(r => console.log('r', r))
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
parseJsonFile()
|
|
@ -1,25 +0,0 @@
|
||||||
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()
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
import fs from "node-fs";
|
||||||
|
import {headersTsv, writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
convertir un json représentant toutes les tâches orgmode en un json rangé par dates
|
||||||
|
**/
|
||||||
|
const sourceFileName = 'export_all_tasks.org_parsed'
|
||||||
|
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/';
|
||||||
|
const outputFileNameJson = sourceFileName + '.json';
|
||||||
|
|
||||||
|
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/" + outputFileNameJson
|
||||||
|
const outputFileName = sourceFileName + '.tsv';
|
||||||
|
|
||||||
|
const events = [headersTsv];
|
||||||
|
let counter = 0;
|
||||||
|
let max_count = 10000
|
||||||
|
|
||||||
|
function parseJsonFile() {
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
// do parse json content and add to tsv lines
|
||||||
|
data.forEach(item => {
|
||||||
|
|
||||||
|
if (counter < max_count) {
|
||||||
|
counter++;
|
||||||
|
console.log('item', item)
|
||||||
|
|
||||||
|
// TODO ajust lines
|
||||||
|
let newLine =
|
||||||
|
// item.visit_count + '\t' +
|
||||||
|
// item.title + '\t' +
|
||||||
|
// item.description + '\t' +
|
||||||
|
// item.preview_image_url + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
// 'firefox_place' + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
// mydate + '\t' +
|
||||||
|
'' + '\t' +
|
||||||
|
'' + '\t'
|
||||||
|
url + '\t' +
|
||||||
|
''
|
||||||
|
// console.log('mydate',stamp, mydate)
|
||||||
|
events.push(newLine)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('events', events.length)
|
||||||
|
// writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n")).then(r => console.log('r', r))
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
parseJsonFile()
|
|
@ -80,7 +80,16 @@ let task = {
|
||||||
tags: [],
|
tags: [],
|
||||||
children: [], // TODO list children tasks with a reference to the parent when level is superior to previous task
|
children: [], // TODO list children tasks with a reference to the parent when level is superior to previous task
|
||||||
tagsInherited: [], // TODO inherit tags
|
tagsInherited: [], // TODO inherit tags
|
||||||
dates: {},
|
dates: {
|
||||||
|
havingDate: 0,
|
||||||
|
havingNoDate: 0,
|
||||||
|
oldEst: 0,
|
||||||
|
mostRecent: 0,
|
||||||
|
years: {},
|
||||||
|
weeks: {},
|
||||||
|
months: {},
|
||||||
|
days: {},
|
||||||
|
},
|
||||||
logbook: {},
|
logbook: {},
|
||||||
properties: {},
|
properties: {},
|
||||||
}
|
}
|
||||||
|
@ -109,7 +118,6 @@ function addAndRefreshCurrentTask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeWordsStatistics(sentence) {
|
function makeWordsStatistics(sentence) {
|
||||||
console.log('sentence', sentence)
|
|
||||||
let split = sentence.split(' ');
|
let split = sentence.split(' ');
|
||||||
if (split && split.length) {
|
if (split && split.length) {
|
||||||
|
|
||||||
|
@ -129,6 +137,7 @@ const dateStats = {
|
||||||
cancelled: 0,
|
cancelled: 0,
|
||||||
scheduled: 0,
|
scheduled: 0,
|
||||||
deadline: 0,
|
deadline: 0,
|
||||||
|
tasks_done: []
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillPeriodTime(periodStat, keyword){
|
function fillPeriodTime(periodStat, keyword){
|
||||||
|
@ -158,7 +167,7 @@ function fillPeriodTime(periodStat, keyword){
|
||||||
* @param keyword
|
* @param keyword
|
||||||
* @param dateFoundElement
|
* @param dateFoundElement
|
||||||
*/
|
*/
|
||||||
function statisticDateFill(keyword, dateFoundElement) {
|
function statisticDateFill(keyword, dateFoundElement, header) {
|
||||||
|
|
||||||
// décompte par années
|
// décompte par années
|
||||||
|
|
||||||
|
@ -183,6 +192,7 @@ function statisticDateFill(keyword, dateFoundElement) {
|
||||||
statistics.dates.weeks[weekOfDate] = Object.create(dateStats)
|
statistics.dates.weeks[weekOfDate] = Object.create(dateStats)
|
||||||
}
|
}
|
||||||
fillPeriodTime(statistics.dates.weeks[weekOfDate], keyword)
|
fillPeriodTime(statistics.dates.weeks[weekOfDate], keyword)
|
||||||
|
statistics.dates.weeks[weekOfDate].tasks_done.push(header)
|
||||||
// décompte par mois
|
// décompte par mois
|
||||||
if (!statistics.dates.months[monthOfDate]) {
|
if (!statistics.dates.months[monthOfDate]) {
|
||||||
statistics.dates.months[monthOfDate] = Object.create(dateStats)
|
statistics.dates.months[monthOfDate] = Object.create(dateStats)
|
||||||
|
@ -195,7 +205,7 @@ function statisticDateFill(keyword, dateFoundElement) {
|
||||||
statistics.dates.days[dayOfDate] = Object.create(dateStats)
|
statistics.dates.days[dayOfDate] = Object.create(dateStats)
|
||||||
}
|
}
|
||||||
fillPeriodTime(statistics.dates.days[dayOfDate], keyword)
|
fillPeriodTime(statistics.dates.days[dayOfDate], keyword)
|
||||||
|
statistics.dates.days[dayOfDate].tasks_done.push(header)
|
||||||
}
|
}
|
||||||
|
|
||||||
function findOldestDate(currentDate) {
|
function findOldestDate(currentDate) {
|
||||||
|
@ -316,8 +326,8 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
||||||
convertedDate = moment(dateFound[0], 'YYYY-MM-DD ddd HH:mm')
|
convertedDate = moment(dateFound[0], 'YYYY-MM-DD ddd HH:mm')
|
||||||
}
|
}
|
||||||
let formattedDate = moment(convertedDate).format()
|
let formattedDate = moment(convertedDate).format()
|
||||||
|
console.log('currentTask.header', currentTask.header)
|
||||||
statisticDateFill(keyword, convertedDate)
|
statisticDateFill(keyword, convertedDate, currentTask.header)
|
||||||
findOldestDate(convertedDate)
|
findOldestDate(convertedDate)
|
||||||
currentTask.dates[keyword] = formattedDate;
|
currentTask.dates[keyword] = formattedDate;
|
||||||
|
|
||||||
|
@ -499,7 +509,7 @@ function sortByValue(literalobject) {
|
||||||
|
|
||||||
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
|
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
|
||||||
|
|
||||||
console.log('statistics.dates', statistics.dates)
|
// console.log('statistics.dates', statistics.dates)
|
||||||
|
|
||||||
return await fs.writeFile(
|
return await fs.writeFile(
|
||||||
`${outputAbsolutePath}${fileName}`,
|
`${outputAbsolutePath}${fileName}`,
|
||||||
|
|
21
utils.mjs
21
utils.mjs
|
@ -1,3 +1,5 @@
|
||||||
|
import fs from "node-fs";
|
||||||
|
|
||||||
export const headersTsv = 'amount\t' +
|
export const headersTsv = 'amount\t' +
|
||||||
'content\t' +
|
'content\t' +
|
||||||
'description\t' +
|
'description\t' +
|
||||||
|
@ -10,3 +12,22 @@ export const headersTsv = 'amount\t' +
|
||||||
'start\t' +
|
'start\t' +
|
||||||
'unique id\t' +
|
'unique id\t' +
|
||||||
'url\t'
|
'url\t'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectThing) {
|
||||||
|
|
||||||
|
|
||||||
|
return await fs.writeFile(
|
||||||
|
`${outputAbsolutePath}${fileName}`,
|
||||||
|
JSON.stringify(jsonObjectThing),
|
||||||
|
"utf8",
|
||||||
|
(err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(`Error writing file: ${err}`);
|
||||||
|
} else {
|
||||||
|
console.log(`File ${fileName} is written successfully!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue