table view
This commit is contained in:
parent
b1e94b32ff
commit
648b6bd2a7
63
main.js
63
main.js
@ -10,8 +10,9 @@ var fs = require('fs');
|
|||||||
var listenPort = 8088;
|
var listenPort = 8088;
|
||||||
var jsonParsedLikes, jsonParsedOutbox;
|
var jsonParsedLikes, jsonParsedOutbox;
|
||||||
// const min_length = 1050; // filter only long toots
|
// const min_length = 1050; // filter only long toots
|
||||||
const min_length = 1; // filter only long toots
|
const min_length = 500; // filter only long toots
|
||||||
const max_toots = 20; // filter only long toots
|
const max_toots = 100; // filter only long toots
|
||||||
|
const filterBiggerTottsBeforeSlicing = true; // filter only long toots
|
||||||
const TemplateVars = {
|
const TemplateVars = {
|
||||||
pageTitle : 'Mastodon export converter to HTML',
|
pageTitle : 'Mastodon export converter to HTML',
|
||||||
likes : jsonParsedLikes,
|
likes : jsonParsedLikes,
|
||||||
@ -35,44 +36,37 @@ fs.readFile('source_data/likes.json',
|
|||||||
console.log('example', example);
|
console.log('example', example);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.readFile('source_data/outbox.json',
|
fs.readFile('source_data/outbox.json',
|
||||||
// callback function that is called when reading file is done
|
// callback function that is called when reading file is done
|
||||||
function (err, data) {
|
function (err, data) {
|
||||||
// json data
|
let minchartoots ;
|
||||||
var jsonData = data;
|
|
||||||
// parse json
|
// parse json
|
||||||
jsonParsedOutbox = JSON.parse(jsonData);
|
jsonParsedOutbox = JSON.parse(data);
|
||||||
// access elements
|
// access elements
|
||||||
console.log('outbox toots length', jsonParsedOutbox.orderedItems.length);
|
console.log('outbox toots length', jsonParsedOutbox.orderedItems.length);
|
||||||
|
|
||||||
TemplateVars.outboxTotalLength = jsonParsedOutbox.orderedItems.length;
|
TemplateVars.outboxTotalLength = jsonParsedOutbox.orderedItems.length;
|
||||||
const slice = jsonParsedOutbox.orderedItems.slice(0, max_toots);
|
if(filterBiggerTottsBeforeSlicing){
|
||||||
|
minchartoots = jsonParsedOutbox.orderedItems.filter(item => {
|
||||||
|
return item['object'].content && item['object'].content.length > min_length;
|
||||||
|
});
|
||||||
|
minchartoots = minchartoots.slice(0, max_toots);
|
||||||
|
}else{
|
||||||
|
const slice = jsonParsedOutbox.orderedItems.slice(0, max_toots);
|
||||||
|
minchartoots = slice.filter(item => {
|
||||||
|
return item['object'].content && item['object'].content.length > min_length;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const minchartoots = slice.filter(item => {
|
|
||||||
return item['object'].content && item['object'].content.length > min_length;
|
|
||||||
});
|
|
||||||
console.log('min_chars', min_length);
|
console.log('min_chars', min_length);
|
||||||
console.log('toots min char corresponding', minchartoots.length);
|
console.log('toots min char corresponding', minchartoots.length);
|
||||||
TemplateVars.outbox = minchartoots;
|
TemplateVars.outbox = minchartoots;
|
||||||
|
|
||||||
const example = minchartoots[1];
|
const example = minchartoots[1];
|
||||||
|
|
||||||
// make statistics on who do we talk to, based on the cc field
|
statsForOutboxToots(minchartoots);
|
||||||
minchartoots.forEach(elem => {
|
|
||||||
if (elem['object'].cc) {
|
|
||||||
elem['object'].cc.forEach(copyFolk => {
|
|
||||||
if (!TemplateVars.outboxStatistics[copyFolk]) {
|
|
||||||
TemplateVars.outboxStatistics[copyFolk] = {
|
|
||||||
name : copyFolk,
|
|
||||||
counter: 0,
|
|
||||||
counterContentLength: 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
TemplateVars.outboxStatistics[copyFolk].counter += 1;
|
|
||||||
TemplateVars.outboxStatistics[copyFolk].counterContentLength += elem['object'].content.length;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const statKeys = Object.keys(TemplateVars.outboxStatistics);
|
const statKeys = Object.keys(TemplateVars.outboxStatistics);
|
||||||
const arrayToSort = [];
|
const arrayToSort = [];
|
||||||
statKeys.forEach(elem => {
|
statKeys.forEach(elem => {
|
||||||
@ -91,7 +85,24 @@ fs.readFile('source_data/outbox.json',
|
|||||||
|
|
||||||
fs.writeFile('output/statistics.json', JSON.stringify(TemplateVars.outboxStatistics), errfileHandler );
|
fs.writeFile('output/statistics.json', JSON.stringify(TemplateVars.outboxStatistics), errfileHandler );
|
||||||
});
|
});
|
||||||
|
const statsForOutboxToots = (tootArray)=>{
|
||||||
|
// make statistics on who do we talk to, based on the cc field
|
||||||
|
tootArray.forEach(elem => {
|
||||||
|
if (elem['object'].cc) {
|
||||||
|
elem['object'].cc.forEach(copyFolk => {
|
||||||
|
if (!TemplateVars.outboxStatistics[copyFolk]) {
|
||||||
|
TemplateVars.outboxStatistics[copyFolk] = {
|
||||||
|
name : copyFolk,
|
||||||
|
counter: 0,
|
||||||
|
counterContentLength: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
TemplateVars.outboxStatistics[copyFolk].counter += 1;
|
||||||
|
TemplateVars.outboxStatistics[copyFolk].counterContentLength += elem['object'].content.length;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
const errfileHandler = (err) => {
|
const errfileHandler = (err) => {
|
||||||
if (err)
|
if (err)
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -9,10 +9,20 @@ html(lang="en")
|
|||||||
h2 Statistics
|
h2 Statistics
|
||||||
fieldset.stats
|
fieldset.stats
|
||||||
h3 You did sent messages to these people
|
h3 You did sent messages to these people
|
||||||
each someone in outboxStatistics
|
table
|
||||||
.name
|
thead
|
||||||
a(href=someone.name)=someone.name
|
tr
|
||||||
.counter=someone.counter
|
th= "name"
|
||||||
|
th= "toots to"
|
||||||
|
th= "toots lengh sum"
|
||||||
|
tbody
|
||||||
|
each someone in outboxStatistics
|
||||||
|
tr
|
||||||
|
td.name
|
||||||
|
a(href=someone.name)=someone.name
|
||||||
|
td.counter=someone.counter
|
||||||
|
td.counter=someone.counterContentLength
|
||||||
|
|
||||||
h2 #{outbox.length} of Messages #{outboxTotalLength} in your outbox.First #{max_toots} toots, filtered by a minimal length of #{min_length} characters of content.
|
h2 #{outbox.length} of Messages #{outboxTotalLength} in your outbox.First #{max_toots} toots, filtered by a minimal length of #{min_length} characters of content.
|
||||||
.columns-area__panels__main
|
.columns-area__panels__main
|
||||||
div.column
|
div.column
|
||||||
|
Loading…
Reference in New Issue
Block a user