added examples

This commit is contained in:
Rene De ren
2025-11-28 16:29:24 +01:00
parent 555d4d865b
commit a81733c492

View File

@@ -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');