Updated distance in measurement helper so its a settable compoment. See example.js file in measurement helper folder

This commit is contained in:
znetsixe
2025-10-05 09:34:00 +02:00
parent d99561fa80
commit de0b947c56
5 changed files with 348 additions and 274 deletions

View File

@@ -2,11 +2,12 @@
const convertModule = require('../convert/index');
class Measurement {
constructor(type, variant, position, windowSize) {
constructor(type, variant, position, windowSize, distance = null) {
this.type = type; // e.g. 'pressure', 'flow', etc.
this.variant = variant; // e.g. 'predicted' or 'measured', etc..
this.position = position; // Downstream or upstream of parent object
this.windowSize = windowSize; // Rolling window size
this.distance = distance; // Distance from parent, if applicable
// Place all data inside an array
this.values = []; // Array to store all values
@@ -36,13 +37,12 @@ class Measurement {
return this;
}
setDistance(distance) {
this.distance = distance;
return this;
}
setValue(value, timestamp = Date.now()) {
/*
if (value === undefined || value === null) {
value = null ;
//throw new Error('Value cannot be null or undefined');
}
*/
//shift the oldest value
if(this.values.length >= this.windowSize){
@@ -168,7 +168,8 @@ class Measurement {
this.type,
this.variant,
this.position,
this.windowSize
this.windowSize,
this.distance
);
// Copy values and timestamps