sort most talked to recievers

This commit is contained in:
Baptiste Lemoine 2020-07-18 17:40:15 +02:00
parent 148a9f309d
commit e8ff25eb06
2 changed files with 22 additions and 7 deletions

26
main.js
View File

@ -8,7 +8,8 @@ const app = express();
var fs = require('fs');
var listenPort = 8088;
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 TemplateVars = {
pageTitle : 'Mastodon export converter to HTML',
likes : jsonParsedLikes,
@ -53,20 +54,33 @@ fs.readFile('source_data/outbox.json',
minchartoots.forEach(elem => {
if (elem['object'].cc) {
elem['object'].cc.forEach(copyFolk => {
if(!TemplateVars.outboxStatistics[copyFolk]){
if (!TemplateVars.outboxStatistics[copyFolk]) {
TemplateVars.outboxStatistics[copyFolk] = {
name : copyFolk,
counter: 0
}
name : copyFolk,
counter: 0,
};
}
TemplateVars.outboxStatistics[copyFolk].counter += 1;
});
}
});
const statKeys = Object.keys(TemplateVars.outboxStatistics);
const arrayToSort = [];
statKeys.forEach(elem => {
arrayToSort.push(
TemplateVars.outboxStatistics[elem],
);
});
arrayToSort.sort( (a,b)=>{
return b.counter - a.counter
})
console.log('arrayToSort', arrayToSort)
TemplateVars.outboxStatistics = arrayToSort;
console.log('TemplateVars.outbox.length', TemplateVars.outbox.length, TemplateVars.outbox[5]['object'].content.length);
TemplateVars.example = example;
console.log('example', example);
// console.log('example', example);
});
app.use(express.static('public'));
app.set('view engine', 'pug');

View File

@ -10,7 +10,8 @@ html(lang="en")
fieldset.stats
h3 You did sent messages to these people
each someone in outboxStatistics
.name=someone.name
.name
a(href=someone.name)=someone.name
.counter=someone.counter
h2 #{outbox.length} Messages in your outbox. Filtered by a minimal length of #{min_length}
.columns-area__panels__main