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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user