Compare commits
22 Commits
fbfcec4b47
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e2ebe4d96 | ||
|
|
e8dd657b4f | ||
|
|
c62d8bc275 | ||
|
|
f869296832 | ||
|
|
9f430cebb5 | ||
|
|
7d05d37678 | ||
|
|
762770a063 | ||
|
|
3ff76228eb | ||
|
|
f01b0bcb19 | ||
|
|
4e098eefaa | ||
|
|
90f87bb538 | ||
|
|
8fe9c7ec05 | ||
|
|
7efd3b0a07 | ||
|
|
c81ee1b470 | ||
|
|
955c17a466 | ||
|
|
052ded7b6e | ||
|
|
321ea33bf7 | ||
|
|
288bd244dd | ||
|
|
d91609b3a4 | ||
|
|
5a575a29fe | ||
|
|
0a6c7ee2e1 | ||
|
|
4cc529b1c2 |
23
CLAUDE.md
Normal file
23
CLAUDE.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# pumpingStation — Claude Code context
|
||||||
|
|
||||||
|
Wet-well basin model and pump orchestration.
|
||||||
|
Part of the [EVOLV](https://gitea.wbd-rd.nl/RnD/EVOLV) wastewater-automation platform.
|
||||||
|
|
||||||
|
## S88 classification
|
||||||
|
|
||||||
|
| Level | Colour | Placement lane |
|
||||||
|
|---|---|---|
|
||||||
|
| **Process Cell** | `#0c99d9` | L5 |
|
||||||
|
|
||||||
|
## Flow layout rules
|
||||||
|
|
||||||
|
When wiring this node into a multi-node demo or production flow, follow the
|
||||||
|
placement rule set in the **EVOLV superproject**:
|
||||||
|
|
||||||
|
> `.claude/rules/node-red-flow-layout.md` (in the EVOLV repo root)
|
||||||
|
|
||||||
|
Key points for this node:
|
||||||
|
- Place on lane **L5** (x-position per the lane table in the rule).
|
||||||
|
- Stack same-level siblings vertically.
|
||||||
|
- Parent/children sit on adjacent lanes (children one lane left, parent one lane right).
|
||||||
|
- Wrap in a Node-RED group box coloured `#0c99d9` (Process Cell).
|
||||||
@@ -24,6 +24,14 @@
|
|||||||
heightInlet: { value: 0.8 }, // m, centre of inlet pipe above floor
|
heightInlet: { value: 0.8 }, // m, centre of inlet pipe above floor
|
||||||
heightOutlet: { value: 0.2 }, // m, centre of outlet pipe above floor
|
heightOutlet: { value: 0.2 }, // m, centre of outlet pipe above floor
|
||||||
heightOverflow: { value: 0.9 }, // m, overflow elevation
|
heightOverflow: { value: 0.9 }, // m, overflow elevation
|
||||||
|
timeleftToFullOrEmptyThresholdSeconds:{value:0}, // time threshold to safeguard starting or stopping pumps in seconds
|
||||||
|
enableDryRunProtection: { value: true },
|
||||||
|
enableOverfillProtection: { value: true },
|
||||||
|
dryRunThresholdPercent: { value: 2 },
|
||||||
|
overfillThresholdPercent: { value: 98 },
|
||||||
|
minHeightBasedOn: { value: "outlet" }, // basis for minimum height check: inlet or outlet
|
||||||
|
processOutputFormat: { value: "process" },
|
||||||
|
dbaseOutputFormat: { value: "influxdb" },
|
||||||
|
|
||||||
// Advanced reference information
|
// Advanced reference information
|
||||||
refHeight: { value: "NAP" }, // reference height
|
refHeight: { value: "NAP" }, // reference height
|
||||||
@@ -47,7 +55,16 @@
|
|||||||
hasDistance: { value: false },
|
hasDistance: { value: false },
|
||||||
distance: { value: 0 },
|
distance: { value: 0 },
|
||||||
distanceUnit: { value: "m" },
|
distanceUnit: { value: "m" },
|
||||||
distanceDescription: { value: "" }
|
distanceDescription: { value: "" },
|
||||||
|
|
||||||
|
// control strategy
|
||||||
|
controlMode: { value: "none" },
|
||||||
|
startLevel: { value: null },
|
||||||
|
stopLevel: { value: null },
|
||||||
|
minFlowLevel: { value: null },
|
||||||
|
maxFlowLevel: { value: null },
|
||||||
|
flowSetpoint: { value: null },
|
||||||
|
flowDeadband: { value: null }
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -86,6 +103,68 @@
|
|||||||
refHeightEl.value = this.refHeight || "NAP";
|
refHeightEl.value = this.refHeight || "NAP";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const minHeightBasedOnEl = document.getElementById("node-input-minHeightBasedOn");
|
||||||
|
if (minHeightBasedOnEl) {
|
||||||
|
minHeightBasedOnEl.value = this.minHeightBasedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dryRunToggle = document.getElementById("node-input-enableDryRunProtection");
|
||||||
|
const dryRunPercent = document.getElementById("node-input-dryRunThresholdPercent");
|
||||||
|
const overfillToggle = document.getElementById("node-input-enableOverfillProtection");
|
||||||
|
const overfillPercent = document.getElementById("node-input-overfillThresholdPercent");
|
||||||
|
|
||||||
|
const toggleInput = (toggleEl, inputEl) => {
|
||||||
|
if (!toggleEl || !inputEl) { return; }
|
||||||
|
inputEl.disabled = !toggleEl.checked;
|
||||||
|
inputEl.parentElement.classList.toggle('disabled', inputEl.disabled);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dryRunToggle && dryRunPercent) {
|
||||||
|
dryRunToggle.checked = !!this.enableDryRunProtection;
|
||||||
|
dryRunPercent.value = Number.isFinite(this.dryRunThresholdPercent) ? this.dryRunThresholdPercent : 2;
|
||||||
|
dryRunToggle.addEventListener('change', () => toggleInput(dryRunToggle, dryRunPercent));
|
||||||
|
toggleInput(dryRunToggle, dryRunPercent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overfillToggle && overfillPercent) {
|
||||||
|
overfillToggle.checked = !!this.enableOverfillProtection;
|
||||||
|
overfillPercent.value = Number.isFinite(this.overfillThresholdPercent) ? this.overfillThresholdPercent : 98;
|
||||||
|
overfillToggle.addEventListener('change', () => toggleInput(overfillToggle, overfillPercent));
|
||||||
|
toggleInput(overfillToggle, overfillPercent);
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeLeftInput = document.getElementById("node-input-timeleftToFullOrEmptyThresholdSeconds");
|
||||||
|
if (timeLeftInput) {
|
||||||
|
timeLeftInput.value = Number.isFinite(this.timeleftToFullOrEmptyThresholdSeconds)
|
||||||
|
? this.timeleftToFullOrEmptyThresholdSeconds
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// control mode toggle UI
|
||||||
|
const toggleModeSections = (val) => {
|
||||||
|
document.querySelectorAll('.ps-mode-section').forEach((el) => el.style.display = 'none');
|
||||||
|
const active = document.getElementById(`ps-mode-${val}`);
|
||||||
|
if (active) active.style.display = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const modeSelect = document.getElementById('node-input-controlMode');
|
||||||
|
if (modeSelect) {
|
||||||
|
modeSelect.value = this.controlMode || 'none';
|
||||||
|
toggleModeSections(modeSelect.value);
|
||||||
|
modeSelect.addEventListener('change', (e) => toggleModeSections(e.target.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
const setNumberField = (id, val) => {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (el) el.value = Number.isFinite(val) ? val : '';
|
||||||
|
};
|
||||||
|
|
||||||
|
setNumberField('node-input-startLevel', this.startLevel);
|
||||||
|
setNumberField('node-input-stopLevel', this.stopLevel);
|
||||||
|
setNumberField('node-input-minFlowLevel', this.minFlowLevel);
|
||||||
|
setNumberField('node-input-maxFlowLevel', this.maxFlowLevel);
|
||||||
|
setNumberField('node-input-flowSetpoint', this.flowSetpoint);
|
||||||
|
setNumberField('node-input-flowDeadband', this.flowDeadband);
|
||||||
|
|
||||||
//------------------- END OF CUSTOM config UI ELEMENTS ------------------- //
|
//------------------- END OF CUSTOM config UI ELEMENTS ------------------- //
|
||||||
},
|
},
|
||||||
@@ -98,14 +177,29 @@
|
|||||||
|
|
||||||
//node specific
|
//node specific
|
||||||
node.refHeight = document.getElementById("node-input-refHeight").value || "NAP";
|
node.refHeight = document.getElementById("node-input-refHeight").value || "NAP";
|
||||||
|
node.minHeightBasedOn = document.getElementById("node-input-minHeightBasedOn").value || "outlet";
|
||||||
node.simulator = document.getElementById("node-input-simulator").checked;
|
node.simulator = document.getElementById("node-input-simulator").checked;
|
||||||
|
|
||||||
["basinVolume","basinHeight","heightInlet","heightOutlet","heightOverflow","basinBottomRef"]
|
["basinVolume","basinHeight","heightInlet","heightOutlet","heightOverflow","basinBottomRef","timeleftToFullOrEmptyThresholdSeconds","dryRunThresholdPercent","overfillThresholdPercent"]
|
||||||
.forEach(field => {
|
.forEach(field => {
|
||||||
node[field] = parseFloat(document.getElementById(`node-input-${field}`).value) || 0;
|
node[field] = parseFloat(document.getElementById(`node-input-${field}`).value) || 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
node.refHeight = document.getElementById("node-input-refHeight").value || "";
|
node.refHeight = document.getElementById("node-input-refHeight").value || "";
|
||||||
|
node.enableDryRunProtection = document.getElementById("node-input-enableDryRunProtection").checked;
|
||||||
|
node.enableOverfillProtection = document.getElementById("node-input-enableOverfillProtection").checked;
|
||||||
|
|
||||||
|
// control strategy
|
||||||
|
node.controlMode = document.getElementById('node-input-controlMode').value || 'none';
|
||||||
|
|
||||||
|
const parseNum = (id) => parseFloat(document.getElementById(id)?.value);
|
||||||
|
node.startLevel = parseNum('node-input-startLevel');
|
||||||
|
node.stopLevel = parseNum('node-input-stopLevel');
|
||||||
|
node.minFlowLevel = parseNum('node-input-minFlowLevel');
|
||||||
|
node.maxFlowLevel = parseNum('node-input-maxFlowLevel');
|
||||||
|
node.flowSetpoint = parseNum('node-input-flowSetpoint');
|
||||||
|
node.flowDeadband = parseNum('node-input-flowDeadband');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -115,7 +209,7 @@
|
|||||||
|
|
||||||
<script type="text/html" data-template-name="pumpingStation">
|
<script type="text/html" data-template-name="pumpingStation">
|
||||||
|
|
||||||
<!-- Simulator toggle -->
|
<h4>Simulation</h4>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-simulator"><i class="fa fa-play-circle"></i> Simulator</label>
|
<label for="node-input-simulator"><i class="fa fa-play-circle"></i> Simulator</label>
|
||||||
<input type="checkbox" id="node-input-simulator" style="width:20px;vertical-align:baseline;" />
|
<input type="checkbox" id="node-input-simulator" style="width:20px;vertical-align:baseline;" />
|
||||||
@@ -124,7 +218,7 @@
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<!-- Basin geometry -->
|
<h4>Basin Geometry</h4>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-basinVolume"><i class="fa fa-cube"></i> Basin Volume (m³)</label>
|
<label for="node-input-basinVolume"><i class="fa fa-cube"></i> Basin Volume (m³)</label>
|
||||||
<input type="number" id="node-input-basinVolume" min="0" step="0.1" />
|
<input type="number" id="node-input-basinVolume" min="0" step="0.1" />
|
||||||
@@ -150,7 +244,58 @@
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<h4>Control Strategy</h4>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-controlMode"><i class="fa fa-sliders"></i> Control mode</label>
|
||||||
|
<select id="node-input-controlMode">
|
||||||
|
<option value="none">None / Manual</option>
|
||||||
|
<option value="levelbased">Level-based</option>
|
||||||
|
<option value="flowbased">Flow-based</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="ps-mode-levelbased" class="ps-mode-section">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-startLevel">startLevel</label>
|
||||||
|
<input type="number" id="node-input-startLevel" placeholder="m" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-stopLevel">stopLevel</label>
|
||||||
|
<input type="number" id="node-input-stopLevel" placeholder="m" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-minFlowLevel">Min flow (m)</label>
|
||||||
|
<input type="number" id="node-input-minFlowLevel" placeholder="m" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-maxFlowLevel">Max flow (m)</label>
|
||||||
|
<input type="number" id="node-input-maxFlowLevel" placeholder="m" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="ps-mode-flowbased" class="ps-mode-section" style="display:none">
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-flowSetpoint">Flow setpoint</label>
|
||||||
|
<input type="number" id="node-input-flowSetpoint" placeholder="m3/h" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-flowDeadband">Deadband</label>
|
||||||
|
<input type="number" id="node-input-flowDeadband" placeholder="m3/h" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h4>Reference</h4>
|
||||||
|
|
||||||
<!-- Reference data -->
|
<!-- Reference data -->
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-minHeightBasedOn"><i class="fa fa-arrows-v"></i> Minimum Height Based On</label>
|
||||||
|
<select id="node-input-minHeightBasedOn" style="width:60%;">
|
||||||
|
<option value="inlet">Inlet Elevation</option>
|
||||||
|
<option value="outlet">Outlet Elevation</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-refHeight"><i class="fa fa-map-marker"></i> Reference height</label>
|
<label for="node-input-refHeight"><i class="fa fa-map-marker"></i> Reference height</label>
|
||||||
<select id="node-input-refHeight" style="width:60%;">
|
<select id="node-input-refHeight" style="width:60%;">
|
||||||
@@ -163,6 +308,59 @@
|
|||||||
<input type="number" id="node-input-basinBottomRef" step="0.01" />
|
<input type="number" id="node-input-basinBottomRef" step="0.01" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h4>Safety</h4>
|
||||||
|
|
||||||
|
<!-- Safety settings -->
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-timeleftToFullOrEmptyThresholdSeconds"><i class="fa fa-clock-o"></i> Time To Empty/Full (s)</label>
|
||||||
|
<input type="number" id="node-input-timeleftToFullOrEmptyThresholdSeconds" min="0" step="1" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-enableDryRunProtection">
|
||||||
|
<i class="fa fa-shield"></i> Dry-run Protection
|
||||||
|
</label>
|
||||||
|
<input type="checkbox" id="node-input-enableDryRunProtection" style="width:20px;vertical-align:baseline;" />
|
||||||
|
<span>Prevent pumps from running on low volume</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-dryRunThresholdPercent" style="padding-left:20px;">Low Volume Threshold (%)</label>
|
||||||
|
<input type="number" id="node-input-dryRunThresholdPercent" min="0" max="100" step="0.1" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-enableOverfillProtection">
|
||||||
|
<i class="fa fa-exclamation-triangle"></i> Overfill Protection
|
||||||
|
</label>
|
||||||
|
<input type="checkbox" id="node-input-enableOverfillProtection" style="width:20px;vertical-align:baseline;" />
|
||||||
|
<span>Stop filling when approaching overflow</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-overfillThresholdPercent" style="padding-left:20px;">High Volume Threshold (%)</label>
|
||||||
|
<input type="number" id="node-input-overfillThresholdPercent" min="0" max="100" step="0.1" />
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h3>Output Formats</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-processOutputFormat"><i class="fa fa-random"></i> Process Output</label>
|
||||||
|
<select id="node-input-processOutputFormat" style="width:60%;">
|
||||||
|
<option value="process">process</option>
|
||||||
|
<option value="json">json</option>
|
||||||
|
<option value="csv">csv</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-dbaseOutputFormat"><i class="fa fa-database"></i> Database Output</label>
|
||||||
|
<select id="node-input-dbaseOutputFormat" style="width:60%;">
|
||||||
|
<option value="influxdb">influxdb</option>
|
||||||
|
<option value="json">json</option>
|
||||||
|
<option value="csv">csv</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Shared asset/logger/position menus -->
|
<!-- Shared asset/logger/position menus -->
|
||||||
<div id="asset-fields-placeholder"></div>
|
<div id="asset-fields-placeholder"></div>
|
||||||
<div id="logger-fields-placeholder"></div>
|
<div id="logger-fields-placeholder"></div>
|
||||||
|
|||||||
100
src/nodeClass.js
100
src/nodeClass.js
@@ -39,35 +39,37 @@ class nodeClass {
|
|||||||
const cfgMgr = new configManager();
|
const cfgMgr = new configManager();
|
||||||
this.defaultConfig = cfgMgr.getConfig(this.name);
|
this.defaultConfig = cfgMgr.getConfig(this.name);
|
||||||
|
|
||||||
// Merge UI config over defaults
|
// Build config: base sections + pumpingStation-specific domain config
|
||||||
this.config = {
|
this.config = cfgMgr.buildConfig(this.name, uiConfig, node.id, {
|
||||||
general: {
|
basin: {
|
||||||
name: this.name,
|
|
||||||
id: node.id, // node.id is for the child registration process
|
|
||||||
unit: uiConfig.unit, // add converter options later to convert to default units (need like a model that defines this which units we are going to use and then conver to those standards)
|
|
||||||
logging: {
|
|
||||||
enabled: uiConfig.enableLog,
|
|
||||||
logLevel: uiConfig.logLevel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
functionality: {
|
|
||||||
positionVsParent: uiConfig.positionVsParent,// Default to 'atEquipment' if not specified
|
|
||||||
distance: uiConfig.hasDistance ? uiConfig.distance : undefined
|
|
||||||
},
|
|
||||||
basin:{
|
|
||||||
volume: uiConfig.basinVolume,
|
volume: uiConfig.basinVolume,
|
||||||
height: uiConfig.basinHeight,
|
height: uiConfig.basinHeight,
|
||||||
heightInlet: uiConfig.heightInlet,
|
heightInlet: uiConfig.heightInlet,
|
||||||
heightOutlet: uiConfig.heightOutlet,
|
heightOutlet: uiConfig.heightOutlet,
|
||||||
heightOverflow: uiConfig.heightOverflow,
|
heightOverflow: uiConfig.heightOverflow,
|
||||||
},
|
},
|
||||||
hydraulics:{
|
hydraulics: {
|
||||||
refHeight: uiConfig.refHeight,
|
refHeight: uiConfig.refHeight,
|
||||||
|
minHeightBasedOn: uiConfig.minHeightBasedOn,
|
||||||
basinBottomRef: uiConfig.basinBottomRef,
|
basinBottomRef: uiConfig.basinBottomRef,
|
||||||
|
},
|
||||||
|
control:{
|
||||||
|
mode: uiConfig.controlMode,
|
||||||
|
levelbased:{
|
||||||
|
startLevel:uiConfig.startLevel,
|
||||||
|
stopLevel:uiConfig.stopLevel,
|
||||||
|
minFlowLevel:uiConfig.minFlowLevel,
|
||||||
|
maxFlowLevel:uiConfig.maxFlowLevel
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
safety:{
|
||||||
console.log(`position vs child for ${this.name} is ${this.config.functionality.positionVsParent} the distance is ${this.config.functionality.distance}`);
|
enableDryRunProtection: uiConfig.enableDryRunProtection,
|
||||||
|
dryRunThresholdPercent: uiConfig.dryRunThresholdPercent,
|
||||||
|
enableOverfillProtection: uiConfig.enableOverfillProtection,
|
||||||
|
overfillThresholdPercent: uiConfig.overfillThresholdPercent,
|
||||||
|
timeleftToFullOrEmptyThresholdSeconds: uiConfig.timeleftToFullOrEmptyThresholdSeconds
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Utility for formatting outputs
|
// Utility for formatting outputs
|
||||||
this._output = new outputUtils();
|
this._output = new outputUtils();
|
||||||
@@ -191,28 +193,56 @@ class nodeClass {
|
|||||||
this.node.on('input', (msg, send, done) => {
|
this.node.on('input', (msg, send, done) => {
|
||||||
switch (msg.topic) {
|
switch (msg.topic) {
|
||||||
//example
|
//example
|
||||||
/*case 'simulator':
|
case 'changemode':
|
||||||
this.source.toggleSimulation();
|
this.source.changeMode(msg.payload);
|
||||||
break;
|
break;
|
||||||
default:
|
case 'registerChild': {
|
||||||
this.source.handleInput(msg);
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
case 'registerChild':
|
|
||||||
// Register this node as a child of the parent node
|
// Register this node as a child of the parent node
|
||||||
const childId = msg.payload;
|
const childId = msg.payload;
|
||||||
const childObj = this.RED.nodes.getNode(childId);
|
const childObj = this.RED.nodes.getNode(childId);
|
||||||
this.source.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent);
|
this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
|
||||||
break;
|
break;
|
||||||
case 'calibratePredictedVolume':
|
}
|
||||||
const calibratedVolume = this.source.measurements
|
case 'calibratePredictedVolume': {
|
||||||
.type('volume')
|
const injectedVol = parseFloat(msg.payload);
|
||||||
.variant('measured')
|
this.source.calibratePredictedVolume(injectedVol);
|
||||||
.position('atequipment')
|
|
||||||
.getCurrentValue('m3');
|
|
||||||
this.source.calibratePredictedVolume(calibratedVolume);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'calibratePredictedLevel': {
|
||||||
|
const injectedLevel = parseFloat(msg.payload);
|
||||||
|
this.source.calibratePredictedLevel(injectedLevel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'q_in': {
|
||||||
|
// payload can be number or { value, unit, timestamp }
|
||||||
|
const val = Number(msg.payload);
|
||||||
|
const unit = msg?.unit;
|
||||||
|
const ts = msg?.timestamp || Date.now();
|
||||||
|
this.source.setManualInflow(val, ts, unit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'Qd': {
|
||||||
|
// Manual demand: operator sets the target output via a
|
||||||
|
// dashboard slider. Only accepted when PS is in 'manual'
|
||||||
|
// mode — mirrors how rotatingMachine gates commands by
|
||||||
|
// mode (virtualControl vs auto).
|
||||||
|
const demand = Number(msg.payload);
|
||||||
|
if (!Number.isFinite(demand)) {
|
||||||
|
this.source.logger.warn(`Invalid Qd value: ${msg.payload}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (this.source.mode === 'manual') {
|
||||||
|
this.source.forwardDemandToChildren(demand).catch((err) =>
|
||||||
|
this.source.logger.error(`Failed to forward demand: ${err.message}`)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.source.logger.debug(
|
||||||
|
`Qd ignored in ${this.source.mode} mode. Switch to manual to use the demand slider.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
1061
src/specificClass.js
1061
src/specificClass.js
File diff suppressed because it is too large
Load Diff
260
test/specificClass.test.js
Normal file
260
test/specificClass.test.js
Normal file
@@ -0,0 +1,260 @@
|
|||||||
|
/**
|
||||||
|
* Tests for pumpingStation specificClass (domain logic).
|
||||||
|
*
|
||||||
|
* The pumpingStation class manages a basin (wet well):
|
||||||
|
* - initBasinProperties: derives surface area, volumes from config
|
||||||
|
* - _calcVolumeFromLevel / _calcLevelFromVolume: linear geometry
|
||||||
|
* - _calcDirection: filling / draining / stable from flow diff
|
||||||
|
* - _callMeasurementHandler: dispatches to type-specific handlers
|
||||||
|
* - getOutput: builds an output snapshot
|
||||||
|
*/
|
||||||
|
|
||||||
|
const PumpingStation = require('../src/specificClass');
|
||||||
|
|
||||||
|
// --------------- helpers ---------------
|
||||||
|
|
||||||
|
function makeConfig(overrides = {}) {
|
||||||
|
const base = {
|
||||||
|
general: {
|
||||||
|
name: 'TestStation',
|
||||||
|
id: 'ps-test-1',
|
||||||
|
unit: 'm3/h',
|
||||||
|
logging: { enabled: false, logLevel: 'error' },
|
||||||
|
},
|
||||||
|
functionality: {
|
||||||
|
softwareType: 'pumpingStation',
|
||||||
|
role: 'stationcontroller',
|
||||||
|
positionVsParent: 'atEquipment',
|
||||||
|
},
|
||||||
|
basin: {
|
||||||
|
volume: 50, // m3 (empty basin volume)
|
||||||
|
height: 5, // m
|
||||||
|
heightInlet: 0.3, // m
|
||||||
|
heightOutlet: 0.2, // m
|
||||||
|
heightOverflow: 4.0, // m
|
||||||
|
},
|
||||||
|
hydraulics: {
|
||||||
|
refHeight: 'NAP',
|
||||||
|
basinBottomRef: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const key of Object.keys(overrides)) {
|
||||||
|
if (typeof overrides[key] === 'object' && !Array.isArray(overrides[key]) && base[key]) {
|
||||||
|
base[key] = { ...base[key], ...overrides[key] };
|
||||||
|
} else {
|
||||||
|
base[key] = overrides[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------- tests ---------------
|
||||||
|
|
||||||
|
describe('pumpingStation specificClass', () => {
|
||||||
|
|
||||||
|
describe('constructor / initialization', () => {
|
||||||
|
it('should create an instance with the given config', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
expect(ps).toBeDefined();
|
||||||
|
expect(ps.config.general.name).toBe('teststation');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should initialize state object with default values', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
expect(ps.state).toEqual({ direction: '', netDownstream: 0, netUpstream: 0, seconds: 0 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should initialize empty machines, stations, child, parent objects', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
expect(ps.machines).toEqual({});
|
||||||
|
expect(ps.stations).toEqual({});
|
||||||
|
expect(ps.child).toEqual({});
|
||||||
|
expect(ps.parent).toEqual({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('initBasinProperties()', () => {
|
||||||
|
it('should calculate surfaceArea = volume / height', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// 50 / 5 = 10 m2
|
||||||
|
expect(ps.basin.surfaceArea).toBe(10);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should calculate maxVol = height * surfaceArea', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// 5 * 10 = 50
|
||||||
|
expect(ps.basin.maxVol).toBe(50);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should calculate maxVolOverflow = heightOverflow * surfaceArea', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// 4.0 * 10 = 40
|
||||||
|
expect(ps.basin.maxVolOverflow).toBe(40);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should calculate minVol = heightOutlet * surfaceArea', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// 0.2 * 10 = 2
|
||||||
|
expect(ps.basin.minVol).toBeCloseTo(2, 5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should calculate minVolOut = heightInlet * surfaceArea', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// 0.3 * 10 = 3
|
||||||
|
expect(ps.basin.minVolOut).toBeCloseTo(3, 5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should store the raw config values on basin', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
expect(ps.basin.volEmptyBasin).toBe(50);
|
||||||
|
expect(ps.basin.heightBasin).toBe(5);
|
||||||
|
expect(ps.basin.heightInlet).toBe(0.3);
|
||||||
|
expect(ps.basin.heightOutlet).toBe(0.2);
|
||||||
|
expect(ps.basin.heightOverflow).toBe(4.0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_calcVolumeFromLevel()', () => {
|
||||||
|
let ps;
|
||||||
|
beforeAll(() => { ps = new PumpingStation(makeConfig()); });
|
||||||
|
|
||||||
|
it('should return level * surfaceArea', () => {
|
||||||
|
// surfaceArea = 10, level = 2 => 20
|
||||||
|
expect(ps._calcVolumeFromLevel(2)).toBe(20);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 for level = 0', () => {
|
||||||
|
expect(ps._calcVolumeFromLevel(0)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clamp negative levels to 0', () => {
|
||||||
|
expect(ps._calcVolumeFromLevel(-3)).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_calcLevelFromVolume()', () => {
|
||||||
|
let ps;
|
||||||
|
beforeAll(() => { ps = new PumpingStation(makeConfig()); });
|
||||||
|
|
||||||
|
it('should return volume / surfaceArea', () => {
|
||||||
|
// surfaceArea = 10, vol = 20 => 2
|
||||||
|
expect(ps._calcLevelFromVolume(20)).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 for volume = 0', () => {
|
||||||
|
expect(ps._calcLevelFromVolume(0)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clamp negative volumes to 0', () => {
|
||||||
|
expect(ps._calcLevelFromVolume(-10)).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('volume/level roundtrip', () => {
|
||||||
|
it('should roundtrip level -> volume -> level', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
const level = 2.7;
|
||||||
|
const vol = ps._calcVolumeFromLevel(level);
|
||||||
|
const levelBack = ps._calcLevelFromVolume(vol);
|
||||||
|
expect(levelBack).toBeCloseTo(level, 10);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_calcDirection()', () => {
|
||||||
|
let ps;
|
||||||
|
beforeAll(() => { ps = new PumpingStation(makeConfig()); });
|
||||||
|
|
||||||
|
it('should return "filling" for positive flow above threshold', () => {
|
||||||
|
expect(ps._calcDirection(0.01)).toBe('filling');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return "draining" for negative flow below negative threshold', () => {
|
||||||
|
expect(ps._calcDirection(-0.01)).toBe('draining');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return "stable" for flow near zero (within threshold)', () => {
|
||||||
|
expect(ps._calcDirection(0.0005)).toBe('stable');
|
||||||
|
expect(ps._calcDirection(-0.0005)).toBe('stable');
|
||||||
|
expect(ps._calcDirection(0)).toBe('stable');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_callMeasurementHandler()', () => {
|
||||||
|
it('should not throw for flow and temperature measurement types', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// flow and temperature handlers are empty stubs, safe to call
|
||||||
|
expect(() => ps._callMeasurementHandler('flow', 0.5, 'downstream', {})).not.toThrow();
|
||||||
|
expect(() => ps._callMeasurementHandler('temperature', 15, 'atEquipment', {})).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch to the correct handler based on measurement type', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// Verify the switch dispatches by checking it does not warn for known types
|
||||||
|
// pressure handler stores values and attempts coolprop calculation
|
||||||
|
// level handler stores values and computes volume
|
||||||
|
// We verify the dispatch logic by calling with type and checking no unhandled error
|
||||||
|
const spy = jest.spyOn(ps, 'updateMeasuredFlow');
|
||||||
|
ps._callMeasurementHandler('flow', 0.5, 'downstream', {});
|
||||||
|
expect(spy).toHaveBeenCalledWith(0.5, 'downstream', {});
|
||||||
|
spy.mockRestore();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getOutput()', () => {
|
||||||
|
it('should return an object containing state and basin', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
const out = ps.getOutput();
|
||||||
|
expect(out).toHaveProperty('state');
|
||||||
|
expect(out).toHaveProperty('basin');
|
||||||
|
expect(out.state).toBe(ps.state);
|
||||||
|
expect(out.basin).toBe(ps.basin);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should include measurement keys in the output', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
const out = ps.getOutput();
|
||||||
|
// After initialization the predicted volume is set
|
||||||
|
expect(typeof out).toBe('object');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_calcRemainingTime()', () => {
|
||||||
|
it('should not throw when called with a level and variant', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
// Should not throw even with no measurement data; it will just find null diffs
|
||||||
|
expect(() => ps._calcRemainingTime(2, 'predicted')).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('tick()', () => {
|
||||||
|
it('should call _updateVolumePrediction and _calcNetFlow', () => {
|
||||||
|
const ps = new PumpingStation(makeConfig());
|
||||||
|
const spyVol = jest.spyOn(ps, '_updateVolumePrediction');
|
||||||
|
const spyNet = jest.spyOn(ps, '_calcNetFlow');
|
||||||
|
// stub _calcRemainingTime to avoid needing full measurement data
|
||||||
|
ps._calcRemainingTime = jest.fn();
|
||||||
|
ps.tick();
|
||||||
|
expect(spyVol).toHaveBeenCalledWith('out');
|
||||||
|
expect(spyVol).toHaveBeenCalledWith('in');
|
||||||
|
expect(spyNet).toHaveBeenCalled();
|
||||||
|
spyVol.mockRestore();
|
||||||
|
spyNet.mockRestore();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('edge cases', () => {
|
||||||
|
it('should handle basin with zero height gracefully', () => {
|
||||||
|
// surfaceArea = volume / height => division by 0 gives Infinity
|
||||||
|
const config = makeConfig({ basin: { volume: 50, height: 0, heightInlet: 0, heightOutlet: 0, heightOverflow: 0 } });
|
||||||
|
const ps = new PumpingStation(config);
|
||||||
|
expect(ps.basin.surfaceArea).toBe(Infinity);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle basin with very small dimensions', () => {
|
||||||
|
const config = makeConfig({ basin: { volume: 0.001, height: 0.001, heightInlet: 0, heightOutlet: 0, heightOverflow: 0.0005 } });
|
||||||
|
const ps = new PumpingStation(config);
|
||||||
|
expect(ps.basin.surfaceArea).toBeCloseTo(1, 5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user