update before closing
This commit is contained in:
@@ -27,6 +27,7 @@ class pumpingStation {
|
||||
this.initBasinProperties();
|
||||
|
||||
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.logger.debug('pumpstation Initialized with all helpers');
|
||||
@@ -36,6 +37,7 @@ class pumpingStation {
|
||||
registerChild(child, softwareType) {
|
||||
this.logger.debug('Setting up child event for softwaretype ' + softwareType);
|
||||
|
||||
//define what to do with measurements
|
||||
if(softwareType === "measurement"){
|
||||
const position = child.config.functionality.positionVsParent;
|
||||
const distance = child.config.functionality.distanceVsParent || 0;
|
||||
@@ -51,18 +53,55 @@ class pumpingStation {
|
||||
|
||||
this.logger.debug(` Emitting... ${eventName} with data:`);
|
||||
// Store directly in parent's measurement container
|
||||
this.measurements
|
||||
.type(measurementType)
|
||||
.variant("measured")
|
||||
.position(position)
|
||||
.value(eventData.value, eventData.timestamp, eventData.unit);
|
||||
this.measurements.type(measurementType).variant("measured").position(position).value(eventData.value, eventData.timestamp, eventData.unit);
|
||||
|
||||
// Call the appropriate handler
|
||||
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) {
|
||||
switch (measurementType) {
|
||||
case 'pressure':
|
||||
@@ -109,6 +148,7 @@ class pumpingStation {
|
||||
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");
|
||||
kelvinTemp = this.measurements.type('temperature').variant('assumed').position('atEquipment').getCurrentValue('K');
|
||||
this.logger.debug(`Temperature is : ${kelvinTemp}`);
|
||||
} else {
|
||||
kelvinTemp = mTemp;
|
||||
}
|
||||
@@ -139,7 +179,7 @@ class pumpingStation {
|
||||
const proc = this.interpolate.interpolate_lin_single_point(volume,this.basin.minVol,this.basin.maxVolOverflow,0,100);
|
||||
this.logger.debug(`PROC volume : ${proc}`);
|
||||
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
|
||||
@@ -147,8 +187,6 @@ this.logger.debug(`PROC volume : ${proc}`);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
_calcNetFlow() {
|
||||
const { heightOverflow, heightOutlet, surfaceArea } = this.basin;
|
||||
|
||||
@@ -218,11 +256,7 @@ this.logger.debug(`PROC volume : ${proc}`);
|
||||
}
|
||||
|
||||
_calcNetFlowFromLevel({ heightOverflow, heightOutlet, surfaceArea }) {
|
||||
const levelObj = this.measurements
|
||||
.type("level")
|
||||
.variant("measured")
|
||||
.position("atEquipment");
|
||||
|
||||
const levelObj = this.measurements.type("level").variant("measured").position("atEquipment");
|
||||
const level = levelObj.getCurrentValue("m");
|
||||
const prevLevel = levelObj.getLaggedValue(2, "m"); // { value, timestamp, unit }
|
||||
const measurement = levelObj.get();
|
||||
@@ -257,12 +291,7 @@ this.logger.debug(`PROC volume : ${proc}`);
|
||||
|
||||
const netFlowRate = lvlRate * surfaceArea; // m³/s inferred from level trend
|
||||
|
||||
this.measurements
|
||||
.type("netFlowRate")
|
||||
.variant("predicted")
|
||||
.position("atEquipment")
|
||||
.value(netFlowRate)
|
||||
.unit("m3/s");
|
||||
this.measurements.type("netFlowRate").variant("predicted").position("atEquipment").value(netFlowRate).unit("m3/s");
|
||||
|
||||
this.logger.warn(
|
||||
`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.minVolOut = minVolOut ;
|
||||
|
||||
this.logger.debug(
|
||||
`Basin initialized | area=${surfaceArea.toFixed(2)} m², max=${maxVol.toFixed(2)} m³, overflow=${maxVolOverflow.toFixed(2)} m³`
|
||||
//init predicted min volume to min vol in order to have a starting point
|
||||
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)} m³`
|
||||
);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user