-
Notifications
You must be signed in to change notification settings - Fork 0
/
popular_users.js
40 lines (31 loc) · 980 Bytes
/
popular_users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var fs = require('fs');
var buffer = fs.readFileSync('./discus_fish_1417444247432.json');
var blocks = JSON.parse(buffer);
var users = {};
for( var i = 0; i < blocks.length - 1; i++ ) {
try{
if(blocks[i].user){
if(users[blocks[i].user]){
users[blocks[i].user]++
} else {
users[blocks[i].user] = 1;
}
}
} catch(e){
}
}
//console.log(users); process.exit(0);
var usersKeysSorted = Object.keys(users).sort(function(a,b){ return - users[a] + users[b] });
// console.log(usersKeysSorted);
var res = {};
for(var i=0; i<20; i++){
res[usersKeysSorted[i]] = users[usersKeysSorted[i]];
}
console.log(res);
// fileName = 'discus_fish_' + (new Date).getTime() + '.json';
// fs.writeFile(fileName, JSON.stringify(transactions, null, 4), function (err) {
// if( err )
// console.log(err);
// else
// console.log('The file was saved: ' + fileName);
// });