-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessing.js
92 lines (84 loc) · 2.54 KB
/
processing.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
"use strict"
let qm = require("qminer");
let loader = require("qminer-data-loader");
// create store for our data stream
let base = new qm.Base({
mode: "createClean",
schema: [{
name: "Sensor",
fields: [
{ name: "Time", type: "datetime" },
{ name: "Value", type: "float" }
]
}]
});
let store = base.store("Sensor");
// first we need to read the value from the store
let tick = store.addStreamAggr({
type: "timeSeriesTick",
timestamp: "Time",
value: "Value"
});
// // create one stream aggregate that prints out the data
// store.addStreamAggr({
// onAdd: rec => { console.log(
// rec.$id, "raw",
// new Date(tick.getTimestamp()).toISOString(),
// tick.getFloat().toFixed(2)
// );}
// });
// // let's compute moving average on the data
// // first we keep it in the time window
// let window = store.addStreamAggr({
// type: "timeSeriesWinBufVector",
// inAggr: tick,
// winsize: 10*1000 // we keep 10 seconds
// });
// // now compute moving average on the window
// let ma = store.addStreamAggr({
// type: "ma",
// inAggr: window
// });
// // and print what we read
// store.addStreamAggr({
// onAdd: rec => { console.log(
// "MAvg",
// new Date(tick.getTimestamp()).toISOString(),
// ma.getFloat().toFixed(2)
// );}
// });
// // we can avoid keeping time window if we compute exponential moving average (EMA)
// let ema = store.addStreamAggr({
// type: "ema",
// inAggr: tick,
// emaType: "previous", // [previous, next, linear]
// interval: 10*1000, // values from the last 10 seconds contribute 90%
// initWindow: 10*1000 // how much do we need to initialize
// });
// // and print what we read
// store.addStreamAggr({
// onAdd: rec => { console.log(
// "EMA",
// new Date(tick.getTimestamp()).toISOString(),
// ema.getFloat().toFixed(2)
// );}
// });
// can we resample to have equally spaced time series
let resampler = store.addStreamAggr({
type: "aggrResample",
inAggr: tick,
roundStart: "m", // output on round seconds
interval: 60*1000, // we output one measurement per second
aggType: "avg" // [sum, avg, min, max]
});
// print the output
let resamplerOut = new qm.StreamAggr(base, {
onStep: () => { console.log(
"Resampler",
new Date(resampler.getTimestamp()).toISOString(),
resampler.getFloat().toFixed(2)
);}
});
resampler.setParams({ outAggr: resamplerOut });
// load data
loader.loadBrownianDataset(store);