-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
42 lines (35 loc) · 1.24 KB
/
utils.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
function getTimeSeries(dataList, getFieldFunction) {
timeseries = [];
for (let it = 0; it < dataList.length; it++) { timeseries[dataList[it]['timestamp']] = getFieldFunction(dataList[it]);}
return timeseries;
}
function getNodesTimeSeries(dataList, getFieldFunction) {
timeseries = [];
for (let it = 0; it < dataList.length; it++) {
let data = dataList[it];
let timeddata = [];
for (let nc = 0; nc < data.nodes.length; nc++) {
timeddata.push(getFieldFunction(data.nodes[nc]));
}
timeseries[data['timestamp']] = timeddata;
}
return timeseries;
}
function aggregateI (cutout) {
return aggregate(cutout, function (data) {return data;});
}
function aggregate (cutout, getDataFunc) {
var dict = {"unknown" : 0};
for (i in cutout) {
let val = getDataFunc(cutout[i]);
if (val) {
if (Object.keys(dict).includes(val)) { dict[val] += 1;
} else { dict[val] = 1; }
} else { dict['unknown'] += 1; }
}
return Object.entries(dict);
}
function aggregateTimeSeries(timeseries) {
for (series in timeseries) { timeseries[series] = aggregateI(timeseries[series]); }
return timeseries;
}