update before closing

This commit is contained in:
znetsixe
2025-10-21 13:44:31 +02:00
parent f29aa4f5af
commit b8b7871e38

View File

@@ -27,6 +27,7 @@ class pumpingStation {
this.initBasinProperties(); this.initBasinProperties();
this.child = {}; // object to hold child information so we know on what to subscribe this.child = {}; // object to hold child information so we know on what to subscribe
this.machines = {}; // object to hold child machine information
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
this.logger.debug('pumpstation Initialized with all helpers'); this.logger.debug('pumpstation Initialized with all helpers');
@@ -36,6 +37,7 @@ class pumpingStation {
registerChild(child, softwareType) { registerChild(child, softwareType) {
this.logger.debug('Setting up child event for softwaretype ' + softwareType); this.logger.debug('Setting up child event for softwaretype ' + softwareType);
//define what to do with measurements
if(softwareType === "measurement"){ if(softwareType === "measurement"){
const position = child.config.functionality.positionVsParent; const position = child.config.functionality.positionVsParent;
const distance = child.config.functionality.distanceVsParent || 0; const distance = child.config.functionality.distanceVsParent || 0;
@@ -51,18 +53,55 @@ class pumpingStation {
this.logger.debug(` Emitting... ${eventName} with data:`); this.logger.debug(` Emitting... ${eventName} with data:`);
// Store directly in parent's measurement container // Store directly in parent's measurement container
this.measurements this.measurements.type(measurementType).variant("measured").position(position).value(eventData.value, eventData.timestamp, eventData.unit);
.type(measurementType)
.variant("measured")
.position(position)
.value(eventData.value, eventData.timestamp, eventData.unit);
// Call the appropriate handler // Call the appropriate handler
this._callMeasurementHandler(measurementType, eventData.value, position, eventData); this._callMeasurementHandler(measurementType, eventData.value, position, eventData);
}); });
} }
//define what to do when machines are connected
if(softwareType == "machine"){
// Check if the machine is already registered
this.machines[child.config.general.id] === undefined ? this.machines[child.config.general.id] = child : this.logger.warn(`Machine ${child.config.general.id} is already registered.`);
//listen for machine pressure changes
this.logger.debug(`Listening for pressure changes from machine ${child.config.general.id}`);
//for now lets focus on handling downstream predicted flow
child.measurements.emitter.on("flow.predicted.downstream", (eventData) => {
this.logger.debug(`Flow prediction update from ${child.config.general.id}: ${eventData.value} ${eventData.unit}`);
this.updateMachineFlowPrediction();
});
} }
}
//how to handle when there are machines connected and there is an updated predicted flow variable
updateMachineFlowPrediction(){
//check if container exists
const hasMeasuredFlow = measurements.type("flow").variant("measured").exists();
//if there is no down / upstream flow being measured we can take the machines flow to calculate the flow and update predicted level
if( ! hasMeasuredFlow ) {
}
}
updateMeasuredTemperature(){
}
updateMeasuredFlow(){
}
_callMeasurementHandler(measurementType, value, position, context) { _callMeasurementHandler(measurementType, value, position, context) {
switch (measurementType) { switch (measurementType) {
case 'pressure': case 'pressure':
@@ -87,7 +126,7 @@ class pumpingStation {
this.updatePosition(); this.updatePosition();
break; break;
} }
} }
// context handler for pressure updates // context handler for pressure updates
updateMeasuredPressure(value, position, context = {}) { updateMeasuredPressure(value, position, context = {}) {
@@ -109,6 +148,7 @@ class pumpingStation {
this.logger.warn(`No temperature measurement available, defaulting to 15C for pressure to level conversion.`); this.logger.warn(`No temperature measurement available, defaulting to 15C for pressure to level conversion.`);
this.measurements.type("temperature").variant("assumed").position("atEquipment").value(15, Date.now(), "C"); this.measurements.type("temperature").variant("assumed").position("atEquipment").value(15, Date.now(), "C");
kelvinTemp = this.measurements.type('temperature').variant('assumed').position('atEquipment').getCurrentValue('K'); kelvinTemp = this.measurements.type('temperature').variant('assumed').position('atEquipment').getCurrentValue('K');
this.logger.debug(`Temperature is : ${kelvinTemp}`);
} else { } else {
kelvinTemp = mTemp; kelvinTemp = mTemp;
} }
@@ -137,9 +177,9 @@ class pumpingStation {
this.logger.debug(`basin minvol : ${this.basin.minVol}, cur volume : ${volume} / ${this.basin.maxVolOverflow}`); this.logger.debug(`basin minvol : ${this.basin.minVol}, cur volume : ${volume} / ${this.basin.maxVolOverflow}`);
const proc = this.interpolate.interpolate_lin_single_point(volume,this.basin.minVol,this.basin.maxVolOverflow,0,100); const proc = this.interpolate.interpolate_lin_single_point(volume,this.basin.minVol,this.basin.maxVolOverflow,0,100);
this.logger.debug(`PROC volume : ${proc}`); this.logger.debug(`PROC volume : ${proc}`);
this.measurements.type("volume").variant("measured").position("atEquipment").value(volume).unit('m3'); this.measurements.type("volume").variant("measured").position("atEquipment").value(volume).unit('m3');
this.measurements.type("volume").variant("procent").position("atEquipment").value(proc) this.measurements.type("volume").variant("procent").position("atEquipment").value(proc);
//calc the most important values back to determine state and net up or downstream flow //calc the most important values back to determine state and net up or downstream flow
@@ -147,8 +187,6 @@ this.logger.debug(`PROC volume : ${proc}`);
} }
_calcNetFlow() { _calcNetFlow() {
const { heightOverflow, heightOutlet, surfaceArea } = this.basin; const { heightOverflow, heightOutlet, surfaceArea } = this.basin;
@@ -218,11 +256,7 @@ this.logger.debug(`PROC volume : ${proc}`);
} }
_calcNetFlowFromLevel({ heightOverflow, heightOutlet, surfaceArea }) { _calcNetFlowFromLevel({ heightOverflow, heightOutlet, surfaceArea }) {
const levelObj = this.measurements const levelObj = this.measurements.type("level").variant("measured").position("atEquipment");
.type("level")
.variant("measured")
.position("atEquipment");
const level = levelObj.getCurrentValue("m"); const level = levelObj.getCurrentValue("m");
const prevLevel = levelObj.getLaggedValue(2, "m"); // { value, timestamp, unit } const prevLevel = levelObj.getLaggedValue(2, "m"); // { value, timestamp, unit }
const measurement = levelObj.get(); const measurement = levelObj.get();
@@ -257,12 +291,7 @@ this.logger.debug(`PROC volume : ${proc}`);
const netFlowRate = lvlRate * surfaceArea; // m³/s inferred from level trend const netFlowRate = lvlRate * surfaceArea; // m³/s inferred from level trend
this.measurements this.measurements.type("netFlowRate").variant("predicted").position("atEquipment").value(netFlowRate).unit("m3/s");
.type("netFlowRate")
.variant("predicted")
.position("atEquipment")
.value(netFlowRate)
.unit("m3/s");
this.logger.warn( this.logger.warn(
`Level-based net flow | rate=${lvlRate.toExponential(3)} m/s, inferred=${netFlowRate.toFixed(3)} m3/s` `Level-based net flow | rate=${lvlRate.toExponential(3)} m/s, inferred=${netFlowRate.toFixed(3)} m3/s`
@@ -298,8 +327,13 @@ this.logger.debug(`PROC volume : ${proc}`);
this.basin.minVol = minVol ; this.basin.minVol = minVol ;
this.basin.minVolOut = minVolOut ; this.basin.minVolOut = minVolOut ;
this.logger.debug( //init predicted min volume to min vol in order to have a starting point
`Basin initialized | area=${surfaceArea.toFixed(2)} m², max=${maxVol.toFixed(2)} m³, overflow=${maxVolOverflow.toFixed(2)}` this.measurements.type("volume").variant("predicted").position("atEquipment").value(minVol).unit('m3');
this.logger.debug(`
Basin initialized | area=${surfaceArea.toFixed(2)} m²,
max=${maxVol.toFixed(2)} m³,
overflow=${maxVolOverflow.toFixed(2)}`
); );