-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfixdata.js
28 lines (24 loc) · 828 Bytes
/
fixdata.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
const fs = require("fs");
const dir = fs.readdirSync("./tmp/data").sort().reverse();
const reqFile = (path) => require("./tmp/data/" + path);
let data = reqFile(dir[0]);
function merge(first, second) {
for(let item of second) {
let i = first.findIndex(t => t.date === item.date);
if(i !== -1) {
first[i].value = Math.max(item.value, first[i].value);
} else {
first.push(item);
}
}
return first;
}
for(let file of dir) {
let current = reqFile(file);
if(!current.activityHistory[0].size || !current.activityHistory[0].size.length) continue; // JS moment
let b = data;
data = current;
current = b;
data.activityHistory[0].size = merge(current.activityHistory[0].size, data.activityHistory[0].size);
}
console.log(JSON.stringify(data));