-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat-cruncher.js
executable file
·78 lines (69 loc) · 1.56 KB
/
stat-cruncher.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const Promise = require('bluebird');
const fs = require('fs');
fs.readFile('epl1920stat.json', 'utf-8', handleFile);
function handleFile(err, data) {
if (err) throw err;
players = JSON.parse(data);
let stats = [
"appearances",
"height",
"weight",
"saves",
"goalsConceded",
"cleanSheets",
"goals",
"assists",
"tackles",
"shots",
"keyPasses"
]
for (let stat of stats) {
console.log("Top 20 " + stat);
console.log("=========");
let a = players.filter(function(player) {
return player[stat] > 0;
})
.sort(function (a, b) {
return b[stat] - a[stat];
})
.slice(0, 20)
.map(function(player, index) {
// return `${player.name}: ${player[stat]}`;
return {
rank: index + 1,
name: player.name,
[stat]: player[stat]
};
});
// for (s of a) {
// console.log(s.name + ' = ' + s[stat]);
// }
console.table(a);
}
// let topHeight = players.filter(function(player) {
// return player.height > 0;
// })
// .sort(function (a, b) {
// return b.height - a.height;
// })
// .slice(0, 20)
// .map(function (player) {
// return {
// name: player.name,
// height: player.height
// };
// });
// console.log(topHeight);
// console.log(players);
// let topKeyPasses = players.sort(function(a, b) {
// return b.tackles - a.tackles;
// })
// .slice(0, 20)
// .map(function({name, tackles}) {
// return {
// name,
// tackles
// };
// });
// console.log(topKeyPasses);
}