added lagged value functionality for retrieving values further down in memory; Converted position always to lower case strings to avoid problems with caps sensitivity names; added examples for use in examples.js

This commit is contained in:
znetsixe
2025-10-16 14:37:42 +02:00
parent f9d1348fd0
commit c99d24e4c6
3 changed files with 69 additions and 4 deletions

View File

@@ -67,6 +67,23 @@ class Measurement {
if (this.values.length === 0) return null;
return this.values[this.values.length - 1];
}
getLaggedValue(lag){
if(this.values.length <= lag) return null;
return this.values[this.values.length - lag];
}
getLaggedSample(lag){
if (lag < 0) throw new Error('lag must be >= 0');
const index = this.values.length - 1 - lag;
if (index < 0) return null;
return {
value: this.values[index],
timestamp: this.timestamps[index],
unit: this.unit,
};
}
getAverage() {
if (this.values.length === 0) return null;