This commit is contained in:
Tykayn 2023-03-14 18:04:54 +01:00 committed by tykayn
parent 9ff38a3aa8
commit 229d71b4a1
6 changed files with 818 additions and 1563 deletions

View File

@ -0,0 +1,86 @@
import fs from "node-fs";
import {writeFileInOuputFolder} from "./parse_orgmode_to_json.mjs";
import moment from "moment";
/**********************
* initialize configs
**********************/
const fileArray = ["2007-07-01 De juillet 2007 à septembre 2007.json","2007-10-01 De octobre 2007 à décembre 2007.json","2008-04-01 De avril 2008 à juin 2008.json","2008-07-01 De juillet 2008 à septembre 2008.json","2008-10-01 De octobre 2008 à décembre 2008.json","2009-01-01 De janvier 2009 à mars 2009.json","2009-04-01 De avril 2009 à juin 2009.json","2009-07-01 De juillet 2009 à septembre 2009.json","2009-10-01 De octobre 2009 à décembre 2009.json","2010-01-01 De janvier 2010 à mars 2010.json","2010-04-01 De avril 2010 à juin 2010.json","2010-07-01 De juillet 2010 à septembre 2010.json","2010-10-01 De octobre 2010 à décembre 2010.json","2011-01-01 De janvier 2011 à mars 2011.json","2011-04-01 De avril 2011 à juin 2011.json","2011-07-01 De juillet 2011 à septembre 2011.json","2011-10-01 De octobre 2011 à décembre 2011.json","2012-01-01 De janvier 2012 à mars 2012.json","2012-04-01 De avril 2012 à juin 2012.json","2012-07-01 De juillet 2012 à septembre 2012.json","2012-10-01 De octobre 2012 à décembre 2012.json","2013-01-01 De janvier 2013 à mars 2013.json","2013-04-01 De avril 2013 à juin 2013.json","2013-07-01 De juillet 2013 à septembre 2013.json","2013-10-01 De octobre 2013 à décembre 2013.json","2014-01-01 De janvier 2014 à mars 2014.json","2014-04-01 De avril 2014 à juin 2014.json","2014-07-01 De juillet 2014 à septembre 2014.json","2014-10-01 De octobre 2014 à décembre 2014.json","2015-01-01 De janvier 2015 à mars 2015.json","2015-04-01 De avril 2015 à juin 2015.json","2015-07-01 De juillet 2015 à septembre 2015.json","2015-10-01 De octobre 2015 à décembre 2015.json","2016-01-01 De janvier 2016 à mars 2016.json","2016-04-01 De avril 2016 à juin 2016.json","2016-07-01 De juillet 2016 à septembre 2016.json","2016-10-01 De octobre 2016 à décembre 2016.json","2017-01-01 De janvier 2017 à mars 2017.json","2017-04-01 De avril 2017 à juin 2017.json"]
const fileNameAllEvents = 'all_researches.tsv';
const headersTsv = 'amount\t' +
'content\t' +
'description\t' +
'destination\t' +
'end\t' +
'kind of activity\t' +
'person\t' +
'place\t' +
'source\t' +
'start\t' +
'unique id\t' +
'url\t'
let allEvents = [
headersTsv
];
const events = [headersTsv];
async function convertJsonToActivities(sourceFilePath, outputFileName)
{
await fs.readFile(sourceFilePath, 'utf8', function (err, data) {
data = JSON.parse(data)
// console.log('data', Object.keys(data[0]))
data['event'].forEach(item => {
// let timemoment = moment.unix(item.query.id[0].timestamp_usec)
let stamp =Math.round( item.query.id[0].timestamp_usec / 1000);
let mydate = new Date(stamp)
let timemoment = moment( mydate)
// return;
// console.log('mydate',item.query.id[0].timestamp_usec, item.query.id[0].timestamp_usec.length , stamp, mydate)
// convert all fields to common event description
let newLine =
'\t' +
item.query.query_text + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t' +
'recherche' + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t' +
timemoment.format() + '\t' +
'' + '\t' +
'' + '\t'
events.push(newLine)
// console.log('events', events.length)
allEvents.push(newLine)
})
console.log('events', events.length)
writeFileInOuputFolder(outputFileName, events.join("\n"))
})
}
fileArray.forEach(item=>{
let filename = item
let sourceFilePath = '/home/tykayn/Nextcloud/ressources/social sorting/2022-12-31_recherches/'+filename
let outputFileName = filename.replace('json' , 'tsv')
convertJsonToActivities(sourceFilePath,outputFileName);
})
writeFileInOuputFolder(fileNameAllEvents, events.join("\n"))

View File

@ -2,7 +2,8 @@
"dependencies": { "dependencies": {
"d3": "^7.8.2", "d3": "^7.8.2",
"node-fs": "^0.1.7", "node-fs": "^0.1.7",
"nodemon": "^2.0.19" "nodemon": "^2.0.19",
"xml-js": "^1.6.11"
}, },
"scripts": { "scripts": {
"start": "node app.js" "start": "node app.js"

View File

@ -12,6 +12,7 @@ import moment from 'moment';
const sourceFileName = 'all_tasks.org' const sourceFileName = 'all_tasks.org'
const sourceFilePath = './sources/' + sourceFileName; const sourceFilePath = './sources/' + sourceFileName;
const outputAbsolutePath = '/home/tykayn/Nextcloud/ressources/social sorting/output/';
let headers = [] let headers = []
let tasksObjectsForJsonExport = [] let tasksObjectsForJsonExport = []
@ -90,12 +91,16 @@ function addAndRefreshCurrentTask() {
}; };
function makeWordsStatistics(sentence) { function makeWordsStatistics(sentence) {
sentence.split(' ')?.forEach(word => { let split = sentence.split(' ');
if (!statistics.words[word]) { if (split && split.length) {
statistics.words[word] = 0
} split.forEach(word => {
statistics.words[word]++ if (!statistics.words[word]) {
}) statistics.words[word] = 0
}
statistics.words[word]++
})
}
} }
/********************** /**********************
@ -128,7 +133,11 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
isHeader = true; isHeader = true;
// compter les étoiles pour trouver le niveau du header // compter les étoiles pour trouver le niveau du header
currentTask.level = line.match(/\*/g)?.length if (line.match(/\*/g)) {
let match = line.match(/\*/g);
currentTask.level = match.length
}
// create a new task // create a new task
@ -150,17 +159,20 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
if (tagsFound) { if (tagsFound) {
tagsFound = tagsFound[0]; tagsFound = tagsFound[0];
let tagList = tagsFound.split(':'); let tagList = tagsFound.split(':');
tagList?.forEach(tag => { if (tagList.length) {
if (tag.length > 1) {
if (!statistics.tags[tag]) { tagList.forEach(tag => {
statistics.tags[tag] = 0 if (tag.length > 1) {
if (!statistics.tags[tag]) {
statistics.tags[tag] = 0
}
statistics.tags[tag]++
currentTask.tags.push(tag)
} }
statistics.tags[tag]++ })
}
currentTask.tags.push(tag)
}
})
} }
@ -229,7 +241,7 @@ fs.readFile(sourceFilePath, 'utf8', function (err, data) {
// console.log('tasksObjectsForJsonExport', jsonContent) // console.log('tasksObjectsForJsonExport', jsonContent)
if (writeJsonAfterParse) { if (writeJsonAfterParse) {
writeJsonFile('export_' + sourceFileName + '_parsed.json', JSON.stringify(jsonContent)); writeFileInOuputFolder('export_' + sourceFileName + '_parsed.json', JSON.stringify(jsonContent));
} }
}) })
@ -317,11 +329,11 @@ function cleanHeader(line) {
return line.trim(); return line.trim();
} }
function writeJsonFile(fileName, fileContent) { export async function writeFileInOuputFolder(fileName, fileContent) {
console.log('write file ', fileName); console.log('write file ', fileName);
return fs.writeFile( return await fs.writeFile(
`./output/${fileName}`, `${outputAbsolutePath}${fileName}`,
fileContent, fileContent,
"utf8", "utf8",
(err) => { (err) => {

View File

@ -11,34 +11,35 @@ date >> stats.org
echo " décomptes: " >> stats.org echo " décomptes: " >> stats.org
# dans les archives, les tâches sont toujours un header de niveau 1, on peut donc les trouver avec la recherche de : "* " # dans les archives, les tâches sont toujours un header de niveau 1, on peut donc les trouver avec la recherche de : "* "
todos=`grep -o '* TODO' all_tasks.org | wc -l` todos=`grep -o '* TODO' all_tasks.org | wc -l`
echo " TODO : $todos" echo " TODO : $todos" | tee -a ./stats.org
counter=`grep -o '* SOMEDAY' all_tasks.org | wc -l` counter=`grep -o '* SOMEDAY' all_tasks.org | wc -l`
echo " SOMEDAY : $counter" echo " SOMEDAY : $counter" | tee -a ./stats.org
someday=$counter someday=$counter
counter=`grep -o '* WAITING' all_tasks.org | wc -l` counter=`grep -o '* WAITING' all_tasks.org | wc -l`
echo " WAITING : $counter" echo " WAITING : $counter" | tee -a ./stats.org
echo " " echo " " | tee -a ./stats.org
counter=`grep -o '* CANCELLED' all_tasks.org | wc -l` counter=`grep -o '* CANCELLED' all_tasks.org | wc -l`
cancelled_tasks=$counter cancelled_tasks=$counter
echo " CANCELLED : $counter" echo " CANCELLED : $counter" | tee -a ./stats.org
counter=`grep -o '* DONE' all_tasks.org | wc -l` counter=`grep -o '* DONE' all_tasks.org | wc -l`
done=$counter done=$counter
echo " DONE : $counter" echo " DONE : $counter" | tee -a ./stats.org
prevus=$((todos + someday)) prevus=$((todos + someday))
finis=$((cancelled_tasks + done)) finis=$((cancelled_tasks + done))
tout=$((prevus + finis)) tout=$((prevus + finis))
echo " " echo " " | tee -a ./stats.org
echo " prévus : $prevus" echo " prévus : $prevus" | tee -a ./stats.org
echo " finis : $finis" echo " finis : $finis" | tee -a ./stats.org
counter=`grep -o '* CREATED' all_tasks.org | wc -l` counter=`grep -o '* CREATED' all_tasks.org | wc -l`
echo " CREATED : $counter" echo " CREATED : $counter" | tee -a ./stats.org
echo " en tout : $tout" echo " en tout : $tout" | tee -a ./stats.org
counter=`ls -l ~/Nextcloud/textes/orgmode/org-roam/*.org | wc -l` counter=`ls -l ~/Nextcloud/textes/orgmode/org-roam/*.org | wc -l`
echo " Roam files : $counter" echo " Roam files : $counter" | tee -a ./stats.org
echo " " | tee -a ./stats.org
#pandoc -i all_tasks.org -o all_tasks.json #pandoc -i all_tasks.org -o all_tasks.json

159
sms_to_csv.mjs Normal file
View File

@ -0,0 +1,159 @@
import fs from "node-fs";
import convert from "xml-js";
import {writeFileInOuputFolder} from "./parse_orgmode_to_json.mjs";
/**********************
* initialize configs
**********************/
const sourceFileName = 'sms-20180423162531.xml'
const outputFileJson = 'sms-20180423162531.json'
const sourceFileJson = 'output/' + outputFileJson
const outputFileCsv = 'sms-20180423162531.tsv'
const sourceFilePath = '/home/tykayn/Nextcloud/ressources/social sorting/' + sourceFileName;
let headers = []
let tasksObjectsForJsonExport = []
let headersByKind = {}
let writeJsonAfterParse = false;
writeJsonAfterParse = true;
/**************************************************************
* fetch the source file to read its contents
*************************************************************/
console.log('parse some org file', sourceFilePath)
if (!sourceFilePath) {
console.error('pas de fichier à ouvrir')
}
function convertToCsv(elementsArray) {
elementsArray.forEach(item => {
console.log('item._attributes.date_sent', item._attributes.date_sent)
console.log('item._attributes.contact_name', item._attributes.date_sent)
console.log('item._attributes.body', item._attributes.date_sent)
})
}
function convertJsonToCsv(sourceFilePath, outputFileName) {
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
const events = [
'amount\t' +
'content\t' +
'description\t' +
'destination\t' +
'end\t' +
'kind of activity\t' +
'person\t' +
'place\t' +
'source\t' +
'start\t' +
'unique id\t' +
'url\t'
];
data = JSON.parse(data)
console.log('data', data)
// console.log('data', Object.keys(data[0]))
data['smses']['sms'].forEach(item => {
// convert all fields to common event description
events.push(
'\t' +
item._attributes.body.replace('\n', ' ') + '\t' +
'sms ' + item._attributes.address + ' le ' + item._attributes.readable_date + '\t' +
item._attributes.address + '\t' +
'' + '\t' +
'' + '\t' +
item._attributes.contact_name + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t'
)
})
console.log('events', events)
writeFileInOuputFolder(outputFileName, events.join("\n"))
})
}
function openSourceFile() {
fs.stat(sourceFilePath, function (err, data) {
if (err == null) {
console.log(`File ${sourceFilePath} exists`);
/**********************
* loop to parse all
*********************/
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
// console.log('data', data)
var jsonConversion = convert.xml2json(data, {compact: true, spaces: 2});
// console.log('smses', Object.keys(jsonConversion))
console.log('jsonConversion[0]', jsonConversion['10'])
writeFileInOuputFolder(outputFileJson, jsonConversion)
convertJsonToCsv(sourceFileJson, outputFileCsv)
})
} else if (err.code === 'ENOENT') {
// file does not exist
console.error(`le fichier ${sourceFilePath} est introuvable. Impossible d en extraire des infos.`, err);
} else {
console.log('Some other error: ', err.code);
}
});
}
// openSourceFile()
function convertJsonToCsv(sourceFilePath, outputFileName) {
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
const events = [
'amount\t' +
'content\t' +
'description\t' +
'destination\t' +
'end\t' +
'kind of activity\t' +
'person\t' +
'place\t' +
'source\t' +
'start\t' +
'unique id\t' +
'url\t'
];
data = JSON.parse(data)
console.log('data', data)
// console.log('data', Object.keys(data[0]))
data['smses']['sms'].forEach(item => {
// convert all fields to common event description
events.push(
'\t' +
item._attributes.body.replace('\n', ' ') + '\t' +
'sms ' + item._attributes.address + ' le '+item._attributes.readable_date+'\t' +
item._attributes.address + '\t' +
'' + '\t' +
'' + '\t' +
item._attributes.contact_name + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t' +
'' + '\t'
)
})
console.log('events', events)
writeFileInOuputFolder(outputFileName, events.join("\n"))
})
}

2056
yarn.lock

File diff suppressed because it is too large Load Diff