Added extra pump data
lagged sample in measurement
This commit is contained in:
@@ -325,6 +325,38 @@ class MeasurementContainer {
|
||||
return value;
|
||||
}
|
||||
|
||||
getLaggedSample(lag = 1,requestedUnit = null ){
|
||||
const measurement = this.get();
|
||||
if (!measurement) return null;
|
||||
|
||||
let sample = measurement.getLaggedSample(lag);
|
||||
if (sample === null) return null;
|
||||
|
||||
// Return as-is if no unit conversion requested
|
||||
if (!requestedUnit) {
|
||||
return sample;
|
||||
}
|
||||
|
||||
// Convert if needed
|
||||
if (measurement.unit && requestedUnit !== measurement.unit) {
|
||||
try {
|
||||
const convertedValue = convertModule(value).from(measurement.unit).to(requestedUnit);
|
||||
//replace old value in sample and return obj
|
||||
sample.value = convertedValue ;
|
||||
sample.unit = requestedUnit;
|
||||
return sample;
|
||||
|
||||
} catch (error) {
|
||||
if (this.logger) {
|
||||
this.logger.error(`Unit conversion failed: ${error.message}`);
|
||||
}
|
||||
return sample; // Return original value if conversion fails
|
||||
}
|
||||
}
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
// Difference calculations between positions
|
||||
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
||||
|
||||
@@ -87,6 +87,7 @@ autoContainer
|
||||
.distance(0.5)
|
||||
.value(1.5, Date.now(), 'bar'); // Input: 1.5 bar → Auto-stored as ~21.76 psi
|
||||
|
||||
|
||||
const converted = autoContainer
|
||||
.type('pressure')
|
||||
.variant('measured')
|
||||
@@ -274,8 +275,8 @@ console.log(` History: [${allValues.values.join(', ')}]\n`);
|
||||
console.log('--- Lagged sample comparison ---');
|
||||
|
||||
const latest = stats.getCurrentValue(); // existing helper
|
||||
const prevSample = stats.getLaggedValue(2); // new helper
|
||||
const prevPrevSample = stats.getLaggedValue(3); // optional
|
||||
const prevSample = stats.getLaggedValue(1); // new helper
|
||||
const prevPrevSample = stats.getLaggedValue(2); // optional
|
||||
|
||||
if (prevSample) {
|
||||
const delta = latest - prevSample.value;
|
||||
|
||||
Reference in New Issue
Block a user