Compare commits
3 Commits
555d4d865b
...
dev-Rene
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
067017f2ea | ||
|
|
52f1cf73b4 | ||
|
|
a81733c492 |
@@ -16,7 +16,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"unit": {
|
"unit": {
|
||||||
"default": "m3/s",
|
"default": "l/s",
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The default measurement unit for this configuration (e.g., 'meters', 'seconds', 'unitless')."
|
"description": "The default measurement unit for this configuration (e.g., 'meters', 'seconds', 'unitless')."
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ class MeasurementContainer {
|
|||||||
this._currentType = typeName;
|
this._currentType = typeName;
|
||||||
this._currentVariant = null;
|
this._currentVariant = null;
|
||||||
this._currentPosition = null;
|
this._currentPosition = null;
|
||||||
|
this._currentChildId = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +100,7 @@ class MeasurementContainer {
|
|||||||
}
|
}
|
||||||
this._currentVariant = variantName;
|
this._currentVariant = variantName;
|
||||||
this._currentPosition = null;
|
this._currentPosition = null;
|
||||||
|
this._currentChildId = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,8 +227,6 @@ class MeasurementContainer {
|
|||||||
return requireValues ? measurement.values?.length > 0 : true;
|
return requireValues ? measurement.values?.length > 0 : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unit(unitName) {
|
unit(unitName) {
|
||||||
if (!this._ensureChainIsValid()) return this;
|
if (!this._ensureChainIsValid()) return this;
|
||||||
|
|
||||||
|
|||||||
@@ -345,6 +345,68 @@ basicContainer.getTypes().forEach(type => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// --- Child Aggregation -----------------------------------------------------
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// ====================================
|
||||||
|
// AGGREGATION WITH CHILD SERIES (sum)
|
||||||
|
// ====================================
|
||||||
|
console.log();
|
||||||
|
console.log('--- Example X: Aggregation with sum() and child series ---');
|
||||||
|
|
||||||
|
// Container where flow is stored internally in m3/h
|
||||||
|
const aggContainer = new MeasurementContainer({
|
||||||
|
windowSize: 10,
|
||||||
|
defaultUnits: {
|
||||||
|
flow: 'm3/h',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Two pumps both feeding the same inlet position
|
||||||
|
aggContainer
|
||||||
|
.child('pumpA')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('inlet')
|
||||||
|
.value(10, Date.now(), 'm3/h'); // 10 m3/h
|
||||||
|
|
||||||
|
aggContainer
|
||||||
|
.child('pumpB')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('inlet')
|
||||||
|
.value(15, Date.now(), 'm3/h'); // 15 m3/h
|
||||||
|
|
||||||
|
// Another position, e.g. outlet, also with two pumps
|
||||||
|
aggContainer
|
||||||
|
.child('pumpA')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('outlet')
|
||||||
|
.value(8, Date.now(), 'm3/h'); // 8 m3/h
|
||||||
|
|
||||||
|
aggContainer
|
||||||
|
.child('pumpB')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('outlet')
|
||||||
|
.value(11, Date.now(), 'm3/h'); // 11 m3/h
|
||||||
|
|
||||||
|
|
||||||
|
// 1) Sum only inlet position (children pumpA + pumpB)
|
||||||
|
const inletTotal = aggContainer.sum('flow', 'measured', ['inlet']);
|
||||||
|
console.log(`Total inlet flow: ${inletTotal} m3/h (expected 25 m3/h)`);
|
||||||
|
|
||||||
|
// 2) Sum inlet + outlet positions together
|
||||||
|
const totalAll = aggContainer.sum('flow', 'measured', ['inlet', 'outlet']);
|
||||||
|
console.log(`Total inlet+outlet flow: ${totalAll} m3/h (expected 44 m3/h)`);
|
||||||
|
|
||||||
|
// 3) Same sum but explicitly ask for a target unit (e.g. l/s)
|
||||||
|
// This will use convertModule(...) internally.
|
||||||
|
// If conversion is not supported, it will fall back to the raw value.
|
||||||
|
const totalAllLps = aggContainer.sum('flow', 'measured', ['inlet', 'outlet'], 'l/s');
|
||||||
|
console.log(`Total inlet+outlet flow in l/s: ${totalAllLps} l/s (converted from m3/h)\n`);
|
||||||
|
|
||||||
|
|
||||||
console.log('\n✅ All examples complete!\n');
|
console.log('\n✅ All examples complete!\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user