2025-10-14 13:51:32 +02:00
|
|
|
|
2025-10-07 18:05:54 +02:00
|
|
|
const { outputUtils, configManager } = require('generalFunctions');
|
|
|
|
|
const Specific = require("./specificClass");
|
|
|
|
|
|
|
|
|
|
class nodeClass {
|
|
|
|
|
/**
|
|
|
|
|
* Create a node.
|
|
|
|
|
* @param {object} uiConfig - Node-RED node configuration.
|
|
|
|
|
* @param {object} RED - Node-RED runtime API.
|
|
|
|
|
* @param {object} nodeInstance - The Node-RED node instance.
|
|
|
|
|
* @param {string} nameOfNode - The name of the node, used for
|
|
|
|
|
*/
|
|
|
|
|
constructor(uiConfig, RED, nodeInstance, nameOfNode) {
|
|
|
|
|
|
|
|
|
|
// Preserve RED reference for HTTP endpoints if needed
|
|
|
|
|
this.node = nodeInstance;
|
|
|
|
|
this.RED = RED;
|
|
|
|
|
this.name = nameOfNode;
|
|
|
|
|
|
|
|
|
|
// Load default & UI config
|
|
|
|
|
this._loadConfig(uiConfig,this.node);
|
|
|
|
|
|
|
|
|
|
// Instantiate core class
|
|
|
|
|
this._setupSpecificClass();
|
|
|
|
|
|
|
|
|
|
// Wire up event and lifecycle handlers
|
|
|
|
|
this._bindEvents();
|
|
|
|
|
this._registerChild();
|
|
|
|
|
this._startTickLoop();
|
|
|
|
|
this._attachInputHandler();
|
|
|
|
|
this._attachCloseHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load and merge default config with user-defined settings.
|
|
|
|
|
* @param {object} uiConfig - Raw config from Node-RED UI.
|
|
|
|
|
*/
|
|
|
|
|
_loadConfig(uiConfig,node) {
|
|
|
|
|
const cfgMgr = new configManager();
|
|
|
|
|
this.defaultConfig = cfgMgr.getConfig(this.name);
|
|
|
|
|
|
2026-03-11 14:59:35 +01:00
|
|
|
// Build config: base sections + pumpingStation-specific domain config
|
|
|
|
|
this.config = cfgMgr.buildConfig(this.name, uiConfig, node.id, {
|
|
|
|
|
basin: {
|
2025-10-16 14:44:45 +02:00
|
|
|
volume: uiConfig.basinVolume,
|
|
|
|
|
height: uiConfig.basinHeight,
|
2026-04-22 16:13:59 +02:00
|
|
|
inflowLevel: uiConfig.inflowLevel,
|
|
|
|
|
outflowLevel: uiConfig.outflowLevel,
|
|
|
|
|
overflowLevel: uiConfig.overflowLevel,
|
Level-armed shift, derived dryRunLevel, side-panel editor + manual q_out
Runtime (specificClass.js):
- Replace direction-based hysteresis with level-armed _shiftArmed state.
Arms when level rises past shiftLevel; disarms when level drops below
startLevel. While armed, ramp foot moves to startLevel and ramp top
to shiftLevel — both ends shift left, then saturate at 100 % up to
maxLevel.
- _scaleLevelToFlowPercent now takes (rampStartLevel, rampTopLevel) so
the saturation point follows the shift state.
- New setManualOutflow mirroring setManualInflow.
Adapter (nodeClass.js):
- Pipe enableShiftedRamp / shiftLevel through to control.levelbased.
- New q_out topic handler.
Editor (pumpingStation.html + new src/editor/ modules):
- Split monolithic <script> into modules: index.js (helpers),
basin-diagram.js, mode-preview.js, hover-couple.js, oneditprepare.js,
oneditsave.js — served via /pumpingStation/editor/:file.
- Mode preview redrawn per the SVG diagrams: OFF tier below 0 %, 0 %
flat from start→inlet, ramp inlet→max, optional shifted-down curve
start→shift with 100 % saturation past shift.
- Mode preview gains zone bands (dryRun / safetyLow / safe / safetyHigh /
overflow), level markers (dryRun derived, start, inlet, max, shift,
overflow), validation ribbon that blocks save on bad ordering.
- Auto-default shiftLevel to 0.9 × maxLevel on enable so the marker is
always visible.
- All level inputs moved to a side panel left of each diagram, color-
coded to match line strokes; hover-couple highlights the paired SVG
line on input focus / mouseover.
- Removed UI for non-static parameters: minHeightBasedOn,
pipelineLength, maxDischargeHead, staticHead, defaultFluid,
maxInflowRate, temperatureReferenceDegC,
timeleftToFullOrEmptyThresholdSeconds, inletPipeDiameter,
outletPipeDiameter, minLevel (now derived = dryRunLevel).
- foreignObject inputs in basin SVG removed (single source of truth in
side panel).
Dashboard example (examples/basic-dashboard.flow.json):
- Add manual Q_OUT slider + q_out builder mirroring the existing q_in
trio so the basin can be exercised end-to-end without a connected
rotating-machine downstream.
Tests (test/basic/specificClass.test.js):
- Replace direction-shift test with two new cases covering shift-disabled
hold-zone behaviour and shift-armed/disarmed transitions through
shiftLevel and startLevel boundaries. 53/53 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:29:34 +02:00
|
|
|
inletPipeDiameter: uiConfig.inletPipeDiameter,
|
|
|
|
|
outletPipeDiameter: uiConfig.outletPipeDiameter,
|
2025-10-16 14:44:45 +02:00
|
|
|
},
|
2026-03-11 14:59:35 +01:00
|
|
|
hydraulics: {
|
2025-10-16 14:44:45 +02:00
|
|
|
refHeight: uiConfig.refHeight,
|
2025-11-20 12:15:46 +01:00
|
|
|
minHeightBasedOn: uiConfig.minHeightBasedOn,
|
2025-10-16 14:44:45 +02:00
|
|
|
basinBottomRef: uiConfig.basinBottomRef,
|
Level-armed shift, derived dryRunLevel, side-panel editor + manual q_out
Runtime (specificClass.js):
- Replace direction-based hysteresis with level-armed _shiftArmed state.
Arms when level rises past shiftLevel; disarms when level drops below
startLevel. While armed, ramp foot moves to startLevel and ramp top
to shiftLevel — both ends shift left, then saturate at 100 % up to
maxLevel.
- _scaleLevelToFlowPercent now takes (rampStartLevel, rampTopLevel) so
the saturation point follows the shift state.
- New setManualOutflow mirroring setManualInflow.
Adapter (nodeClass.js):
- Pipe enableShiftedRamp / shiftLevel through to control.levelbased.
- New q_out topic handler.
Editor (pumpingStation.html + new src/editor/ modules):
- Split monolithic <script> into modules: index.js (helpers),
basin-diagram.js, mode-preview.js, hover-couple.js, oneditprepare.js,
oneditsave.js — served via /pumpingStation/editor/:file.
- Mode preview redrawn per the SVG diagrams: OFF tier below 0 %, 0 %
flat from start→inlet, ramp inlet→max, optional shifted-down curve
start→shift with 100 % saturation past shift.
- Mode preview gains zone bands (dryRun / safetyLow / safe / safetyHigh /
overflow), level markers (dryRun derived, start, inlet, max, shift,
overflow), validation ribbon that blocks save on bad ordering.
- Auto-default shiftLevel to 0.9 × maxLevel on enable so the marker is
always visible.
- All level inputs moved to a side panel left of each diagram, color-
coded to match line strokes; hover-couple highlights the paired SVG
line on input focus / mouseover.
- Removed UI for non-static parameters: minHeightBasedOn,
pipelineLength, maxDischargeHead, staticHead, defaultFluid,
maxInflowRate, temperatureReferenceDegC,
timeleftToFullOrEmptyThresholdSeconds, inletPipeDiameter,
outletPipeDiameter, minLevel (now derived = dryRunLevel).
- foreignObject inputs in basin SVG removed (single source of truth in
side panel).
Dashboard example (examples/basic-dashboard.flow.json):
- Add manual Q_OUT slider + q_out builder mirroring the existing q_in
trio so the basin can be exercised end-to-end without a connected
rotating-machine downstream.
Tests (test/basic/specificClass.test.js):
- Replace direction-shift test with two new cases covering shift-disabled
hold-zone behaviour and shift-armed/disarmed transitions through
shiftLevel and startLevel boundaries. 53/53 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:29:34 +02:00
|
|
|
maxInflowRate: uiConfig.maxInflowRate,
|
|
|
|
|
staticHead: uiConfig.staticHead,
|
|
|
|
|
maxDischargeHead: uiConfig.maxDischargeHead,
|
|
|
|
|
pipelineLength: uiConfig.pipelineLength,
|
|
|
|
|
defaultFluid: uiConfig.defaultFluid,
|
|
|
|
|
temperatureReferenceDegC: uiConfig.temperatureReferenceDegC,
|
2025-11-25 14:57:39 +01:00
|
|
|
},
|
2025-11-27 17:46:24 +01:00
|
|
|
control:{
|
|
|
|
|
mode: uiConfig.controlMode,
|
|
|
|
|
levelbased:{
|
2026-04-22 16:13:59 +02:00
|
|
|
minLevel:uiConfig.minLevel,
|
2025-11-27 17:46:24 +01:00
|
|
|
startLevel:uiConfig.startLevel,
|
Level-armed shift, derived dryRunLevel, side-panel editor + manual q_out
Runtime (specificClass.js):
- Replace direction-based hysteresis with level-armed _shiftArmed state.
Arms when level rises past shiftLevel; disarms when level drops below
startLevel. While armed, ramp foot moves to startLevel and ramp top
to shiftLevel — both ends shift left, then saturate at 100 % up to
maxLevel.
- _scaleLevelToFlowPercent now takes (rampStartLevel, rampTopLevel) so
the saturation point follows the shift state.
- New setManualOutflow mirroring setManualInflow.
Adapter (nodeClass.js):
- Pipe enableShiftedRamp / shiftLevel through to control.levelbased.
- New q_out topic handler.
Editor (pumpingStation.html + new src/editor/ modules):
- Split monolithic <script> into modules: index.js (helpers),
basin-diagram.js, mode-preview.js, hover-couple.js, oneditprepare.js,
oneditsave.js — served via /pumpingStation/editor/:file.
- Mode preview redrawn per the SVG diagrams: OFF tier below 0 %, 0 %
flat from start→inlet, ramp inlet→max, optional shifted-down curve
start→shift with 100 % saturation past shift.
- Mode preview gains zone bands (dryRun / safetyLow / safe / safetyHigh /
overflow), level markers (dryRun derived, start, inlet, max, shift,
overflow), validation ribbon that blocks save on bad ordering.
- Auto-default shiftLevel to 0.9 × maxLevel on enable so the marker is
always visible.
- All level inputs moved to a side panel left of each diagram, color-
coded to match line strokes; hover-couple highlights the paired SVG
line on input focus / mouseover.
- Removed UI for non-static parameters: minHeightBasedOn,
pipelineLength, maxDischargeHead, staticHead, defaultFluid,
maxInflowRate, temperatureReferenceDegC,
timeleftToFullOrEmptyThresholdSeconds, inletPipeDiameter,
outletPipeDiameter, minLevel (now derived = dryRunLevel).
- foreignObject inputs in basin SVG removed (single source of truth in
side panel).
Dashboard example (examples/basic-dashboard.flow.json):
- Add manual Q_OUT slider + q_out builder mirroring the existing q_in
trio so the basin can be exercised end-to-end without a connected
rotating-machine downstream.
Tests (test/basic/specificClass.test.js):
- Replace direction-shift test with two new cases covering shift-disabled
hold-zone behaviour and shift-armed/disarmed transitions through
shiftLevel and startLevel boundaries. 53/53 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:29:34 +02:00
|
|
|
maxLevel:uiConfig.maxLevel,
|
|
|
|
|
curveType: uiConfig.levelCurveType || uiConfig.curveType,
|
|
|
|
|
logCurveFactor: uiConfig.logCurveFactor,
|
|
|
|
|
enableShiftedRamp: uiConfig.enableShiftedRamp,
|
Hold-then-ramp shift semantics + shiftArmPercent + e2e tests
Runtime (specificClass.js):
- Replace the "shift left both ramp ends" geometry with a true
hold-then-ramp hysteresis driven by output %, not level:
• Up-curve % crosses shiftArmPercent on the way up → ARM.
• Filling→draining transition while armed → capture the up-curve %
at that moment as _shiftHoldValue.
• Draining + level ≥ shiftLevel → output stays at _shiftHoldValue
(horizontal hold, matching the dashed segment in the SVG).
• Draining + level in [start, shift] → output ramps holdValue → 0 %
along the same curve shape (linear or log) as the up curve.
• Draining + level < startLevel → 0 % AND disarm.
• Returning to filling clears holdValue, stays armed; next drain
transition captures a fresh hold so bouncing fills rearm cleanly.
• Disarm only when level ≤ startLevel.
- New _curveShape(x) helper for shared linear/log shaping.
- Removed legacy _levelBasedRampStart / _levelBasedRampTop /
_updateShiftArmed in favour of the inline state machine.
Adapter (nodeClass.js):
- Pipe shiftArmPercent through to control.levelbased.
Editor (pumpingStation.html + src/editor/):
- Add shiftArmPercent input row (% with unit) to the mode side panel
(only shown when shifted ramp is enabled). Default 95 %.
- Add the horizontal arming-% line + label inside the mode SVG —
this is the "% Threshold triggering shifted ramp down" line from
the original drawing that had been missing.
- Redraw the shifted-down curve to match the SVG geometry literally:
100 % flat from maxLevel → shiftLevel, then ramp shiftLevel →
startLevel down to 0 %, OFF below startLevel. Preview shows the
worst-case envelope (hold = 100 %); runtime hold is captured live.
- Validation extended: 0 < shiftArmPercent ≤ 100; ordering rules
preserved (start < shift ≤ max etc.).
- Auto-default shiftArmPercent to 95 when shift is enabled and the
current value is missing or out of range.
Dashboard example (examples/basic-dashboard.flow.json):
- Parser now reads `level.predicted.atequipment.default` etc. The
MeasurementContainer flatten format includes the implicit 'default'
childId; consumers must include it. Comment in the parser points
at the documenting source in generalFunctions.
Tests:
- test/basic: replace old level-armed-shift tests with two new ones
that exercise the hold-then-ramp arming, capture, hold, ramp-down,
disarm, and the bounce case (filling→draining→filling→draining
captures a fresh hold each time).
- test/integration/shifted-ramp-end-to-end.test.js: new file. Drives
Q_IN/Q_OUT through the full runtime tick with a controllable clock,
asserting the same hysteresis path the dashboard exercises.
- test/integration/basic-dashboard-flow.test.js: fixture keys updated
to the .default-suffixed form so they match the real flatten output.
56/56 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 11:46:46 +02:00
|
|
|
shiftLevel: uiConfig.shiftLevel,
|
|
|
|
|
shiftArmPercent: uiConfig.shiftArmPercent
|
2025-11-27 17:46:24 +01:00
|
|
|
}
|
|
|
|
|
},
|
2025-11-25 14:57:39 +01:00
|
|
|
safety:{
|
|
|
|
|
enableDryRunProtection: uiConfig.enableDryRunProtection,
|
|
|
|
|
dryRunThresholdPercent: uiConfig.dryRunThresholdPercent,
|
Level-armed shift, derived dryRunLevel, side-panel editor + manual q_out
Runtime (specificClass.js):
- Replace direction-based hysteresis with level-armed _shiftArmed state.
Arms when level rises past shiftLevel; disarms when level drops below
startLevel. While armed, ramp foot moves to startLevel and ramp top
to shiftLevel — both ends shift left, then saturate at 100 % up to
maxLevel.
- _scaleLevelToFlowPercent now takes (rampStartLevel, rampTopLevel) so
the saturation point follows the shift state.
- New setManualOutflow mirroring setManualInflow.
Adapter (nodeClass.js):
- Pipe enableShiftedRamp / shiftLevel through to control.levelbased.
- New q_out topic handler.
Editor (pumpingStation.html + new src/editor/ modules):
- Split monolithic <script> into modules: index.js (helpers),
basin-diagram.js, mode-preview.js, hover-couple.js, oneditprepare.js,
oneditsave.js — served via /pumpingStation/editor/:file.
- Mode preview redrawn per the SVG diagrams: OFF tier below 0 %, 0 %
flat from start→inlet, ramp inlet→max, optional shifted-down curve
start→shift with 100 % saturation past shift.
- Mode preview gains zone bands (dryRun / safetyLow / safe / safetyHigh /
overflow), level markers (dryRun derived, start, inlet, max, shift,
overflow), validation ribbon that blocks save on bad ordering.
- Auto-default shiftLevel to 0.9 × maxLevel on enable so the marker is
always visible.
- All level inputs moved to a side panel left of each diagram, color-
coded to match line strokes; hover-couple highlights the paired SVG
line on input focus / mouseover.
- Removed UI for non-static parameters: minHeightBasedOn,
pipelineLength, maxDischargeHead, staticHead, defaultFluid,
maxInflowRate, temperatureReferenceDegC,
timeleftToFullOrEmptyThresholdSeconds, inletPipeDiameter,
outletPipeDiameter, minLevel (now derived = dryRunLevel).
- foreignObject inputs in basin SVG removed (single source of truth in
side panel).
Dashboard example (examples/basic-dashboard.flow.json):
- Add manual Q_OUT slider + q_out builder mirroring the existing q_in
trio so the basin can be exercised end-to-end without a connected
rotating-machine downstream.
Tests (test/basic/specificClass.test.js):
- Replace direction-shift test with two new cases covering shift-disabled
hold-zone behaviour and shift-armed/disarmed transitions through
shiftLevel and startLevel boundaries. 53/53 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:29:34 +02:00
|
|
|
enableHighVolumeSafety: uiConfig.enableHighVolumeSafety ?? uiConfig.enableOverfillProtection,
|
|
|
|
|
highVolumeSafetyThresholdPercent: uiConfig.highVolumeSafetyThresholdPercent ?? uiConfig.overfillThresholdPercent,
|
2025-11-25 14:57:39 +01:00
|
|
|
enableOverfillProtection: uiConfig.enableOverfillProtection,
|
|
|
|
|
overfillThresholdPercent: uiConfig.overfillThresholdPercent,
|
|
|
|
|
timeleftToFullOrEmptyThresholdSeconds: uiConfig.timeleftToFullOrEmptyThresholdSeconds
|
Level-armed shift, derived dryRunLevel, side-panel editor + manual q_out
Runtime (specificClass.js):
- Replace direction-based hysteresis with level-armed _shiftArmed state.
Arms when level rises past shiftLevel; disarms when level drops below
startLevel. While armed, ramp foot moves to startLevel and ramp top
to shiftLevel — both ends shift left, then saturate at 100 % up to
maxLevel.
- _scaleLevelToFlowPercent now takes (rampStartLevel, rampTopLevel) so
the saturation point follows the shift state.
- New setManualOutflow mirroring setManualInflow.
Adapter (nodeClass.js):
- Pipe enableShiftedRamp / shiftLevel through to control.levelbased.
- New q_out topic handler.
Editor (pumpingStation.html + new src/editor/ modules):
- Split monolithic <script> into modules: index.js (helpers),
basin-diagram.js, mode-preview.js, hover-couple.js, oneditprepare.js,
oneditsave.js — served via /pumpingStation/editor/:file.
- Mode preview redrawn per the SVG diagrams: OFF tier below 0 %, 0 %
flat from start→inlet, ramp inlet→max, optional shifted-down curve
start→shift with 100 % saturation past shift.
- Mode preview gains zone bands (dryRun / safetyLow / safe / safetyHigh /
overflow), level markers (dryRun derived, start, inlet, max, shift,
overflow), validation ribbon that blocks save on bad ordering.
- Auto-default shiftLevel to 0.9 × maxLevel on enable so the marker is
always visible.
- All level inputs moved to a side panel left of each diagram, color-
coded to match line strokes; hover-couple highlights the paired SVG
line on input focus / mouseover.
- Removed UI for non-static parameters: minHeightBasedOn,
pipelineLength, maxDischargeHead, staticHead, defaultFluid,
maxInflowRate, temperatureReferenceDegC,
timeleftToFullOrEmptyThresholdSeconds, inletPipeDiameter,
outletPipeDiameter, minLevel (now derived = dryRunLevel).
- foreignObject inputs in basin SVG removed (single source of truth in
side panel).
Dashboard example (examples/basic-dashboard.flow.json):
- Add manual Q_OUT slider + q_out builder mirroring the existing q_in
trio so the basin can be exercised end-to-end without a connected
rotating-machine downstream.
Tests (test/basic/specificClass.test.js):
- Replace direction-shift test with two new cases covering shift-disabled
hold-zone behaviour and shift-armed/disarmed transitions through
shiftLevel and startLevel boundaries. 53/53 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:29:34 +02:00
|
|
|
},
|
|
|
|
|
output: {
|
|
|
|
|
process: uiConfig.processOutputFormat,
|
|
|
|
|
dbase: uiConfig.dbaseOutputFormat
|
2025-10-07 18:05:54 +02:00
|
|
|
}
|
2026-03-11 14:59:35 +01:00
|
|
|
});
|
2025-10-07 18:05:54 +02:00
|
|
|
|
|
|
|
|
// Utility for formatting outputs
|
|
|
|
|
this._output = new outputUtils();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Instantiate the core logic and store as source.
|
|
|
|
|
*/
|
|
|
|
|
_setupSpecificClass() {
|
|
|
|
|
this.source = new Specific(this.config);
|
|
|
|
|
this.node.source = this.source; // Store the source in the node instance for easy access
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bind Node-RED status updates.
|
|
|
|
|
*/
|
|
|
|
|
_bindEvents() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-21 12:45:19 +02:00
|
|
|
// init registration msg
|
2025-10-07 18:05:54 +02:00
|
|
|
_registerChild() {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.node.send([
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
{ topic: 'registerChild', payload: this.node.id , positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' , distance: this.config?.functionality?.distance || null},
|
|
|
|
|
]);
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-21 12:45:19 +02:00
|
|
|
_updateNodeStatus() {
|
|
|
|
|
const ps = this.source;
|
|
|
|
|
|
2025-11-03 07:42:51 +01:00
|
|
|
const pickVariant = (type, prefer = ['measured', 'predicted'], position = 'atEquipment', unit) => {
|
|
|
|
|
for (const variant of prefer) {
|
|
|
|
|
const chain = ps.measurements.type(type).variant(variant).position(position);
|
|
|
|
|
const value = unit ? chain.getCurrentValue(unit) : chain.getCurrentValue();
|
|
|
|
|
if (value != null) return { value, variant };
|
2025-10-21 12:45:19 +02:00
|
|
|
}
|
2025-11-03 07:42:51 +01:00
|
|
|
return { value: null, variant: null };
|
|
|
|
|
};
|
2025-10-21 12:45:19 +02:00
|
|
|
|
2025-11-03 07:42:51 +01:00
|
|
|
const vol = pickVariant('volume', ['measured', 'predicted'], 'atEquipment', 'm3');
|
|
|
|
|
const volPercent = pickVariant('volumePercent', ['measured','predicted'], 'atEquipment'); // already unitless
|
|
|
|
|
const level = pickVariant('level', ['measured', 'predicted'], 'atEquipment', 'm');
|
2025-11-03 09:17:22 +01:00
|
|
|
const netFlow = pickVariant('netFlowRate', ['measured', 'predicted'], 'atEquipment', 'm3/h');
|
2025-11-03 07:42:51 +01:00
|
|
|
|
2026-04-22 16:13:59 +02:00
|
|
|
const maxVolBeforeOverflow = ps.basin?.maxVolAtOverflow ?? ps.basin?.maxVol ?? 0;
|
2025-11-03 07:42:51 +01:00
|
|
|
const currentVolume = vol.value ?? 0;
|
|
|
|
|
const currentvolPercent = volPercent.value ?? 0;
|
2025-11-03 09:17:22 +01:00
|
|
|
const netFlowM3h = netFlow.value ?? 0;
|
2025-11-03 07:42:51 +01:00
|
|
|
|
|
|
|
|
const direction = ps.state?.direction ?? 'unknown';
|
|
|
|
|
const secondsRemaining = ps.state?.seconds ?? null;
|
|
|
|
|
const timeRemainingMinutes = secondsRemaining != null ? Math.round(secondsRemaining / 60) : null;
|
|
|
|
|
|
|
|
|
|
const badgePieces = [];
|
|
|
|
|
badgePieces.push(`${currentvolPercent.toFixed(1)}% `);
|
|
|
|
|
badgePieces.push(
|
2025-11-03 09:17:22 +01:00
|
|
|
`V=${currentVolume.toFixed(2)} / ${maxVolBeforeOverflow.toFixed(2)} m³`
|
2025-11-03 07:42:51 +01:00
|
|
|
);
|
2025-11-03 09:17:22 +01:00
|
|
|
badgePieces.push(`net: ${netFlowM3h.toFixed(0)} m³/h`);
|
2025-11-03 07:42:51 +01:00
|
|
|
if (timeRemainingMinutes != null) {
|
|
|
|
|
badgePieces.push(`t≈${timeRemainingMinutes} min)`);
|
2025-10-21 12:45:19 +02:00
|
|
|
}
|
2025-11-03 07:42:51 +01:00
|
|
|
|
|
|
|
|
const { symbol, fill } = (() => {
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case 'filling': return { symbol: '⬆️', fill: 'blue' };
|
|
|
|
|
case 'draining': return { symbol: '⬇️', fill: 'orange' };
|
|
|
|
|
case 'steady': return { symbol: '⏸️', fill: 'green' };
|
|
|
|
|
default: return { symbol: '❔', fill: 'grey' };
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
badgePieces[0] = `${symbol} ${badgePieces[0]}`;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
fill,
|
|
|
|
|
shape: 'dot',
|
|
|
|
|
text: badgePieces.join(' | ')
|
|
|
|
|
};
|
2025-10-21 12:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-11-03 07:42:51 +01:00
|
|
|
|
2025-10-21 12:45:19 +02:00
|
|
|
// any time based functions here
|
2025-10-07 18:05:54 +02:00
|
|
|
_startTickLoop() {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this._tickInterval = setInterval(() => this._tick(), 1000);
|
2025-10-21 12:45:19 +02:00
|
|
|
|
|
|
|
|
// Update node status on nodered screen every second ( this is not the best way to do this, but it works for now)
|
|
|
|
|
this._statusInterval = setInterval(() => {
|
|
|
|
|
const status = this._updateNodeStatus();
|
|
|
|
|
this.node.status(status);
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
2025-10-07 18:05:54 +02:00
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute a single tick: update measurement, format and send outputs.
|
|
|
|
|
*/
|
|
|
|
|
_tick() {
|
2025-10-23 09:51:54 +02:00
|
|
|
|
|
|
|
|
//pumping station needs time based ticks to recalc level when predicted
|
|
|
|
|
this.source.tick();
|
2025-10-07 18:05:54 +02:00
|
|
|
const raw = this.source.getOutput();
|
2025-11-06 11:19:20 +01:00
|
|
|
const processMsg = this._output.formatMsg(raw, this.source.config, 'process');
|
|
|
|
|
const influxMsg = this._output.formatMsg(raw, this.source.config, 'influxdb');
|
2025-10-07 18:05:54 +02:00
|
|
|
|
|
|
|
|
// Send only updated outputs on ports 0 & 1
|
|
|
|
|
this.node.send([processMsg, influxMsg]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attach the node's input handler, routing control messages to the class.
|
|
|
|
|
*/
|
|
|
|
|
_attachInputHandler() {
|
|
|
|
|
this.node.on('input', (msg, send, done) => {
|
|
|
|
|
switch (msg.topic) {
|
2025-10-14 08:36:45 +02:00
|
|
|
//example
|
2025-11-20 12:15:46 +01:00
|
|
|
case 'changemode':
|
|
|
|
|
this.source.changeMode(msg.payload);
|
2025-10-07 18:05:54 +02:00
|
|
|
break;
|
2026-03-11 13:39:57 +01:00
|
|
|
case 'registerChild': {
|
2025-10-16 14:44:45 +02:00
|
|
|
// Register this node as a child of the parent node
|
|
|
|
|
const childId = msg.payload;
|
2026-03-11 13:39:57 +01:00
|
|
|
const childObj = this.RED.nodes.getNode(childId);
|
2026-03-31 18:20:09 +02:00
|
|
|
this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
|
2025-10-16 14:44:45 +02:00
|
|
|
break;
|
2026-03-31 18:20:09 +02:00
|
|
|
}
|
|
|
|
|
case 'calibratePredictedVolume': {
|
2025-11-30 20:13:21 +01:00
|
|
|
const injectedVol = parseFloat(msg.payload);
|
2025-11-30 17:46:07 +01:00
|
|
|
this.source.calibratePredictedVolume(injectedVol);
|
|
|
|
|
break;
|
2026-03-31 18:20:09 +02:00
|
|
|
}
|
|
|
|
|
case 'calibratePredictedLevel': {
|
2025-11-30 20:13:21 +01:00
|
|
|
const injectedLevel = parseFloat(msg.payload);
|
2025-11-30 17:46:07 +01:00
|
|
|
this.source.calibratePredictedLevel(injectedLevel);
|
2025-11-07 15:07:56 +01:00
|
|
|
break;
|
2026-03-31 18:20:09 +02:00
|
|
|
}
|
2025-11-27 17:46:24 +01:00
|
|
|
case 'q_in': {
|
|
|
|
|
// payload can be number or { value, unit, timestamp }
|
|
|
|
|
const val = Number(msg.payload);
|
2025-11-30 09:24:18 +01:00
|
|
|
const unit = msg?.unit;
|
2025-11-27 17:46:24 +01:00
|
|
|
const ts = msg?.timestamp || Date.now();
|
|
|
|
|
this.source.setManualInflow(val, ts, unit);
|
|
|
|
|
break;
|
|
|
|
|
}
|
Level-armed shift, derived dryRunLevel, side-panel editor + manual q_out
Runtime (specificClass.js):
- Replace direction-based hysteresis with level-armed _shiftArmed state.
Arms when level rises past shiftLevel; disarms when level drops below
startLevel. While armed, ramp foot moves to startLevel and ramp top
to shiftLevel — both ends shift left, then saturate at 100 % up to
maxLevel.
- _scaleLevelToFlowPercent now takes (rampStartLevel, rampTopLevel) so
the saturation point follows the shift state.
- New setManualOutflow mirroring setManualInflow.
Adapter (nodeClass.js):
- Pipe enableShiftedRamp / shiftLevel through to control.levelbased.
- New q_out topic handler.
Editor (pumpingStation.html + new src/editor/ modules):
- Split monolithic <script> into modules: index.js (helpers),
basin-diagram.js, mode-preview.js, hover-couple.js, oneditprepare.js,
oneditsave.js — served via /pumpingStation/editor/:file.
- Mode preview redrawn per the SVG diagrams: OFF tier below 0 %, 0 %
flat from start→inlet, ramp inlet→max, optional shifted-down curve
start→shift with 100 % saturation past shift.
- Mode preview gains zone bands (dryRun / safetyLow / safe / safetyHigh /
overflow), level markers (dryRun derived, start, inlet, max, shift,
overflow), validation ribbon that blocks save on bad ordering.
- Auto-default shiftLevel to 0.9 × maxLevel on enable so the marker is
always visible.
- All level inputs moved to a side panel left of each diagram, color-
coded to match line strokes; hover-couple highlights the paired SVG
line on input focus / mouseover.
- Removed UI for non-static parameters: minHeightBasedOn,
pipelineLength, maxDischargeHead, staticHead, defaultFluid,
maxInflowRate, temperatureReferenceDegC,
timeleftToFullOrEmptyThresholdSeconds, inletPipeDiameter,
outletPipeDiameter, minLevel (now derived = dryRunLevel).
- foreignObject inputs in basin SVG removed (single source of truth in
side panel).
Dashboard example (examples/basic-dashboard.flow.json):
- Add manual Q_OUT slider + q_out builder mirroring the existing q_in
trio so the basin can be exercised end-to-end without a connected
rotating-machine downstream.
Tests (test/basic/specificClass.test.js):
- Replace direction-shift test with two new cases covering shift-disabled
hold-zone behaviour and shift-armed/disarmed transitions through
shiftLevel and startLevel boundaries. 53/53 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 19:29:34 +02:00
|
|
|
case 'q_out': {
|
|
|
|
|
const val = Number(msg.payload);
|
|
|
|
|
const unit = msg?.unit;
|
|
|
|
|
const ts = msg?.timestamp || Date.now();
|
|
|
|
|
this.source.setManualOutflow(val, ts, unit);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-04-14 08:27:11 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2025-10-07 18:05:54 +02:00
|
|
|
}
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clean up timers and intervals when Node-RED stops the node.
|
|
|
|
|
*/
|
|
|
|
|
_attachCloseHandler() {
|
|
|
|
|
this.node.on('close', (done) => {
|
|
|
|
|
clearInterval(this._tickInterval);
|
2025-10-21 12:45:19 +02:00
|
|
|
clearInterval(this._statusInterval);
|
2026-04-22 16:13:59 +02:00
|
|
|
this.node.status({}); // clear node status badge
|
2025-10-07 18:05:54 +02:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = nodeClass;
|