CycleView & more
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PeakDetectorSimple } from './PeakDetection';
|
||||
import { MovingAverage} from './MovingAverage';
|
||||
import { List } from 'immutable';
|
||||
|
||||
|
||||
@@ -25,8 +26,16 @@ export default class DataAnalysis {
|
||||
console.log("cache reset");
|
||||
}
|
||||
|
||||
const newDataArr = newData.toArray();
|
||||
|
||||
// active time
|
||||
const newAverages = this.movingAverage.addVector(newDataArr);
|
||||
this.activeMeasurements += newAverages.reduce((n, val) => {
|
||||
return n + (val >= analysisParameters.activeTimeThreshold);
|
||||
});
|
||||
|
||||
// peaks
|
||||
const newPeaks = this.peakDetectorSimple.addVector(newData.toArray());
|
||||
const newPeaks = this.peakDetectorSimple.addVector(newDataArr);
|
||||
this.allPeaks = this.allPeaks.concat(List(newPeaks));
|
||||
|
||||
// aggregated sum/max
|
||||
@@ -38,11 +47,13 @@ export default class DataAnalysis {
|
||||
const windowed = allMeasurements.slice(-windowNumDataPoints);
|
||||
const peakMaxWindow = windowed.reduce((running, x) => Math.max(x, running), 0);
|
||||
const momentumWindow = windowed.reduce((sum, x) => sum + x, 0);
|
||||
|
||||
|
||||
this.analyzedUpToIdx = allMeasurements.size;
|
||||
return {
|
||||
peaks: this.allPeaks,
|
||||
totalTime: allMeasurements / analysisParameters.numMeasurementsPerSec,
|
||||
activeTime: this.activeMeasurements / analysisParameters.numMeasurementsPerSec,
|
||||
|
||||
totalMomentum: this.aggregatedMomentum,
|
||||
peakMax: this.peakMax,
|
||||
@@ -54,6 +65,9 @@ export default class DataAnalysis {
|
||||
|
||||
|
||||
_resetCache(analysisParameters, sessionId) {
|
||||
this.movingAverage = analysisParameters ? new MovingAverage(analysisParameters.movingAverageWindowSize) : null;
|
||||
this.activeMeasurements = 0;
|
||||
|
||||
this.peakDetectorSimple = analysisParameters ? new PeakDetectorSimple(analysisParameters.peakDetectorSimpleThreshold) : null;
|
||||
this.allPeaks = List();
|
||||
|
||||
|
||||
29
data_processing/MovingAverage.js
Normal file
29
data_processing/MovingAverage.js
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
/**
|
||||
* A moving average computation
|
||||
*/
|
||||
export class MovingAverage {
|
||||
constructor(windowSize) {
|
||||
this._windowSize = windowSize;
|
||||
this._queue = [];
|
||||
this._queueSum = 0;
|
||||
}
|
||||
|
||||
windowSize() {
|
||||
return this._windowSize;
|
||||
}
|
||||
|
||||
addVector(vec) {
|
||||
return vec.map(this.add.bind(this));
|
||||
}
|
||||
|
||||
add(value) {
|
||||
this._queueSum += value;
|
||||
this._queue.push(value);
|
||||
if(this._queue.length > this._windowSize) {
|
||||
this._queueSum -= this._queue[0];
|
||||
this._queue.shift();
|
||||
}
|
||||
return this._queueSum / this._queue.length;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user