added sum and child id support

This commit is contained in:
znetsixe
2025-11-28 09:59:39 +01:00
parent db85100c4d
commit 555d4d865b
3 changed files with 148 additions and 69 deletions

View File

@@ -177,18 +177,18 @@ const downstreamData = basicContainer
.get();
//check wether a serie exists
const hasSeries = measurements
const hasSeries = basicContainer
.type("flow")
.variant("measured")
.exists(); // true if any position exists
const hasUpstreamValues = measurements
const hasUpstreamValues = basicContainer
.type("flow")
.variant("measured")
.exists({ position: "upstream", requireValues: true });
// Passing everything explicitly
const hasPercent = measurements.exists({
const hasPercent = basicContainer.exists({
type: "volume",
variant: "percent",
position: "atEquipment",
@@ -274,14 +274,14 @@ console.log(` History: [${allValues.values.join(', ')}]\n`);
console.log('--- Lagged sample comparison ---');
const latest = stats.getCurrentValue(); // existing helper
const prevSample = stats.getLaggedValue(1); // new helper
const prevPrevSample = stats.getLaggedValue(2); // optional
const latestSample = stats.getLaggedSample(0); // newest sample object
const prevSample = stats.getLaggedSample(1);
const prevPrevSample = stats.getLaggedSample(2);
if (prevSample) {
const delta = latest - prevSample.value;
const delta = (latestSample?.value ?? 0) - (prevSample.value ?? 0);
console.log(
`Current vs previous: ${latest} ${statsData.unit} (t=${stats.get().getLatestTimestamp()}) vs ` +
`Current vs previous: ${latestSample?.value} ${statsData.unit} (t=${latestSample?.timestamp}) vs ` +
`${prevSample.value} ${prevSample.unit} (t=${prevSample.timestamp})`
);
console.log(`Δ = ${delta.toFixed(2)} ${statsData.unit}`);