75 lines
2.1 KiB
JavaScript
Executable File
75 lines
2.1 KiB
JavaScript
Executable File
exports.name = 'masto_conversion';
|
|
const fs = require('fs');
|
|
|
|
class Conversion {
|
|
hello(){
|
|
console.log('hello from conversion')
|
|
}
|
|
likes(){
|
|
// read file likes
|
|
fs.readFile('source_data/likes.json',
|
|
// callback function that is called when reading file is done
|
|
function (err, data) {
|
|
// parse json
|
|
let jsonParsedLikes = JSON.parse(data);
|
|
// access elements
|
|
const lengthOfLikes = jsonParsedLikes.orderedItems.length;
|
|
console.log('likes length', lengthOfLikes);
|
|
return jsonParsedLikes;
|
|
});
|
|
}
|
|
|
|
filterToots(toots,options){
|
|
let minchartoots ;
|
|
|
|
if(options.filterBiggerTottsBeforeSlicing){
|
|
minchartoots = toots.filter(item => {
|
|
return item['object'].content && item['object'].content.length > options.min_length;
|
|
});
|
|
minchartoots = minchartoots.slice(0, options.max_toots);
|
|
}else{
|
|
const slice = toots.slice(0, options.max_toots);
|
|
minchartoots = slice.filter(item => {
|
|
return item['object'].content && item['object'].content.length > options.min_length;
|
|
});
|
|
}
|
|
return minchartoots
|
|
}
|
|
|
|
makeStatsForToots(tootArray){
|
|
let stats = {};
|
|
// 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 (!stats[copyFolk]) {
|
|
stats[copyFolk] = {
|
|
name : copyFolk,
|
|
counter: 0,
|
|
counterContentLength: 0,
|
|
};
|
|
}
|
|
stats[copyFolk].counter += 1;
|
|
stats[copyFolk].counterContentLength += elem['object'].content.length;
|
|
});
|
|
}
|
|
});
|
|
return this.sortTootsByLength(stats);
|
|
}
|
|
|
|
sortTootsByLength(stats){
|
|
const statKeys = Object.keys(stats);
|
|
const arrayToSort = [];
|
|
statKeys.forEach(elem => {
|
|
arrayToSort.push(
|
|
stats[elem],
|
|
);
|
|
});
|
|
arrayToSort.sort( (a,b)=>{
|
|
return b.counter - a.counter
|
|
});
|
|
return arrayToSort;
|
|
}
|
|
}
|
|
exports.conversion = new Conversion();
|