Compare commits
19 Commits
5df3881375
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 858189d6da | |||
| ec42ebcb25 | |||
| f4629e5fcc | |||
| dafe4c5336 | |||
| 5439d5111a | |||
| 1e5ef47a4d | |||
| 2b87c67876 | |||
| 0db90c0e4b | |||
| 1e07093101 | |||
| ce25ee930a | |||
| a293e0286a | |||
| 012b8a7ff6 | |||
| d5d078413c | |||
| 17662ef7cb | |||
| 9d8da15d0e | |||
| d503cf5dc9 | |||
| f653a1e98c | |||
| 3886277616 | |||
| 83018fabe0 |
@@ -66,6 +66,33 @@
|
|||||||
"units": ["g/m³", "mol/m³"]
|
"units": ["g/m³", "mol/m³"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Quantity (Ammonium)",
|
||||||
|
"models": [
|
||||||
|
{
|
||||||
|
"name": "VegaAmmoniaSense 10",
|
||||||
|
"units": ["g/m³", "mol/m³"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Quantity (NOx)",
|
||||||
|
"models": [
|
||||||
|
{
|
||||||
|
"name": "VegaNOxSense 10",
|
||||||
|
"units": ["g/m³", "mol/m³"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Quantity (TSS)",
|
||||||
|
"models": [
|
||||||
|
{
|
||||||
|
"name": "VegaSolidsProbe",
|
||||||
|
"units": ["g/m³"]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -83,7 +110,6 @@
|
|||||||
{
|
{
|
||||||
"id": "hidrostal-pump-001",
|
"id": "hidrostal-pump-001",
|
||||||
"name": "hidrostal-H05K-S03R",
|
"name": "hidrostal-H05K-S03R",
|
||||||
|
|
||||||
"units": ["l/s"]
|
"units": ["l/s"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
1
datasets/get_all_assets.php
Normal file
1
datasets/get_all_assets.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Database connection failed: SQLSTATE[28000] [1045] Access denied for user 'pimmoe1q_rdlab'@'localhost' (using password: YES)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,229 +0,0 @@
|
|||||||
{
|
|
||||||
"success": true,
|
|
||||||
"message": "Product modellen succesvol opgehaald.",
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"id": "1",
|
|
||||||
"name": "Macbook Air 12",
|
|
||||||
"product_model_subtype_id": "1",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "1",
|
|
||||||
"product_model_status": null,
|
|
||||||
"vendor_name": "Apple",
|
|
||||||
"product_subtype_name": "Laptop",
|
|
||||||
"product_model_meta": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "2",
|
|
||||||
"name": "Macbook Air 13",
|
|
||||||
"product_model_subtype_id": "1",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "1",
|
|
||||||
"product_model_status": null,
|
|
||||||
"vendor_name": "Apple",
|
|
||||||
"product_subtype_name": "Laptop",
|
|
||||||
"product_model_meta": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "3",
|
|
||||||
"name": "AirMac 1 128 GB White",
|
|
||||||
"product_model_subtype_id": "2",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "1",
|
|
||||||
"product_model_status": null,
|
|
||||||
"vendor_name": "Apple",
|
|
||||||
"product_subtype_name": "Desktop",
|
|
||||||
"product_model_meta": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "4",
|
|
||||||
"name": "AirMac 2 256 GB Black",
|
|
||||||
"product_model_subtype_id": "2",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "1",
|
|
||||||
"product_model_status": null,
|
|
||||||
"vendor_name": "Apple",
|
|
||||||
"product_subtype_name": "Desktop",
|
|
||||||
"product_model_meta": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "5",
|
|
||||||
"name": "AirMac 2 256 GB White",
|
|
||||||
"product_model_subtype_id": "2",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "1",
|
|
||||||
"product_model_status": null,
|
|
||||||
"vendor_name": "Apple",
|
|
||||||
"product_subtype_name": "Desktop",
|
|
||||||
"product_model_meta": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "6",
|
|
||||||
"name": "Vegabar 14",
|
|
||||||
"product_model_subtype_id": "3",
|
|
||||||
"product_model_description": "vegabar 14",
|
|
||||||
"vendor_id": "4",
|
|
||||||
"product_model_status": "Actief",
|
|
||||||
"vendor_name": "vega",
|
|
||||||
"product_subtype_name": "pressure",
|
|
||||||
"product_model_meta": {
|
|
||||||
"machineCurve": {
|
|
||||||
"np": {
|
|
||||||
"700": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
12.962460720759278,
|
|
||||||
20.65443723573673,
|
|
||||||
31.029351002816465,
|
|
||||||
44.58926412111886,
|
|
||||||
62.87460150792057
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"800": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
13.035157335397209,
|
|
||||||
20.74906989186132,
|
|
||||||
31.029351002816465,
|
|
||||||
44.58926412111886,
|
|
||||||
62.87460150792057
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"900": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
13.064663380158798,
|
|
||||||
20.927197054134297,
|
|
||||||
31.107126521989933,
|
|
||||||
44.58926412111886,
|
|
||||||
62.87460150792057
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"1000": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
13.039271391128953,
|
|
||||||
21.08680188366637,
|
|
||||||
31.30899920405947,
|
|
||||||
44.58926412111886,
|
|
||||||
62.87460150792057
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"1100": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
12.940075520572446,
|
|
||||||
21.220547481589954,
|
|
||||||
31.51468295656385,
|
|
||||||
44.621326083982,
|
|
||||||
62.87460150792057
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nq": {
|
|
||||||
"700": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
119.13938764447377,
|
|
||||||
150.12178608265387,
|
|
||||||
178.82698019104356,
|
|
||||||
202.3699313222398,
|
|
||||||
227.06382297856618
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"800": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
112.59072109293984,
|
|
||||||
148.15847460389205,
|
|
||||||
178.82698019104356,
|
|
||||||
202.3699313222398,
|
|
||||||
227.06382297856618
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"900": {
|
|
||||||
"x": [
|
|
||||||
0,
|
|
||||||
24.59,
|
|
||||||
49.18,
|
|
||||||
73.77,
|
|
||||||
100
|
|
||||||
],
|
|
||||||
"y": [
|
|
||||||
105.6217241180404,
|
|
||||||
144.00502117747064,
|
|
||||||
177.15212647335034,
|
|
||||||
202.3699313222398,
|
|
||||||
227.06382297856618
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "7",
|
|
||||||
"name": "Vegabar 10",
|
|
||||||
"product_model_subtype_id": "3",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "4",
|
|
||||||
"product_model_status": "Actief",
|
|
||||||
"vendor_name": "vega",
|
|
||||||
"product_subtype_name": "pressure",
|
|
||||||
"product_model_meta": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "8",
|
|
||||||
"name": "VegaFlow 10",
|
|
||||||
"product_model_subtype_id": "4",
|
|
||||||
"product_model_description": null,
|
|
||||||
"vendor_id": "4",
|
|
||||||
"product_model_status": "Actief",
|
|
||||||
"vendor_name": "vega",
|
|
||||||
"product_subtype_name": "flow",
|
|
||||||
"product_model_meta": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
4
index.js
4
index.js
@@ -14,7 +14,6 @@ const validation = require('./src/helper/validationUtils.js');
|
|||||||
const configUtils = require('./src/helper/configUtils.js');
|
const configUtils = require('./src/helper/configUtils.js');
|
||||||
const assertions = require('./src/helper/assertionUtils.js')
|
const assertions = require('./src/helper/assertionUtils.js')
|
||||||
const coolprop = require('./src/coolprop-node/src/index.js');
|
const coolprop = require('./src/coolprop-node/src/index.js');
|
||||||
const gravity = require('./src/helper/gravity.js')
|
|
||||||
|
|
||||||
// Domain-specific modules
|
// Domain-specific modules
|
||||||
const { MeasurementContainer } = require('./src/measurements/index.js');
|
const { MeasurementContainer } = require('./src/measurements/index.js');
|
||||||
@@ -45,6 +44,5 @@ module.exports = {
|
|||||||
convert,
|
convert,
|
||||||
MenuManager,
|
MenuManager,
|
||||||
childRegistrationUtils,
|
childRegistrationUtils,
|
||||||
loadCurve,
|
loadCurve
|
||||||
gravity
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,30 +47,30 @@ class ConfigManager {
|
|||||||
return fs.existsSync(configPath);
|
return fs.existsSync(configPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
createEndpoint(nodeName) {
|
createEndpoint(nodeName) {
|
||||||
try {
|
try {
|
||||||
// Load the config for this node
|
// Load the config for this node
|
||||||
const config = this.getConfig(nodeName);
|
const config = this.getConfig(nodeName);
|
||||||
|
|
||||||
// Convert config to JSON
|
// Convert config to JSON
|
||||||
const configJSON = JSON.stringify(config, null, 2);
|
const configJSON = JSON.stringify(config, null, 2);
|
||||||
|
|
||||||
// Assemble the complete script
|
// Assemble the complete script
|
||||||
return `
|
return `
|
||||||
// Create the namespace structure
|
// Create the namespace structure
|
||||||
window.EVOLV = window.EVOLV || {};
|
window.EVOLV = window.EVOLV || {};
|
||||||
window.EVOLV.nodes = window.EVOLV.nodes || {};
|
window.EVOLV.nodes = window.EVOLV.nodes || {};
|
||||||
window.EVOLV.nodes.${nodeName} = window.EVOLV.nodes.${nodeName} || {};
|
window.EVOLV.nodes.${nodeName} = window.EVOLV.nodes.${nodeName} || {};
|
||||||
|
|
||||||
// Inject the pre-loaded config data directly into the namespace
|
// Inject the pre-loaded config data directly into the namespace
|
||||||
window.EVOLV.nodes.${nodeName}.config = ${configJSON};
|
window.EVOLV.nodes.${nodeName}.config = ${configJSON};
|
||||||
|
|
||||||
console.log('${nodeName} config loaded and endpoint created');
|
console.log('${nodeName} config loaded and endpoint created');
|
||||||
`;
|
`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to create endpoint for '${nodeName}': ${error.message}`);
|
throw new Error(`Failed to create endpoint for '${nodeName}': ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ConfigManager;
|
module.exports = ConfigManager;
|
||||||
@@ -348,13 +348,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"control": {
|
"control": {
|
||||||
"mode": {
|
"controlStrategy": {
|
||||||
"default": "levelbased",
|
"default": "levelBased",
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "string",
|
"type": "enum",
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"value": "levelbased",
|
"value": "levelBased",
|
||||||
"description": "Lead and lag pumps are controlled by basin level thresholds."
|
"description": "Lead and lag pumps are controlled by basin level thresholds."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -362,21 +362,9 @@
|
|||||||
"description": "Pumps target a discharge pressure setpoint."
|
"description": "Pumps target a discharge pressure setpoint."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"value": "flowBased",
|
"value": "flowTracking",
|
||||||
"description": "Pumps modulate to match measured inflow or downstream demand."
|
"description": "Pumps modulate to match measured inflow or downstream demand."
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"value": "percentageBased",
|
|
||||||
"description": "Pumps operate to maintain basin volume at a target percentage."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"value":"powerBased",
|
|
||||||
"description": "Pumps are controlled based on power consumption.For example, to limit peak power usage or operate within netcongestion limits."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"value": "hybrid",
|
|
||||||
"description": "Combines multiple control strategies for optimized operation."
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"value": "manual",
|
"value": "manual",
|
||||||
"description": "Pumps are operated manually or by an external controller."
|
"description": "Pumps are operated manually or by an external controller."
|
||||||
@@ -385,114 +373,96 @@
|
|||||||
"description": "Primary control philosophy for pump actuation."
|
"description": "Primary control philosophy for pump actuation."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"allowedModes": {
|
"levelSetpoints": {
|
||||||
"default": [
|
"default": {
|
||||||
"levelbased",
|
"startLeadPump": 1.2,
|
||||||
"pressurebased",
|
"stopLeadPump": 0.8,
|
||||||
"flowbased",
|
"startLagPump": 1.8,
|
||||||
"percentagebased",
|
"stopLagPump": 1.4,
|
||||||
"powerbased",
|
"alarmHigh": 2.3,
|
||||||
"manual"
|
"alarmLow": 0.3
|
||||||
],
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "set",
|
"type": "object",
|
||||||
"itemType": "string",
|
"description": "Level thresholds that govern pump staging and alarms (m).",
|
||||||
"description": "List of control modes that the station is permitted to operate in."
|
"schema": {
|
||||||
}
|
"startLeadPump": {
|
||||||
},
|
"default": 1.2,
|
||||||
"levelbased": {
|
"rules": {
|
||||||
"thresholds": {
|
"type": "number",
|
||||||
"default": [30,40,50,60,70,80,90],
|
"description": "Level that starts the lead pump."
|
||||||
"rules": {
|
|
||||||
"type": "array",
|
|
||||||
"description": "Each time a threshold is overwritten a new pump can start or kick into higher gear. Volume thresholds (%) in ascending order used for level-based control."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"timeThresholdSeconds": {
|
|
||||||
"default": 5,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Duration the volume condition must persist before triggering pump actions (seconds)."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"pressureBased": {
|
|
||||||
"pressureSetpoint": {
|
|
||||||
"default": 1000,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"max": 5000,
|
|
||||||
"description": "Target discharge pressure when operating in pressure control (kPa)."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flowBased": {
|
|
||||||
"equalizationTargetPercent": {
|
|
||||||
"default": 60,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"max": 100,
|
|
||||||
"description": "Target fill percentage of the basin when operating in equalization mode."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flowBalanceTolerance": {
|
|
||||||
"default": 5,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Allowable error between inflow and outflow before adjustments are triggered (m3/h)."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"percentageBased": {
|
|
||||||
"targetVolumePercent": {
|
|
||||||
"default": 50,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"max": 100,
|
|
||||||
"description": "Target basin volume percentage to maintain during percentage-based control."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tolerancePercent": {
|
|
||||||
"default": 5,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Acceptable deviation from the target volume percentage before corrective action is taken."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"powerBased": {
|
|
||||||
"maxPowerKW": {
|
|
||||||
"default": 50,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Maximum allowable power consumption for the pumping station (kW)."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"powerControlMode": {
|
|
||||||
"default": "limit",
|
|
||||||
"rules": {
|
|
||||||
"type": "enum",
|
|
||||||
"values": [
|
|
||||||
{
|
|
||||||
"value": "limit",
|
|
||||||
"description": "Limit pump operation to stay below the max power threshold."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"value": "optimize",
|
|
||||||
"description": "Optimize pump scheduling to minimize power usage while meeting flow demands."
|
|
||||||
}
|
}
|
||||||
],
|
},
|
||||||
"description": "Defines how power constraints are managed during operation."
|
"stopLeadPump": {
|
||||||
|
"default": 0.8,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Level that stops the lead pump."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"startLagPump": {
|
||||||
|
"default": 1.8,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Level that starts the lag pump."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"stopLagPump": {
|
||||||
|
"default": 1.4,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Level that stops the lag pump."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"alarmHigh": {
|
||||||
|
"default": 2.3,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "High level alarm threshold."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"alarmLow": {
|
||||||
|
"default": 0.3,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Low level alarm threshold."
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pressureSetpoint": {
|
||||||
|
"default": 250,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 0,
|
||||||
|
"description": "Target discharge pressure when operating in pressure control (kPa)."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"alarmDebounceSeconds": {
|
||||||
|
"default": 10,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 0,
|
||||||
|
"description": "Time a condition must persist before raising an alarm (seconds)."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"equalizationTargetPercent": {
|
||||||
|
"default": 60,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 0,
|
||||||
|
"max": 100,
|
||||||
|
"description": "Target fill percentage of the basin when operating in equalization mode."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoRestartAfterPowerLoss": {
|
||||||
|
"default": true,
|
||||||
|
"rules": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "If true, pumps resume based on last known state after power restoration."
|
||||||
|
}
|
||||||
|
},
|
||||||
"manualOverrideTimeoutMinutes": {
|
"manualOverrideTimeoutMinutes": {
|
||||||
"default": 30,
|
"default": 30,
|
||||||
"rules": {
|
"rules": {
|
||||||
@@ -500,63 +470,13 @@
|
|||||||
"min": 0,
|
"min": 0,
|
||||||
"description": "Duration after which a manual override expires automatically (minutes)."
|
"description": "Duration after which a manual override expires automatically (minutes)."
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
"safety": {
|
|
||||||
"enableDryRunProtection": {
|
|
||||||
"default": true,
|
|
||||||
"rules": {
|
|
||||||
"type": "boolean",
|
|
||||||
"description": "If true, pumps will be prevented from running if basin volume is too low."
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"dryRunThresholdPercent": {
|
"flowBalanceTolerance": {
|
||||||
"default": 2,
|
"default": 5,
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 100,
|
"description": "Allowable error between inflow and outflow before adjustments are triggered (m3/h)."
|
||||||
"description": "Volume percentage below which dry run protection activates."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dryRunDebounceSeconds": {
|
|
||||||
"default": 30,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Time the low-volume condition must persist before dry-run protection engages (seconds)."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"enableOverfillProtection": {
|
|
||||||
"default": true,
|
|
||||||
"rules": {
|
|
||||||
"type": "boolean",
|
|
||||||
"description": "If true, high level alarms and shutdowns will be enforced to prevent overfilling."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"overfillThresholdPercent": {
|
|
||||||
"default": 98,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"max": 100,
|
|
||||||
"description": "Volume percentage above which overfill protection activates."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"overfillDebounceSeconds": {
|
|
||||||
"default": 30,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Time the high-volume condition must persist before overfill protection engages (seconds)."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"timeleftToFullOrEmptyThresholdSeconds": {
|
|
||||||
"default": 120,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"min": 0,
|
|
||||||
"description": "Time threshold (seconds) used to predict imminent full or empty conditions."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -245,6 +245,10 @@
|
|||||||
{
|
{
|
||||||
"value": "fysicalControl",
|
"value": "fysicalControl",
|
||||||
"description": "Controlled via physical buttons or switches; ignores external automated commands."
|
"description": "Controlled via physical buttons or switches; ignores external automated commands."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "maintenance",
|
||||||
|
"description": "No active control from auto, virtual, or fysical sources."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "The operational mode of the machine."
|
"description": "The operational mode of the machine."
|
||||||
@@ -256,13 +260,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"schema":{
|
"schema":{
|
||||||
"auto": {
|
"auto": {
|
||||||
"default": [
|
"default": ["statusCheck", "execMovement", "execSequence", "emergencyStop"],
|
||||||
"statuscheck",
|
|
||||||
"execmovement",
|
|
||||||
"execsequence",
|
|
||||||
"emergencystop",
|
|
||||||
"entermaintenance"
|
|
||||||
],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "set",
|
"type": "set",
|
||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
@@ -270,13 +268,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"virtualControl": {
|
"virtualControl": {
|
||||||
"default": [
|
"default": ["statusCheck", "execMovement", "execSequence", "emergencyStop"],
|
||||||
"statuscheck",
|
|
||||||
"execmovement",
|
|
||||||
"execsequence",
|
|
||||||
"emergencystop",
|
|
||||||
"exitmaintenance"
|
|
||||||
],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "set",
|
"type": "set",
|
||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
@@ -284,22 +276,25 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fysicalControl": {
|
"fysicalControl": {
|
||||||
"default": [
|
"default": ["statusCheck", "emergencyStop"],
|
||||||
"statuscheck",
|
|
||||||
"emergencystop",
|
|
||||||
"entermaintenance",
|
|
||||||
"exitmaintenance"
|
|
||||||
],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "set",
|
"type": "set",
|
||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
"description": "Actions allowed in fysicalControl mode."
|
"description": "Actions allowed in fysicalControl mode."
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"maintenance": {
|
||||||
|
"default": ["statusCheck"],
|
||||||
|
"rules": {
|
||||||
|
"type": "set",
|
||||||
|
"itemType": "string",
|
||||||
|
"description": "Actions allowed in maintenance mode."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"description": "Information about valid command sources recognized by the machine."
|
"description": "Information about valid command sources recognized by the machine."
|
||||||
},
|
}
|
||||||
|
},
|
||||||
"allowedSources":{
|
"allowedSources":{
|
||||||
"default": {},
|
"default": {},
|
||||||
"rules": {
|
"rules": {
|
||||||
@@ -391,22 +386,6 @@
|
|||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
"description": "Sequence of states for booting up the machine."
|
"description": "Sequence of states for booting up the machine."
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"entermaintenance":{
|
|
||||||
"default": ["stopping","coolingdown","idle","maintenance"],
|
|
||||||
"rules": {
|
|
||||||
"type": "set",
|
|
||||||
"itemType": "string",
|
|
||||||
"description": "Sequence of states if the machine is running to put it in maintenance state"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exitmaintenance":{
|
|
||||||
"default": ["off","idle"],
|
|
||||||
"rules": {
|
|
||||||
"type": "set",
|
|
||||||
"itemType": "string",
|
|
||||||
"description": "Sequence of states if the machine is running to put it in maintenance state"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -433,6 +412,14 @@
|
|||||||
],
|
],
|
||||||
"description": "The frequency at which calculations are performed."
|
"description": "The frequency at which calculations are performed."
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"flowNumber": {
|
||||||
|
"default": 1,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"nullable": false,
|
||||||
|
"description": "Defines which effluent flow of the parent node to handle."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3,61 +3,11 @@ const customRefs = require('./refData.js');
|
|||||||
|
|
||||||
class CoolPropWrapper {
|
class CoolPropWrapper {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
this.defaultRefrigerant = null;
|
this.defaultRefrigerant = null;
|
||||||
this.defaultTempUnit = 'K'; // K, C, F
|
this.defaultTempUnit = 'K'; // K, C, F
|
||||||
this.defaultPressureUnit = 'Pa' // Pa, kPa, bar, psi
|
this.defaultPressureUnit = 'Pa' // Pa, kPa, bar, psi
|
||||||
this.customRef = false;
|
this.customRef = false;
|
||||||
this.PropsSI = this._propsSI.bind(this);
|
|
||||||
|
|
||||||
|
|
||||||
// 🔹 Wastewater correction options (defaults)
|
|
||||||
this._ww = {
|
|
||||||
enabled: true,
|
|
||||||
tss_g_per_L: 3.5, // default MLSS / TSS
|
|
||||||
density_k: 2e-4, // +0.02% per g/L
|
|
||||||
viscosity_k: 0.07, // +7% per g/L (clamped)
|
|
||||||
viscosity_max_gpl: 4 // cap effect at 4 g/L
|
|
||||||
};
|
|
||||||
|
|
||||||
this._initPromise = null;
|
|
||||||
this._autoInit({ refrigerant: 'Water' });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_isWastewaterFluid(fluidRaw) {
|
|
||||||
if (!fluidRaw) return false;
|
|
||||||
const token = String(fluidRaw).trim().toLowerCase();
|
|
||||||
return token === 'wastewater' || token.startsWith('wastewater:');
|
|
||||||
}
|
|
||||||
|
|
||||||
_parseWastewaterFluid(fluidRaw) {
|
|
||||||
if (!this._isWastewaterFluid(fluidRaw)) return null;
|
|
||||||
const ww = { ...this._ww };
|
|
||||||
const [, tail] = String(fluidRaw).split(':');
|
|
||||||
if (tail) {
|
|
||||||
tail.split(',').forEach(pair => {
|
|
||||||
const [key, value] = pair.split('=').map(s => s.trim().toLowerCase());
|
|
||||||
if (key === 'tss' && !Number.isNaN(Number(value))) {
|
|
||||||
ww.tss_g_per_L = Number(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return ww;
|
|
||||||
}
|
|
||||||
|
|
||||||
_applyWastewaterCorrection(outputKey, baseValue, ww) {
|
|
||||||
if (!Number.isFinite(baseValue) || !ww || !ww.enabled) return baseValue;
|
|
||||||
switch (outputKey.toUpperCase()) {
|
|
||||||
case 'D': // density
|
|
||||||
return baseValue * (1 + ww.density_k * ww.tss_g_per_L);
|
|
||||||
case 'V': // viscosity
|
|
||||||
const effTss = Math.min(ww.tss_g_per_L, ww.viscosity_max_gpl);
|
|
||||||
return baseValue * (1 + ww.viscosity_k * effTss);
|
|
||||||
default:
|
|
||||||
return baseValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temperature conversion helpers
|
// Temperature conversion helpers
|
||||||
@@ -457,31 +407,13 @@ class CoolPropWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_autoInit(defaults) {
|
// Direct access to CoolProp functions
|
||||||
if (!this._initPromise) {
|
|
||||||
this._initPromise = this.init(defaults);
|
|
||||||
}
|
|
||||||
return this._initPromise;
|
|
||||||
}
|
|
||||||
|
|
||||||
_propsSI(outputKey, inKey1, inVal1, inKey2, inVal2, fluidRaw) {
|
|
||||||
if (!this.initialized) {
|
|
||||||
// Start init if no one else asked yet
|
|
||||||
this._autoInit({ refrigerant: this.defaultRefrigerant || 'Water' });
|
|
||||||
throw new Error('CoolProp is still warming up, retry PropsSI in a moment');
|
|
||||||
}
|
|
||||||
const ww = this._parseWastewaterFluid(fluidRaw);
|
|
||||||
const fluid = ww ? 'Water' : (this.customRefString || fluidRaw);
|
|
||||||
const baseValue = coolprop.PropsSI(outputKey, inKey1, inVal1, inKey2, inVal2, fluid);
|
|
||||||
return ww ? this._applyWastewaterCorrection(outputKey, baseValue, ww) : baseValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Access to coolprop
|
|
||||||
async getPropsSI() {
|
async getPropsSI() {
|
||||||
await this._ensureInit({ refrigerant: this.defaultRefrigerant || 'Water' });
|
if(!this.initialized) {
|
||||||
return this.PropsSI;
|
await coolprop.init();
|
||||||
|
}
|
||||||
|
return coolprop.PropsSI;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new CoolPropWrapper();
|
module.exports = new CoolPropWrapper();
|
||||||
|
|||||||
@@ -11,8 +11,12 @@ class ChildRegistrationUtils {
|
|||||||
|
|
||||||
this.logger.debug(`Registering child: ${name} (${id}) as ${softwareType} at ${positionVsParent}`);
|
this.logger.debug(`Registering child: ${name} (${id}) as ${softwareType} at ${positionVsParent}`);
|
||||||
|
|
||||||
// Enhanced child setup
|
// Enhanced child setup - multiple parents
|
||||||
child.parent = this.mainClass;
|
if (Array.isArray(child.parent)) {
|
||||||
|
child.parent.push(this.mainClass);
|
||||||
|
} else {
|
||||||
|
child.parent = [this.mainClass];
|
||||||
|
}
|
||||||
child.positionVsParent = positionVsParent;
|
child.positionVsParent = positionVsParent;
|
||||||
|
|
||||||
// Enhanced measurement container with rich context
|
// Enhanced measurement container with rich context
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
/**
|
|
||||||
* Gravity calculations based on WGS-84 ellipsoid model.
|
|
||||||
* Author: Rene de Ren (Waterschap Brabantse Delta)
|
|
||||||
* License: EUPL-1.2
|
|
||||||
*/
|
|
||||||
|
|
||||||
class Gravity {
|
|
||||||
constructor() {
|
|
||||||
// Standard (conventional) gravity at 45° latitude, sea level
|
|
||||||
this.g0 = 9.80665; // m/s²
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns standard gravity (constant)
|
|
||||||
* @returns {number} gravity in m/s²
|
|
||||||
*/
|
|
||||||
getStandardGravity() {
|
|
||||||
return this.g0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Computes local gravity based on latitude and elevation.
|
|
||||||
* Formula: WGS-84 normal gravity (Somigliana)
|
|
||||||
* @param {number} latitudeDeg Latitude in degrees (−90 → +90)
|
|
||||||
* @param {number} elevationM Elevation above sea level [m]
|
|
||||||
* @returns {number} gravity in m/s²
|
|
||||||
*/
|
|
||||||
getLocalGravity(latitudeDeg, elevationM = 0) {
|
|
||||||
const phi = (latitudeDeg * Math.PI) / 180;
|
|
||||||
const sinPhi = Math.sin(phi);
|
|
||||||
const sin2 = sinPhi * sinPhi;
|
|
||||||
const sin2_2phi = Math.sin(2 * phi) ** 2;
|
|
||||||
|
|
||||||
// WGS-84 normal gravity on the ellipsoid
|
|
||||||
const gSurface =
|
|
||||||
9.780327 * (1 + 0.0053024 * sin2 - 0.0000058 * sin2_2phi);
|
|
||||||
|
|
||||||
// Free-air correction for elevation (~ −3.086×10⁻⁶ m/s² per m)
|
|
||||||
const gLocal = gSurface - 3.086e-6 * elevationM;
|
|
||||||
return gLocal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates hydrostatic pressure difference (ΔP = ρ g h)
|
|
||||||
* @param {number} density Fluid density [kg/m³]
|
|
||||||
* @param {number} heightM Height difference [m]
|
|
||||||
* @param {number} latitudeDeg Latitude (for local g)
|
|
||||||
* @param {number} elevationM Elevation (for local g)
|
|
||||||
* @returns {number} Pressure difference [Pa]
|
|
||||||
*/
|
|
||||||
pressureHead(density, heightM, latitudeDeg = 45, elevationM = 0) {
|
|
||||||
const g = this.getLocalGravity(latitudeDeg, elevationM);
|
|
||||||
return density * g * heightM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates weight force (F = m g)
|
|
||||||
* @param {number} massKg Mass [kg]
|
|
||||||
* @param {number} latitudeDeg Latitude (for local g)
|
|
||||||
* @param {number} elevationM Elevation (for local g)
|
|
||||||
* @returns {number} Force [N]
|
|
||||||
*/
|
|
||||||
weightForce(massKg, latitudeDeg = 45, elevationM = 0) {
|
|
||||||
const g = this.getLocalGravity(latitudeDeg, elevationM);
|
|
||||||
return massKg * g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = new Gravity();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
const gravity = gravity;
|
|
||||||
|
|
||||||
// Standard gravity
|
|
||||||
console.log('g₀ =', gravity.getStandardGravity(), 'm/s²');
|
|
||||||
|
|
||||||
// Local gravity (Breda ≈ 51.6° N, 3 m elevation)
|
|
||||||
console.log('g @ Breda =', gravity.getLocalGravity(51.6, 3).toFixed(6), 'm/s²');
|
|
||||||
|
|
||||||
// Head pressure for 5 m water column at Breda
|
|
||||||
console.log(
|
|
||||||
'ΔP =',
|
|
||||||
gravity.pressureHead(1000, 5, 51.6, 3).toFixed(1),
|
|
||||||
'Pa'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Weight of 1 kg mass at Breda
|
|
||||||
console.log('Weight =', gravity.weightForce(1, 51.6, 3).toFixed(6), 'N');
|
|
||||||
*/
|
|
||||||
@@ -180,6 +180,7 @@ async apiCall(node) {
|
|||||||
// Only add tagCode to URL if it exists
|
// Only add tagCode to URL if it exists
|
||||||
if (tagCode) {
|
if (tagCode) {
|
||||||
apiUrl += `&asset_tag_number=${tagCode}`;
|
apiUrl += `&asset_tag_number=${tagCode}`;
|
||||||
|
console.log('hello there');
|
||||||
}
|
}
|
||||||
|
|
||||||
assetregisterAPI += apiUrl;
|
assetregisterAPI += apiUrl;
|
||||||
@@ -460,6 +461,10 @@ populateModels(
|
|||||||
// Store only the metadata for the selected model
|
// Store only the metadata for the selected model
|
||||||
node["modelMetadata"] = modelData.find((model) => model.name === selectedModel);
|
node["modelMetadata"] = modelData.find((model) => model.name === selectedModel);
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
console.log('hello here I am:');
|
||||||
|
console.log(node["modelMetadata"]);
|
||||||
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ async apiCall(node) {
|
|||||||
// Only add tagCode to URL if it exists
|
// Only add tagCode to URL if it exists
|
||||||
if (tagCode) {
|
if (tagCode) {
|
||||||
apiUrl += `&asset_tag_number=${tagCode}`;
|
apiUrl += `&asset_tag_number=${tagCode}`;
|
||||||
|
console.log('hello there');
|
||||||
}
|
}
|
||||||
|
|
||||||
assetregisterAPI += apiUrl;
|
assetregisterAPI += apiUrl;
|
||||||
@@ -460,7 +461,10 @@ populateModels(
|
|||||||
// Store only the metadata for the selected model
|
// Store only the metadata for the selected model
|
||||||
node["modelMetadata"] = modelData.find((model) => model.name === selectedModel);
|
node["modelMetadata"] = modelData.find((model) => model.name === selectedModel);
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
console.log('hello here I am:');
|
||||||
|
console.log(node["modelMetadata"]);
|
||||||
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class OutputUtils {
|
|||||||
|
|
||||||
influxDBFormat(changedFields, config , flatTags) {
|
influxDBFormat(changedFields, config , flatTags) {
|
||||||
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
|
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
|
||||||
const measurement = `${config.functionality?.softwareType}_${config.general?.id}`;
|
const measurement = config.general.name;
|
||||||
const payload = {
|
const payload = {
|
||||||
measurement: measurement,
|
measurement: measurement,
|
||||||
fields: changedFields,
|
fields: changedFields,
|
||||||
@@ -104,23 +104,24 @@ class OutputUtils {
|
|||||||
return {
|
return {
|
||||||
// general properties
|
// general properties
|
||||||
id: config.general?.id,
|
id: config.general?.id,
|
||||||
|
name: config.general?.name,
|
||||||
|
unit: config.general?.unit,
|
||||||
// functionality properties
|
// functionality properties
|
||||||
softwareType: config.functionality?.softwareType,
|
softwareType: config.functionality?.softwareType,
|
||||||
role: config.functionality?.role,
|
role: config.functionality?.role,
|
||||||
// asset properties (exclude machineCurve)
|
// asset properties (exclude machineCurve)
|
||||||
uuid: config.asset?.uuid,
|
uuid: config.asset?.uuid,
|
||||||
tagcode: config.asset?.tagcode,
|
|
||||||
geoLocation: config.asset?.geoLocation,
|
geoLocation: config.asset?.geoLocation,
|
||||||
category: config.asset?.category,
|
supplier: config.asset?.supplier,
|
||||||
type: config.asset?.type,
|
type: config.asset?.type,
|
||||||
|
subType: config.asset?.subType,
|
||||||
model: config.asset?.model,
|
model: config.asset?.model,
|
||||||
unit: config.general?.unit,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
processFormat(changedFields,config) {
|
processFormat(changedFields,config) {
|
||||||
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
|
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
|
||||||
const measurement = `${config.functionality?.softwareType}_${config.general?.id}`;
|
const measurement = config.general.name;
|
||||||
const payload = changedFields;
|
const payload = changedFields;
|
||||||
const topic = measurement;
|
const topic = measurement;
|
||||||
const msg = { topic: topic, payload: payload };
|
const msg = { topic: topic, payload: payload };
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class Measurement {
|
|||||||
|
|
||||||
// Create a new measurement that is the difference between two positions
|
// Create a new measurement that is the difference between two positions
|
||||||
static createDifference(upstreamMeasurement, downstreamMeasurement) {
|
static createDifference(upstreamMeasurement, downstreamMeasurement) {
|
||||||
|
console.log('hello:');
|
||||||
if (upstreamMeasurement.type !== downstreamMeasurement.type ||
|
if (upstreamMeasurement.type !== downstreamMeasurement.type ||
|
||||||
upstreamMeasurement.variant !== downstreamMeasurement.variant) {
|
upstreamMeasurement.variant !== downstreamMeasurement.variant) {
|
||||||
throw new Error('Cannot calculate difference between different measurement types or variants');
|
throw new Error('Cannot calculate difference between different measurement types or variants');
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ class PhysicalPositionMenu {
|
|||||||
return {
|
return {
|
||||||
positionGroups: [
|
positionGroups: [
|
||||||
{ group: 'Positional', options: [
|
{ group: 'Positional', options: [
|
||||||
{ value: 'upstream', label: '→ Upstream', icon: '→'}, //flow is then typically left to right
|
{ value: 'upstream', label: '← Upstream', icon: '←'},
|
||||||
{ value: 'atEquipment', label: '⊥ in place' , icon: '⊥' },
|
{ value: 'atEquipment', label: '⊥ in place' , icon: '⊥' },
|
||||||
{ value: 'downstream', label: '← Downstream' , icon: '←' }
|
{ value: 'downstream', label: '→ Downstream' , icon: '→' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,279 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Discrete PID controller with optional derivative filtering and integral limits.
|
|
||||||
* Sample times are expressed in milliseconds to align with Node.js timestamps.
|
|
||||||
*/
|
|
||||||
class PIDController {
|
|
||||||
constructor(options = {}) {
|
|
||||||
const {
|
|
||||||
kp = 1,
|
|
||||||
ki = 0,
|
|
||||||
kd = 0,
|
|
||||||
sampleTime = 1000,
|
|
||||||
derivativeFilter = 0.15,
|
|
||||||
outputMin = Number.NEGATIVE_INFINITY,
|
|
||||||
outputMax = Number.POSITIVE_INFINITY,
|
|
||||||
integralMin = null,
|
|
||||||
integralMax = null,
|
|
||||||
derivativeOnMeasurement = true,
|
|
||||||
autoMode = true
|
|
||||||
} = options;
|
|
||||||
|
|
||||||
this.kp = 0;
|
|
||||||
this.ki = 0;
|
|
||||||
this.kd = 0;
|
|
||||||
|
|
||||||
this.setTunings({ kp, ki, kd });
|
|
||||||
this.setSampleTime(sampleTime);
|
|
||||||
this.setOutputLimits(outputMin, outputMax);
|
|
||||||
this.setIntegralLimits(integralMin, integralMax);
|
|
||||||
this.setDerivativeFilter(derivativeFilter);
|
|
||||||
|
|
||||||
this.derivativeOnMeasurement = Boolean(derivativeOnMeasurement);
|
|
||||||
this.autoMode = Boolean(autoMode);
|
|
||||||
|
|
||||||
this.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update controller gains at runtime.
|
|
||||||
* Accepts partial objects, e.g. setTunings({ kp: 2.0 }).
|
|
||||||
*/
|
|
||||||
setTunings({ kp = this.kp, ki = this.ki, kd = this.kd } = {}) {
|
|
||||||
[kp, ki, kd].forEach((gain, index) => {
|
|
||||||
if (!Number.isFinite(gain)) {
|
|
||||||
const label = ['kp', 'ki', 'kd'][index];
|
|
||||||
throw new TypeError(`${label} must be a finite number`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.kp = kp;
|
|
||||||
this.ki = ki;
|
|
||||||
this.kd = kd;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the controller execution interval in milliseconds.
|
|
||||||
*/
|
|
||||||
setSampleTime(sampleTimeMs = this.sampleTime) {
|
|
||||||
if (!Number.isFinite(sampleTimeMs) || sampleTimeMs <= 0) {
|
|
||||||
throw new RangeError('sampleTime must be a positive number of milliseconds');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sampleTime = sampleTimeMs;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constrain controller output.
|
|
||||||
*/
|
|
||||||
setOutputLimits(min = this.outputMin, max = this.outputMax) {
|
|
||||||
if (!Number.isFinite(min) && min !== Number.NEGATIVE_INFINITY) {
|
|
||||||
throw new TypeError('outputMin must be finite or -Infinity');
|
|
||||||
}
|
|
||||||
if (!Number.isFinite(max) && max !== Number.POSITIVE_INFINITY) {
|
|
||||||
throw new TypeError('outputMax must be finite or Infinity');
|
|
||||||
}
|
|
||||||
if (min >= max) {
|
|
||||||
throw new RangeError('outputMin must be smaller than outputMax');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.outputMin = min;
|
|
||||||
this.outputMax = max;
|
|
||||||
this.lastOutput = this._clamp(this.lastOutput ?? 0, this.outputMin, this.outputMax);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constrain the accumulated integral term.
|
|
||||||
*/
|
|
||||||
setIntegralLimits(min = this.integralMin ?? null, max = this.integralMax ?? null) {
|
|
||||||
if (min !== null && !Number.isFinite(min)) {
|
|
||||||
throw new TypeError('integralMin must be null or a finite number');
|
|
||||||
}
|
|
||||||
if (max !== null && !Number.isFinite(max)) {
|
|
||||||
throw new TypeError('integralMax must be null or a finite number');
|
|
||||||
}
|
|
||||||
if (min !== null && max !== null && min > max) {
|
|
||||||
throw new RangeError('integralMin must be smaller than integralMax');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.integralMin = min;
|
|
||||||
this.integralMax = max;
|
|
||||||
this.integral = this._applyIntegralLimits(this.integral ?? 0);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure exponential filter applied to the derivative term.
|
|
||||||
* Value 0 disables filtering, 1 keeps the previous derivative entirely.
|
|
||||||
*/
|
|
||||||
setDerivativeFilter(value = this.derivativeFilter ?? 0) {
|
|
||||||
if (!Number.isFinite(value) || value < 0 || value > 1) {
|
|
||||||
throw new RangeError('derivativeFilter must be between 0 and 1');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.derivativeFilter = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Switch between automatic (closed-loop) and manual mode.
|
|
||||||
*/
|
|
||||||
setMode(mode) {
|
|
||||||
if (mode !== 'automatic' && mode !== 'manual') {
|
|
||||||
throw new Error('mode must be either "automatic" or "manual"');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.autoMode = mode === 'automatic';
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Force a manual output (typically when in manual mode).
|
|
||||||
*/
|
|
||||||
setManualOutput(value) {
|
|
||||||
this._assertNumeric('manual output', value);
|
|
||||||
this.lastOutput = this._clamp(value, this.outputMin, this.outputMax);
|
|
||||||
return this.lastOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset dynamic state (integral, derivative memory, timestamps).
|
|
||||||
*/
|
|
||||||
reset(state = {}) {
|
|
||||||
const {
|
|
||||||
integral = 0,
|
|
||||||
lastOutput = 0,
|
|
||||||
timestamp = null
|
|
||||||
} = state;
|
|
||||||
|
|
||||||
this.integral = this._applyIntegralLimits(Number.isFinite(integral) ? integral : 0);
|
|
||||||
this.prevError = null;
|
|
||||||
this.prevMeasurement = null;
|
|
||||||
this.lastOutput = this._clamp(
|
|
||||||
Number.isFinite(lastOutput) ? lastOutput : 0,
|
|
||||||
this.outputMin ?? Number.NEGATIVE_INFINITY,
|
|
||||||
this.outputMax ?? Number.POSITIVE_INFINITY
|
|
||||||
);
|
|
||||||
this.lastTimestamp = Number.isFinite(timestamp) ? timestamp : null;
|
|
||||||
this.derivativeState = 0;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute one control loop iteration.
|
|
||||||
*/
|
|
||||||
update(setpoint, measurement, timestamp = Date.now()) {
|
|
||||||
this._assertNumeric('setpoint', setpoint);
|
|
||||||
this._assertNumeric('measurement', measurement);
|
|
||||||
this._assertNumeric('timestamp', timestamp);
|
|
||||||
|
|
||||||
if (!this.autoMode) {
|
|
||||||
this.prevError = setpoint - measurement;
|
|
||||||
this.prevMeasurement = measurement;
|
|
||||||
this.lastTimestamp = timestamp;
|
|
||||||
return this.lastOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lastTimestamp !== null && (timestamp - this.lastTimestamp) < this.sampleTime) {
|
|
||||||
return this.lastOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
const elapsedMs = this.lastTimestamp === null ? this.sampleTime : (timestamp - this.lastTimestamp);
|
|
||||||
const dtSeconds = Math.max(elapsedMs / 1000, Number.EPSILON);
|
|
||||||
|
|
||||||
const error = setpoint - measurement;
|
|
||||||
this.integral = this._applyIntegralLimits(this.integral + error * dtSeconds);
|
|
||||||
|
|
||||||
const derivative = this._computeDerivative({ error, measurement, dtSeconds });
|
|
||||||
this.derivativeState = this.derivativeFilter === 0
|
|
||||||
? derivative
|
|
||||||
: this.derivativeState + (derivative - this.derivativeState) * (1 - this.derivativeFilter);
|
|
||||||
|
|
||||||
const output = (this.kp * error) + (this.ki * this.integral) + (this.kd * this.derivativeState);
|
|
||||||
this.lastOutput = this._clamp(output, this.outputMin, this.outputMax);
|
|
||||||
|
|
||||||
this.prevError = error;
|
|
||||||
this.prevMeasurement = measurement;
|
|
||||||
this.lastTimestamp = timestamp;
|
|
||||||
|
|
||||||
return this.lastOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inspect controller state for diagnostics or persistence.
|
|
||||||
*/
|
|
||||||
getState() {
|
|
||||||
return {
|
|
||||||
kp: this.kp,
|
|
||||||
ki: this.ki,
|
|
||||||
kd: this.kd,
|
|
||||||
sampleTime: this.sampleTime,
|
|
||||||
outputLimits: { min: this.outputMin, max: this.outputMax },
|
|
||||||
integralLimits: { min: this.integralMin, max: this.integralMax },
|
|
||||||
derivativeFilter: this.derivativeFilter,
|
|
||||||
derivativeOnMeasurement: this.derivativeOnMeasurement,
|
|
||||||
autoMode: this.autoMode,
|
|
||||||
integral: this.integral,
|
|
||||||
lastOutput: this.lastOutput,
|
|
||||||
lastTimestamp: this.lastTimestamp
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
getLastOutput() {
|
|
||||||
return this.lastOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
_computeDerivative({ error, measurement, dtSeconds }) {
|
|
||||||
if (!(dtSeconds > 0) || !Number.isFinite(dtSeconds)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.derivativeOnMeasurement && this.prevMeasurement !== null) {
|
|
||||||
return -(measurement - this.prevMeasurement) / dtSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.prevError === null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (error - this.prevError) / dtSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
_applyIntegralLimits(value) {
|
|
||||||
if (!Number.isFinite(value)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = value;
|
|
||||||
if (this.integralMin !== null && result < this.integralMin) {
|
|
||||||
result = this.integralMin;
|
|
||||||
}
|
|
||||||
if (this.integralMax !== null && result > this.integralMax) {
|
|
||||||
result = this.integralMax;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
_assertNumeric(label, value) {
|
|
||||||
if (!Number.isFinite(value)) {
|
|
||||||
throw new TypeError(`${label} must be a finite number`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_clamp(value, min, max) {
|
|
||||||
if (value < min) {
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
if (value > max) {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = PIDController;
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
const { PIDController } = require('./index');
|
|
||||||
|
|
||||||
console.log('=== PID CONTROLLER EXAMPLES ===\n');
|
|
||||||
console.log('This guide shows how to instantiate, tune, and operate the PID helper.\n');
|
|
||||||
|
|
||||||
// ====================================
|
|
||||||
// EXAMPLE 1: FLOW CONTROL LOOP
|
|
||||||
// ====================================
|
|
||||||
console.log('--- Example 1: Pump speed control ---');
|
|
||||||
|
|
||||||
const pumpController = new PIDController({
|
|
||||||
kp: 1.1,
|
|
||||||
ki: 0.35,
|
|
||||||
kd: 0.08,
|
|
||||||
sampleTime: 250, // ms
|
|
||||||
outputMin: 0,
|
|
||||||
outputMax: 100,
|
|
||||||
derivativeFilter: 0.2
|
|
||||||
});
|
|
||||||
|
|
||||||
const pumpSetpoint = 75; // desired flow percentage
|
|
||||||
let pumpFlow = 20;
|
|
||||||
const pumpStart = Date.now();
|
|
||||||
|
|
||||||
for (let i = 0; i < 10; i += 1) {
|
|
||||||
const timestamp = pumpStart + (i + 1) * pumpController.sampleTime;
|
|
||||||
const controlSignal = pumpController.update(pumpSetpoint, pumpFlow, timestamp);
|
|
||||||
|
|
||||||
// Simple first-order plant approximation
|
|
||||||
pumpFlow += (controlSignal - pumpFlow) * 0.12;
|
|
||||||
pumpFlow -= (pumpFlow - pumpSetpoint) * 0.05; // disturbance rejection
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Cycle ${i + 1}: output=${controlSignal.toFixed(2)}% | flow=${pumpFlow.toFixed(2)}%`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Pump loop state:', pumpController.getState(), '\n');
|
|
||||||
|
|
||||||
// ====================================
|
|
||||||
// EXAMPLE 2: TANK LEVEL WITH MANUAL/AUTO
|
|
||||||
// ====================================
|
|
||||||
console.log('--- Example 2: Tank level handover ---');
|
|
||||||
|
|
||||||
const tankController = new PIDController({
|
|
||||||
kp: 2.0,
|
|
||||||
ki: 0.5,
|
|
||||||
kd: 0.25,
|
|
||||||
sampleTime: 400,
|
|
||||||
derivativeFilter: 0.25,
|
|
||||||
outputMin: 0,
|
|
||||||
outputMax: 1
|
|
||||||
}).setIntegralLimits(-0.3, 0.3);
|
|
||||||
|
|
||||||
tankController.setMode('manual');
|
|
||||||
tankController.setManualOutput(0.4);
|
|
||||||
console.log(`Manual output locked at ${tankController.getLastOutput().toFixed(2)}\n`);
|
|
||||||
|
|
||||||
tankController.setMode('automatic');
|
|
||||||
|
|
||||||
let level = 0.2;
|
|
||||||
const levelSetpoint = 0.8;
|
|
||||||
const tankStart = Date.now();
|
|
||||||
|
|
||||||
for (let step = 0; step < 8; step += 1) {
|
|
||||||
const timestamp = tankStart + (step + 1) * tankController.sampleTime;
|
|
||||||
const output = tankController.update(levelSetpoint, level, timestamp);
|
|
||||||
|
|
||||||
// Integrating process with slight disturbance
|
|
||||||
level += (output - 0.5) * 0.18;
|
|
||||||
level += 0.02; // inflow bump
|
|
||||||
level = Math.max(0, Math.min(1, level));
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Cycle ${step + 1}: output=${output.toFixed(3)} | level=${level.toFixed(3)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\nBest practice tips:');
|
|
||||||
console.log(' - Call update() on a fixed interval (sampleTime).');
|
|
||||||
console.log(' - Clamp output and integral to avoid windup.');
|
|
||||||
console.log(' - Use setMode("manual") during maintenance or bump-less transfer.');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
pumpController,
|
|
||||||
tankController
|
|
||||||
};
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
const PIDController = require('./PIDController');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience factory for one-line instantiation.
|
|
||||||
*/
|
|
||||||
const createPidController = (options) => new PIDController(options);
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
PIDController,
|
|
||||||
createPidController
|
|
||||||
};
|
|
||||||
@@ -52,10 +52,6 @@ class state{
|
|||||||
return this.stateManager.getRunTimeHours();
|
return this.stateManager.getRunTimeHours();
|
||||||
}
|
}
|
||||||
|
|
||||||
getMaintenanceTimeHours(){
|
|
||||||
return this.stateManager.getMaintenanceTimeHours();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async moveTo(targetPosition) {
|
async moveTo(targetPosition) {
|
||||||
|
|
||||||
|
|||||||
@@ -205,10 +205,6 @@
|
|||||||
{
|
{
|
||||||
"value": "off",
|
"value": "off",
|
||||||
"description": "Machine is off."
|
"description": "Machine is off."
|
||||||
},
|
|
||||||
{
|
|
||||||
"value": "maintenance",
|
|
||||||
"description": "Machine locked for inspection or repair; automatic control disabled."
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Current state of the machine."
|
"description": "Current state of the machine."
|
||||||
@@ -220,7 +216,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"schema": {
|
"schema": {
|
||||||
"idle": {
|
"idle": {
|
||||||
"default": ["starting", "off","emergencystop","maintenance"],
|
"default": ["starting", "off","emergencystop"],
|
||||||
"rules":{
|
"rules":{
|
||||||
"type": "set",
|
"type": "set",
|
||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
@@ -284,7 +280,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"off": {
|
"off": {
|
||||||
"default": ["idle","emergencystop","maintenance"],
|
"default": ["idle","emergencystop"],
|
||||||
"rules":{
|
"rules":{
|
||||||
"type": "set",
|
"type": "set",
|
||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
@@ -292,20 +288,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"emergencystop": {
|
"emergencystop": {
|
||||||
"default": ["idle","off","maintenance"],
|
"default": ["idle","off"],
|
||||||
"rules":{
|
"rules":{
|
||||||
"type": "set",
|
"type": "set",
|
||||||
"itemType": "string",
|
"itemType": "string",
|
||||||
"description": "Allowed transitions from emergency stop state."
|
"description": "Allowed transitions from emergency stop state."
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"maintenance": {
|
|
||||||
"default": ["maintenance","idle","off"],
|
|
||||||
"rules":{
|
|
||||||
"type": "set",
|
|
||||||
"itemType": "string",
|
|
||||||
"description": "Allowed transitions for maintenance mode"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"description": "Allowed transitions between states."
|
"description": "Allowed transitions between states."
|
||||||
|
|||||||
@@ -48,14 +48,10 @@ class stateManager {
|
|||||||
// Define valid transitions (can be extended dynamically if needed)
|
// Define valid transitions (can be extended dynamically if needed)
|
||||||
this.validTransitions = config.state.allowedTransitions;
|
this.validTransitions = config.state.allowedTransitions;
|
||||||
|
|
||||||
//runtime tracking
|
// NEW: Initialize runtime tracking
|
||||||
this.runTimeHours = 0; // cumulative runtime in hours
|
this.runTimeHours = 0; // cumulative runtime in hours
|
||||||
this.runTimeStart = null; // timestamp when active state began
|
this.runTimeStart = null; // timestamp when active state began
|
||||||
|
|
||||||
//maintenance tracking
|
|
||||||
this.maintenanceTimeStart = null; //timestamp when active state began
|
|
||||||
this.maintenanceTimeHours = 0; //cumulative
|
|
||||||
|
|
||||||
// Define active states (runtime counts only in these states)
|
// Define active states (runtime counts only in these states)
|
||||||
this.activeStates = config.state.activeStates;
|
this.activeStates = config.state.activeStates;
|
||||||
}
|
}
|
||||||
@@ -77,9 +73,8 @@ class stateManager {
|
|||||||
); //go back early and reject promise
|
); //go back early and reject promise
|
||||||
}
|
}
|
||||||
|
|
||||||
//Time tracking based on active states
|
// NEW: Handle runtime tracking based on active states
|
||||||
this.handleRuntimeTracking(newState);
|
this.handleRuntimeTracking(newState);
|
||||||
this.handleMaintenancetimeTracking(newState);
|
|
||||||
|
|
||||||
const transitionDuration = this.transitionTimes[this.currentState] || 0; // Default to 0 if no transition time
|
const transitionDuration = this.transitionTimes[this.currentState] || 0; // Default to 0 if no transition time
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
@@ -105,7 +100,7 @@ class stateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleRuntimeTracking(newState) {
|
handleRuntimeTracking(newState) {
|
||||||
//Handle runtime tracking based on active states
|
// NEW: Handle runtime tracking based on active states
|
||||||
const wasActive = this.activeStates.has(this.currentState);
|
const wasActive = this.activeStates.has(this.currentState);
|
||||||
const willBeActive = this.activeStates.has(newState);
|
const willBeActive = this.activeStates.has(newState);
|
||||||
if (wasActive && !willBeActive && this.runTimeStart) {
|
if (wasActive && !willBeActive && this.runTimeStart) {
|
||||||
@@ -125,28 +120,6 @@ class stateManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMaintenancetimeTracking(newState) {
|
|
||||||
//is this maintenance time ?
|
|
||||||
const wasActive = (this.currentState == "maintenance"? true:false);
|
|
||||||
const willBeActive = ( newState == "maintenance" ? true:false );
|
|
||||||
|
|
||||||
if (wasActive && this.maintenanceTimeStart) {
|
|
||||||
// stop runtime timer and accumulate elapsed time
|
|
||||||
const elapsed = (Date.now() - this.maintenanceTimeStart) / 3600000; // hours
|
|
||||||
this.maintenanceTimeHours += elapsed;
|
|
||||||
this.maintenanceTimeStart = null;
|
|
||||||
this.logger.debug(
|
|
||||||
`Maintenance timer stopped; elapsed=${elapsed.toFixed(
|
|
||||||
3
|
|
||||||
)}h, total=${this.maintenanceTimeHours.toFixed(3)}h.`
|
|
||||||
);
|
|
||||||
} else if (willBeActive && !this.runTimeStart) {
|
|
||||||
// starting new runtime
|
|
||||||
this.maintenanceTimeStart = Date.now();
|
|
||||||
this.logger.debug("Runtime timer started.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isValidTransition(newState) {
|
isValidTransition(newState) {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Check 1 Transition valid ? From ${
|
`Check 1 Transition valid ? From ${
|
||||||
@@ -177,6 +150,7 @@ class stateManager {
|
|||||||
return this.descriptions[state] || "No description available.";
|
return this.descriptions[state] || "No description available.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NEW: Getter to retrieve current cumulative runtime (active time) in hours.
|
||||||
getRunTimeHours() {
|
getRunTimeHours() {
|
||||||
// If currently active add the ongoing duration.
|
// If currently active add the ongoing duration.
|
||||||
let currentElapsed = 0;
|
let currentElapsed = 0;
|
||||||
@@ -185,15 +159,6 @@ class stateManager {
|
|||||||
}
|
}
|
||||||
return this.runTimeHours + currentElapsed;
|
return this.runTimeHours + currentElapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMaintenanceTimeHours() {
|
|
||||||
// If currently active add the ongoing duration.
|
|
||||||
let currentElapsed = 0;
|
|
||||||
if (this.maintenanceTimeStart) {
|
|
||||||
currentElapsed = (Date.now() - this.maintenanceTimeStart) / 3600000;
|
|
||||||
}
|
|
||||||
return this.maintenanceTimeHours + currentElapsed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = stateManager;
|
module.exports = stateManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user