-
Notifications
You must be signed in to change notification settings - Fork 0
/
population.js
87 lines (71 loc) · 1.94 KB
/
population.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
79
80
81
82
83
84
85
86
87
//===----------------------------------------------------------------------===//
//
// Violet API Server Population Eggreator
//
//===----------------------------------------------------------------------===//
//
// Copyright (C) 2021. violet-team. All Rights Reserved.
//
//===----------------------------------------------------------------------===//
const a_syncdatabase = require("./api/syncdatabase");
const path = require("path");
const fs = require("fs");
async function _cachePopulationSource() {
const conn = a_syncdatabase();
for (var i = 0; i < 30; i++) {
const data = conn.query(
`SELECT ArticleId FROM viewtime WHERE ViewSeconds>=24
order by Id limit 1000000 offset ` + (i * 1000000).toString()
);
const dataPath = path.resolve(
__dirname,
"population-src-" + i.toString() + ".json"
);
console.log(data.length);
console.log(data[0]);
fs.writeFileSync(
dataPath,
JSON.stringify(data.map((x) => x["ArticleId"])),
function (err) {
console.log(err);
process.exit();
}
);
}
}
// _cachePopulationSource();
async function _buildPopulation() {
var rr = {};
for (var i = 0; i < 30; i++) {
const dataPath = path.resolve(
__dirname,
"population-src-" + i.toString() + ".json"
);
var j = JSON.parse(fs.readFileSync(dataPath));
for (var x of j) {
if (x in rr) rr[x] += 1;
else rr[x] = 1;
}
console.log(j.length);
}
var items = Object.keys(rr).map(function(key) {
return [key, rr[key]];
});
// Sort the array based on the second element
items.sort(function(first, second) {
return second[1] - first[1];
});
const dataPath2 = path.resolve(
__dirname,
"population.json"
);
fs.writeFileSync(
dataPath2,
JSON.stringify(items.map((x) => parseInt(x[0]))),
function (err) {
console.log(err);
process.exit();
}
);
}
_buildPopulation();