added pumpingStation config, expanded functionality for difference in measurement container

This commit is contained in:
znetsixe
2025-10-15 14:09:37 +02:00
parent 428c611ec6
commit f9d1348fd0
3 changed files with 69 additions and 42 deletions

View File

@@ -248,37 +248,42 @@ class MeasurementContainer {
}
differenceUpDown(){
}
// Difference calculations between positions
difference(requestedUnit = null) {
if (!this._currentType || !this._currentVariant) {
throw new Error('Type and variant must be specified for difference calculation');
}
const upstream = this.measurements?.[this._currentType]?.[this._currentVariant]?.['upstream'] || null;
const downstream = this.measurements?.[this._currentType]?.[this._currentVariant]?.['downstream'] || null;
if (!upstream || !downstream || upstream.values.length === 0 || downstream.values.length === 0) {
return null;
}
// Get target unit for conversion
const targetUnit = requestedUnit || upstream.unit || downstream.unit;
// Get values in the same unit
const upstreamValue = this._convertValueToUnit(upstream.getCurrentValue(), upstream.unit, targetUnit);
const downstreamValue = this._convertValueToUnit(downstream.getCurrentValue(), downstream.unit, targetUnit);
const upstreamAvg = this._convertValueToUnit(upstream.getAverage(), upstream.unit, targetUnit);
const downstreamAvg = this._convertValueToUnit(downstream.getAverage(), downstream.unit, targetUnit);
return {
value: downstreamValue - upstreamValue,
avgDiff: downstreamAvg - upstreamAvg,
unit: targetUnit
};
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
if (!this._currentType || !this._currentVariant) {
throw new Error("Type and variant must be specified for difference calculation");
}
const get = pos =>
this.measurements?.[this._currentType]?.[this._currentVariant]?.[pos] || null;
const a = get(from);
const b = get(to);
if (!a || !b || a.values.length === 0 || b.values.length === 0) {
return null;
}
const targetUnit = requestedUnit || a.unit || b.unit;
const aVal = this._convertValueToUnit(a.getCurrentValue(), a.unit, targetUnit);
const bVal = this._convertValueToUnit(b.getCurrentValue(), b.unit, targetUnit);
const aAvg = this._convertValueToUnit(a.getAverage(), a.unit, targetUnit);
const bAvg = this._convertValueToUnit(b.getAverage(), b.unit, targetUnit);
return {
value: aVal - bVal,
avgDiff: aAvg - bAvg,
unit: targetUnit,
from,
to,
};
}
// Helper methods
_ensureChainIsValid() {
if (!this._currentType || !this._currentVariant || !this._currentPosition) {