-
Notifications
You must be signed in to change notification settings - Fork 13
/
export-popularity.js
37 lines (32 loc) · 1.09 KB
/
export-popularity.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
const fs = require("fs");
const groupdata = require("./report.json").data;
// Looking at activity over the last 3 months
const lastXMonths = (period => {
const now = new Date();
const ayearago = new Date();
const months = [];
ayearago.setDate(1);
ayearago.setMonth(ayearago.getMonth() - (period - 1));
while (ayearago < now) {
months.push(ayearago.toJSON().slice(0,7));
ayearago.setMonth(ayearago.getMonth() + 1);
}
return months;
})(3);
let activityLevels = [];
groupdata.filter(d => d && ["cg", "bg"].includes(d.type))
.forEach(d => {
let total = 0;
['lists', 'repository', 'wiki', 'rss', 'join']
.forEach(servicetype => {
const data = d.activity[servicetype];
let values = [];
if (data && Object.keys(data)) {
values = lastXMonths.map(m => data[m] || 0);
}
total += values.reduce((acc, d) => acc + d, 0);
})
activityLevels.push({id: d.id, activity: total});
});
activityLevels.sort((a,b) => b.activity - a.activity);
fs.writeFileSync("popularity.json", JSON.stringify(activityLevels.map(d => d.id), null, 2));