App, peak detection bugfix
This commit is contained in:
@@ -57,16 +57,17 @@ class DataProcessing {
|
||||
if (running) {
|
||||
console.log("Starting session", deviceURL + "/api/session/start" );
|
||||
req.open("GET", deviceURL + "/api/session/start");
|
||||
req.send();
|
||||
this.dataSource.startIndex = 0;
|
||||
this.dataSource.start();
|
||||
} else {
|
||||
console.log("Stopping session");
|
||||
req.open("GET", deviceURL + "/api/session/stop");
|
||||
req.send();
|
||||
this.dataSource.stop();
|
||||
this.dataSource.startIndex = 0;
|
||||
}
|
||||
req.addEventListener("error", evt => console.log(evt));
|
||||
req.addEventListener("abort", evt => console.log(evt));
|
||||
req.send();
|
||||
}
|
||||
|
||||
onNewData = (data) => {
|
||||
@@ -76,9 +77,7 @@ class DataProcessing {
|
||||
let success = false;
|
||||
if (data.sessionStartTime == this.sessionStartTime && data.startIndex == this.rawMeasurements.size) {
|
||||
// normal case, add received data to measurement array
|
||||
console.log("success: normal case");
|
||||
this.rawMeasurements = this.rawMeasurements.concat(List(data.values));
|
||||
this.analyzeNewMeasurements(data.startIndex);
|
||||
success = true;
|
||||
}
|
||||
else if (data.startIndex === 0) {
|
||||
@@ -86,7 +85,6 @@ class DataProcessing {
|
||||
this.sessionStartTime = data.sessionStartTime;
|
||||
this.rawMeasurements = List(data.values);
|
||||
success = true;
|
||||
console.log("New start", this.sessionStartTime, this.rawMeasurements.toArray());
|
||||
} else {
|
||||
console.log("Requery :(");
|
||||
console.log("this.sessionStartTime", this.sessionStartTime);
|
||||
@@ -102,7 +100,6 @@ class DataProcessing {
|
||||
if (success) {
|
||||
const analysis = this.analyzeNewMeasurements(data.startIndex);
|
||||
const report = reportDeviceData(this.sessionStartTime, data.startIndex, this.rawMeasurements, analysis);
|
||||
console.log("reporting device data", report);
|
||||
this.store.dispatch(report);
|
||||
}
|
||||
}
|
||||
@@ -111,7 +108,6 @@ class DataProcessing {
|
||||
//TODO is ".toArray()" really necessary here?
|
||||
const newPeaks = this.peakDetectorSimple.addVector(this.rawMeasurements.slice(newDataStartIdx).toArray());
|
||||
this.peaks = this.peaks.concat(List(newPeaks));
|
||||
console.log("new peaks", newPeaks, "total peaks", this.peaks.toArray());
|
||||
const totalMomentum = this.rawMeasurements.reduce((sum, x) => sum + x, 0);
|
||||
const peakMax = this.rawMeasurements.reduce((running, x) => Math.max(x, running), 0);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as msgpack from 'msgpack-lite';
|
||||
|
||||
class DeviceHttpDataSource {
|
||||
|
||||
constructor(dataUrl, onNewData, pollInterval=2000, startIndex = 0) {
|
||||
constructor(dataUrl, onNewData, pollInterval=800, startIndex = 0) {
|
||||
this.dataUrl = dataUrl;
|
||||
this.onNewData = onNewData;
|
||||
this.pollInterval = pollInterval;
|
||||
|
||||
@@ -41,7 +41,8 @@ class PeakDetectorSimple {
|
||||
const [last, current, next] = this._queue;
|
||||
const is_maximum = current > next && current > last;
|
||||
if (is_maximum && (current - this._last_min) > this._threshold) {
|
||||
result = this._counter;
|
||||
result = this._counter + 1;
|
||||
this._last_min = current;
|
||||
}
|
||||
this._last_min = Math.min(this._last_min, current);
|
||||
this._counter += 1;
|
||||
|
||||
11
data_processing/PeakDetection.test.js
Normal file
11
data_processing/PeakDetection.test.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { PeakDetectorSimple } from './PeakDetection';
|
||||
|
||||
describe("test PeakDetectorSimple", () => {
|
||||
|
||||
it("detects simple peak", () => {
|
||||
let pd = new PeakDetectorSimple(40);
|
||||
const result = pd.addVector([0, 10, 30, 50, 30, 50, 2, 0, 60, 0 ]);
|
||||
expect(result).toEqual([3, 8]);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user