This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaggregate.js
148 lines (139 loc) · 5.95 KB
/
aggregate.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var mysql = require("./collection/mysql");
var batch_size = 2500;
async function main() {
console.log("Clearing existing data");
await mysql.clearAllStatistics();
console.log("Starting kills aggregation");
var limits = await mysql.getLimits("kills");
console.log("Progress:");
console.log("0%----------------------------------------------------------------------------------------------------100%");
var lastPercent = 0;
var currentPercent = 0;
process.stdout.write(' [');
let size = limits[0].last - limits[0].first;
for (let id = limits[0].first; id < limits[0].last; id += batch_size) {
let result = await mysql.aggregateKills(id, id + batch_size);
for (let row of result) {
try {
await mysql.updateKillStatistics(row.character_name, row.monster_name, row.map, row.monster_level, row.kills, row.total_gold);
} catch (e) {
console.log("Invalid Row" + row);
}
}
currentPercent = Math.floor(id / size * 100);
for (let i = 0; i < currentPercent - lastPercent; i++)
process.stdout.write('#');
lastPercent = currentPercent;
}
for (let i = 0; i < 100 - lastPercent; i++)
process.stdout.write('#');
process.stdout.write('] \n');
console.log("Finished kills aggregation")
console.log("Starting drops aggregation");
limits = await mysql.getLimits("drops");
console.log("Progress:");
console.log("0%----------------------------------------------------------------------------------------------------100%");
lastPercent = 0;
currentPercent = 0;
process.stdout.write(' [');
size = limits[0].last - limits[0].first;
for (let id = limits[0].first; id < limits[0].last; id += batch_size) {
let result = await mysql.aggregateDrops(id, id + batch_size);
for (let row of result) {
try {
await mysql.updateDropStatistics(row.monster_name, row.item_name, row.map, row.monster_level, row.seen);
} catch (e) {
console.log("Invalid Row" + row);
}
}
currentPercent = Math.floor(id / size * 100);
for (let i = 0; i < currentPercent - lastPercent; i++)
process.stdout.write('#');
lastPercent = currentPercent;
}
for (let i = 0; i < 100 - lastPercent; i++)
process.stdout.write('#');
process.stdout.write('] \n');
console.log("Finished drops aggregation");
console.log("Starting exchange aggregation");
limits = await mysql.getLimits("exchanges");
console.log("Progress:");
console.log("0%----------------------------------------------------------------------------------------------------100%");
lastPercent = 0;
currentPercent = 0;
process.stdout.write(' [');
size = limits[0].last - limits[0].first;
for (let id = limits[0].first; id < limits[0].last; id += batch_size) {
let result = await mysql.aggregateExchanges(id, id + batch_size);
for (let row of result) {
try {
await mysql.updateExchangeStatistics(row.item_name, row.item_level, row.result, row.amount, row.seen);
} catch (e) {
console.log("Invalid Row" + row);
}
}
currentPercent = Math.floor(id / size * 100);
for (let i = 0; i < currentPercent - lastPercent; i++)
process.stdout.write('#');
lastPercent = currentPercent;
}
for (let i = 0; i < 100 - lastPercent; i++)
process.stdout.write('#');
process.stdout.write('] \n');
console.log("Finished exchange aggregation");
console.log("Starting compound aggregation");
limits = await mysql.getLimits("compounds");
console.log("Progress:");
console.log("0%----------------------------------------------------------------------------------------------------100%");
lastPercent = 0;
currentPercent = 0;
process.stdout.write(' [');
size = limits[0].last - limits[0].first;
for (let id = limits[0].first; id < limits[0].last; id += batch_size) {
let result = await mysql.aggregateCompounds(id, id + batch_size);
for (let row of result) {
try {
await mysql.updateCompoundsStatistics(row.item_name, row.item_level, row.total, row.success);
} catch (e) {
console.log("Invalid Row" + row);
}
}
currentPercent = Math.floor(id / size * 100);
for (let i = 0; i < currentPercent - lastPercent; i++)
process.stdout.write('#');
lastPercent = currentPercent;
}
for (let i = 0; i < 100 - lastPercent; i++)
process.stdout.write('#');
process.stdout.write('] \n');
console.log("Finished compound aggregation");
console.log("Starting upgrade aggregation");
limits = await mysql.getLimits("upgrades");
console.log("Progress:");
console.log("0%----------------------------------------------------------------------------------------------------100%");
lastPercent = 0;
currentPercent = 0;
process.stdout.write(' [');
size = limits[0].last - limits[0].first;
for (let id = limits[0].first; id < limits[0].last; id += batch_size) {
let result = await mysql.aggregateUpgrades(id, id + batch_size);
for (let row of result) {
try {
await mysql.updateUpgradesStatistics(row.item_name, row.item_level, row.total, row.success);
} catch (e) {
console.log("Invalid Row" + row);
}
}
currentPercent = Math.floor(id / size * 100);
for (let i = 0; i < currentPercent - lastPercent; i++)
process.stdout.write('#');
lastPercent = currentPercent;
}
for (let i = 0; i < 100 - lastPercent; i++)
process.stdout.write('#');
process.stdout.write('] \n')
console.log("Finished upgrade aggregation");
console.log("All statistics have been updated");
process.exit();
}
main();