Compare commits
8 Commits
main
...
59ff4d230e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59ff4d230e | ||
|
|
53c25f2d10 | ||
|
|
8540328bf5 | ||
|
|
133d442b76 | ||
|
|
0038a8c2c2 | ||
|
|
2aa7f88f03 | ||
|
|
2a82b7d7dc | ||
|
|
2a6a0bc34b |
49
CONTRACT.md
Normal file
49
CONTRACT.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# monster — Contract
|
||||
|
||||
Hand-maintained for Phase 6; the `## Inputs` table is generated from
|
||||
`src/commands/index.js` (see Phase 9 generator). Keep ≤ 80 lines.
|
||||
|
||||
## Inputs (msg.topic on Port 0)
|
||||
|
||||
| Canonical | Aliases (deprecated) | Payload | Effect |
|
||||
|---|---|---|---|
|
||||
| `cmd.start` | `i_start` | truthy/falsy | Sets `source.i_start`. On the next tick a sampling run begins if flow bounds validate. |
|
||||
| `set.schedule` | `monsternametijden` | array of AQUON rows (`SAMPLE_NAME`, `DESCRIPTION`, `SAMPLED_DATE`, `START_DATE`, `END_DATE`) | Stores the schedule and recomputes `nextDate` + `daysPerYear` for the configured `aquonSampleName`. |
|
||||
| `set.rain` | `rain_data` | per-location rain forecast (Open-Meteo shape) | Aggregates hourly precipitation into `sumRain` / `avgRain`; feeds the rain-scaled flow prediction. |
|
||||
| `data.flow` | `input_q` | `{ value: number, unit: string }` | Converts to m³/h and pushes into `flow.manual.atequipment`. Blends with measured-child flow in `getEffectiveFlow()`. |
|
||||
| `set.mode` | `setMode` | string | Delegated to `source.setMode()` if defined. Reserved for future use. |
|
||||
| `set.model-prediction` | `model_prediction` | numeric | Delegated to `source.setModelPrediction()` if defined. Reserved for future use. |
|
||||
|
||||
Aliases log a one-time deprecation warning the first time they fire.
|
||||
|
||||
## Outputs (msg.topic on Port 0/1/2)
|
||||
|
||||
- **Port 0 (process):** `msg.topic = config.general.name`. Payload built
|
||||
by `outputUtils.formatMsg(..., 'process')` from `getOutput()`. Delta-
|
||||
compressed — only changed fields are emitted. Carries `pulse`, `running`,
|
||||
`bucketVol`, `sumPuls`, `predFlow`, `m3PerPuls`, `q`, `timeLeft`,
|
||||
`targetVolumeM3`, `targetProgressPct`, `targetDeltaL`, `predictedRateM3h`,
|
||||
`sumRain`, `avgRain`, `nextDate`, plus the flat measurements snapshot.
|
||||
- **Port 1 (InfluxDB telemetry):** same shape as Port 0, formatted with the
|
||||
`'influxdb'` formatter.
|
||||
- **Port 2 (registration):** at startup the node sends one
|
||||
`{ topic: 'child.register', payload: <node.id>, positionVsParent, distance }`
|
||||
to its parent.
|
||||
|
||||
## Events emitted by `source.measurements.emitter`
|
||||
|
||||
The `MeasurementContainer` fires `<type>.measured.<position>` whenever a
|
||||
matching series receives a new value. monster writes:
|
||||
|
||||
- `flow.manual.atequipment` — operator-supplied manual flow.
|
||||
- `flow.measured.<position>` — re-emitted when a child measurement fires
|
||||
(one of `flow.measured.upstream`, `flow.measured.downstream`,
|
||||
`flow.measured.atequipment`).
|
||||
|
||||
## Children accepted
|
||||
|
||||
`measurement` only. The router subscribes to a child's
|
||||
`flow.measured.<position>` events when the child's `config.asset.type` is
|
||||
`'flow'` (or missing). Other asset types are ignored. monster has no
|
||||
position-based filtering — all three positions are wired and the latest
|
||||
value wins for each.
|
||||
1202
examples/02-integrated-e2e.json
Normal file
1202
examples/02-integrated-e2e.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +0,0 @@
|
||||
[
|
||||
{"id":"monster_edge_tab","type":"tab","label":"monster edge","disabled":false,"info":"monster edge example"},
|
||||
{"id":"monster_edge_node","type":"monster","z":"monster_edge_tab","name":"monster edge","x":420,"y":180,"wires":[["monster_edge_dbg"]]},
|
||||
{"id":"monster_edge_inj","type":"inject","z":"monster_edge_tab","name":"unknown topic","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"doesNotExist","payload":"x","payloadType":"str","x":170,"y":180,"wires":[["monster_edge_node"]]},
|
||||
{"id":"monster_edge_dbg","type":"debug","z":"monster_edge_tab","name":"monster edge debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":180,"wires":[]}
|
||||
]
|
||||
@@ -1,6 +0,0 @@
|
||||
[
|
||||
{"id":"monster_int_tab","type":"tab","label":"monster integration","disabled":false,"info":"monster integration example"},
|
||||
{"id":"monster_int_node","type":"monster","z":"monster_int_tab","name":"monster integration","x":420,"y":180,"wires":[["monster_int_dbg"]]},
|
||||
{"id":"monster_int_inj","type":"inject","z":"monster_int_tab","name":"registerChild","props":[{"p":"topic","vt":"str"},{"p":"payload","vt":"str"}],"topic":"registerChild","payload":"example-child-id","payloadType":"str","x":170,"y":180,"wires":[["monster_int_node"]]},
|
||||
{"id":"monster_int_dbg","type":"debug","z":"monster_int_tab","name":"monster integration debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":680,"y":180,"wires":[]}
|
||||
]
|
||||
@@ -1,743 +0,0 @@
|
||||
[
|
||||
{
|
||||
"id": "monster_api_tab",
|
||||
"type": "tab",
|
||||
"label": "Monster API + Dashboard",
|
||||
"disabled": false,
|
||||
"info": "Full monster orchestration example with API integrations. Credentials are placeholders."
|
||||
},
|
||||
{
|
||||
"id": "ui_base_monster_api",
|
||||
"type": "ui-base",
|
||||
"name": "EVOLV Demo",
|
||||
"path": "/dashboard",
|
||||
"appIcon": "",
|
||||
"includeClientData": true,
|
||||
"acceptsClientConfig": [
|
||||
"ui-notification",
|
||||
"ui-control"
|
||||
],
|
||||
"showPathInSidebar": false,
|
||||
"headerContent": "page",
|
||||
"navigationStyle": "default",
|
||||
"titleBarStyle": "default"
|
||||
},
|
||||
{
|
||||
"id": "ui_theme_monster_api",
|
||||
"type": "ui-theme",
|
||||
"name": "Monster API Theme",
|
||||
"colors": {
|
||||
"surface": "#ffffff",
|
||||
"primary": "#4f8582",
|
||||
"bgPage": "#efefef",
|
||||
"groupBg": "#ffffff",
|
||||
"groupOutline": "#d8d8d8"
|
||||
},
|
||||
"sizes": {
|
||||
"density": "default",
|
||||
"pagePadding": "14px",
|
||||
"groupGap": "14px",
|
||||
"groupBorderRadius": "6px",
|
||||
"widgetGap": "12px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ui_page_monster_api",
|
||||
"type": "ui-page",
|
||||
"name": "Monster API",
|
||||
"ui": "ui_base_monster_api",
|
||||
"path": "/monster-api",
|
||||
"icon": "science",
|
||||
"layout": "grid",
|
||||
"theme": "ui_theme_monster_api",
|
||||
"breakpoints": [
|
||||
{
|
||||
"name": "Default",
|
||||
"px": "0",
|
||||
"cols": "12"
|
||||
}
|
||||
],
|
||||
"order": 1,
|
||||
"className": ""
|
||||
},
|
||||
{
|
||||
"id": "ui_group_monster_api_ctrl",
|
||||
"type": "ui-group",
|
||||
"name": "Input",
|
||||
"page": "ui_page_monster_api",
|
||||
"width": "6",
|
||||
"height": "1",
|
||||
"order": 1,
|
||||
"showTitle": true,
|
||||
"className": ""
|
||||
},
|
||||
{
|
||||
"id": "ui_group_monster_api_obs",
|
||||
"type": "ui-group",
|
||||
"name": "Output",
|
||||
"page": "ui_page_monster_api",
|
||||
"width": "12",
|
||||
"height": "1",
|
||||
"order": 2,
|
||||
"showTitle": true,
|
||||
"className": ""
|
||||
},
|
||||
{
|
||||
"id": "monster_api_node",
|
||||
"type": "monster",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Monster API",
|
||||
"samplingtime": "24",
|
||||
"minvolume": "5",
|
||||
"maxweight": "23",
|
||||
"nominalFlowMin": "1000",
|
||||
"flowMax": "6000",
|
||||
"maxRainRef": "10",
|
||||
"minSampleIntervalSec": "60",
|
||||
"emptyWeightBucket": "8.3",
|
||||
"aquon_sample_name": "112150",
|
||||
"enableLog": false,
|
||||
"logLevel": "error",
|
||||
"positionVsParent": "atEquipment",
|
||||
"positionIcon": "⊥",
|
||||
"hasDistance": false,
|
||||
"distance": "",
|
||||
"x": 980,
|
||||
"y": 320,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_parse_output",
|
||||
"monster_api_zinfo_prepare"
|
||||
],
|
||||
[
|
||||
"monster_api_dbg_influx"
|
||||
],
|
||||
[
|
||||
"monster_api_dbg_parent"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_info",
|
||||
"type": "comment",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Template only: set credentials/URLs before production",
|
||||
"info": "All secrets in this flow are placeholders. Replace with env vars or credential nodes.",
|
||||
"x": 260,
|
||||
"y": 80,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_inj_flow",
|
||||
"type": "inject",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_ctrl",
|
||||
"name": "Flow 1800 m3/h",
|
||||
"props": [
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "5",
|
||||
"crontab": "",
|
||||
"once": true,
|
||||
"onceDelay": "1",
|
||||
"topic": "",
|
||||
"payload": "1800",
|
||||
"payloadType": "num",
|
||||
"x": 170,
|
||||
"y": 180,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_build_flow"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_build_flow",
|
||||
"type": "function",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Build input_q",
|
||||
"func": "msg.topic='input_q';\nmsg.payload={value:Number(msg.payload),unit:'m3/h'};\nreturn Number.isFinite(msg.payload.value)?msg:null;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 390,
|
||||
"y": 180,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_node"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_inj_start",
|
||||
"type": "inject",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_ctrl",
|
||||
"name": "Manual Start",
|
||||
"props": [
|
||||
{
|
||||
"p": "topic",
|
||||
"vt": "str"
|
||||
},
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": false,
|
||||
"onceDelay": "0.1",
|
||||
"topic": "i_start",
|
||||
"payload": "true",
|
||||
"payloadType": "bool",
|
||||
"x": 160,
|
||||
"y": 240,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_node"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_weather_trigger",
|
||||
"type": "inject",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Weather fetch (daily)",
|
||||
"props": [
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "",
|
||||
"crontab": "55 07 * * *",
|
||||
"once": false,
|
||||
"onceDelay": "",
|
||||
"topic": "",
|
||||
"payload": "",
|
||||
"payloadType": "date",
|
||||
"x": 190,
|
||||
"y": 420,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_weather_http"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_weather_http",
|
||||
"type": "http request",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Open-Meteo",
|
||||
"method": "GET",
|
||||
"ret": "txt",
|
||||
"paytoqs": "ignore",
|
||||
"url": "https://api.open-meteo.com/v1/forecast?latitude=51.71&longitude=4.81&hourly=precipitation,precipitation_probability&timezone=Europe%2FBerlin&past_days=1&forecast_days=2",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"insecureHTTPParser": false,
|
||||
"authType": "",
|
||||
"senderr": false,
|
||||
"headers": [],
|
||||
"x": 380,
|
||||
"y": 420,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_weather_json"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_weather_json",
|
||||
"type": "json",
|
||||
"z": "monster_api_tab",
|
||||
"name": "rain_data",
|
||||
"property": "payload",
|
||||
"action": "",
|
||||
"pretty": false,
|
||||
"x": 550,
|
||||
"y": 420,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_weather_topic"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_weather_topic",
|
||||
"type": "change",
|
||||
"z": "monster_api_tab",
|
||||
"name": "topic rain_data",
|
||||
"rules": [
|
||||
{
|
||||
"t": "set",
|
||||
"p": "topic",
|
||||
"pt": "msg",
|
||||
"to": "rain_data",
|
||||
"tot": "str"
|
||||
}
|
||||
],
|
||||
"x": 720,
|
||||
"y": 420,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_node"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_aquon_trigger",
|
||||
"type": "inject",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Aquon fetch (daily)",
|
||||
"props": [
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "",
|
||||
"crontab": "15 07 * * *",
|
||||
"once": false,
|
||||
"onceDelay": "",
|
||||
"topic": "",
|
||||
"payload": "",
|
||||
"payloadType": "date",
|
||||
"x": 180,
|
||||
"y": 500,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_sftp_get"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_sftp_get",
|
||||
"type": "sftp in",
|
||||
"z": "monster_api_tab",
|
||||
"sftp": "monster_api_sftp_cfg",
|
||||
"operation": "get",
|
||||
"filename": "wsBD_MONSTERNAMETIJDEN.csv",
|
||||
"localFilename": "./.node-red/node_modules/typicals/monster/config/monsternametijden.csv",
|
||||
"name": "Aquon schedule",
|
||||
"x": 380,
|
||||
"y": 500,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_file_in"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_file_in",
|
||||
"type": "file in",
|
||||
"z": "monster_api_tab",
|
||||
"name": "read monsternametijden",
|
||||
"filename": "./.node-red/node_modules/typicals/monster/config/monsternametijden.csv",
|
||||
"filenameType": "str",
|
||||
"format": "utf8",
|
||||
"chunk": false,
|
||||
"sendError": false,
|
||||
"encoding": "none",
|
||||
"allProps": false,
|
||||
"x": 590,
|
||||
"y": 500,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_csv"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_csv",
|
||||
"type": "csv",
|
||||
"z": "monster_api_tab",
|
||||
"name": "monsternametijden",
|
||||
"sep": ",",
|
||||
"hdrin": true,
|
||||
"hdrout": "all",
|
||||
"multi": "mult",
|
||||
"ret": "\\n",
|
||||
"temp": "SAMPLE_NAME,DESCRIPTION,SAMPLED_DATE,START_DATE,END_DATE",
|
||||
"skip": "0",
|
||||
"strings": true,
|
||||
"include_empty_strings": "",
|
||||
"include_null_values": "",
|
||||
"x": 780,
|
||||
"y": 500,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_schedule_topic"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_schedule_topic",
|
||||
"type": "change",
|
||||
"z": "monster_api_tab",
|
||||
"name": "topic monsternametijden",
|
||||
"rules": [
|
||||
{
|
||||
"t": "set",
|
||||
"p": "topic",
|
||||
"pt": "msg",
|
||||
"to": "monsternametijden",
|
||||
"tot": "str"
|
||||
}
|
||||
],
|
||||
"x": 990,
|
||||
"y": 500,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_node"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_zinfo_prepare",
|
||||
"type": "function",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Z-Info prepare on run stop",
|
||||
"func": "const p=(msg&&msg.payload&&typeof msg.payload==='object')?msg.payload:{};\nconst runningNow=Boolean(p.running);\nconst runningPrev=Boolean(context.get('runningPrev'));\ncontext.set('runningPrev',runningNow);\nif(!(runningPrev && !runningNow)){\n return null;\n}\nconst today=new Date();\nconst day=String(today.getDate()).padStart(2,'0');\nconst month=String(today.getMonth()+1).padStart(2,'0');\nconst year=today.getFullYear();\nconst yesterdayDate=new Date(today.getTime()-24*3600*1000);\nconst yDay=String(yesterdayDate.getDate()).padStart(2,'0');\nconst yMonth=String(yesterdayDate.getMonth()+1).padStart(2,'0');\nconst yYear=yesterdayDate.getFullYear();\nmsg.zinfoDateFrom=`${yYear}-${yMonth}-${yDay}`;\nmsg.zinfoDateUntil=`${year}-${month}-${day}`;\nmsg.zinfoData={\n m3Total:Number(p.m3Total||0),\n pulse:Math.max(0,Math.floor(Number(p.m3PerPuls||p.m3PerPulse||0)))\n};\nmsg.payload='grant_type=password&username=__SET_ZINFO_USERNAME__&password=__SET_ZINFO_PASSWORD__&client_id=__SET_ZINFO_CLIENT_ID__&client_secret=__SET_ZINFO_CLIENT_SECRET__';\nmsg.headers=msg.headers||{};\nmsg.headers['content-type']='application/x-www-form-urlencoded';\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1260,
|
||||
"y": 320,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_zinfo_token"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_zinfo_token",
|
||||
"type": "http request",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Z-Info token",
|
||||
"method": "POST",
|
||||
"ret": "txt",
|
||||
"paytoqs": "ignore",
|
||||
"url": "https://__SET_ZINFO_HOST__/WSR/zi_wsr.svc/token",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"insecureHTTPParser": false,
|
||||
"authType": "",
|
||||
"senderr": false,
|
||||
"headers": [],
|
||||
"x": 1450,
|
||||
"y": 320,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_zinfo_token_json"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_zinfo_token_json",
|
||||
"type": "json",
|
||||
"z": "monster_api_tab",
|
||||
"name": "token json",
|
||||
"property": "payload",
|
||||
"action": "",
|
||||
"pretty": false,
|
||||
"x": 1630,
|
||||
"y": 320,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_zinfo_import_builder"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_zinfo_import_builder",
|
||||
"type": "function",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Build Z-Info import",
|
||||
"func": "const token=msg.payload&&msg.payload.access_token;\nconst z=msg.zinfoData||{};\nconst from=msg.zinfoDateFrom;\nconst until=msg.zinfoDateUntil;\nconst ns='__SET_ZINFO_NAMESPACE__';\nmsg.payload={\n import:{\n algemeen:{\n AanleverendeOrganisatie:'NL.25',\n Versie:'IMm2018',\n Batchid:`ZI_PA_NL.25_${Date.now()}.json`,\n Systeembron:'WBD/NEERSG',\n Systeemdoel:'HWH/Z-info',\n Opmerking:'template'\n },\n data:[{\n Meetwaarden:[\n {mepid:`${ns}.F021.m3`,dbmDtm:from,dbmTijd:'06:00',demDtm:until,demTijd:'06:00',mwdWaarde:`${Number(z.m3Total||0)}`,mwdWaardeAN:'',nMwd:'',mwdOpmerk:'template'},\n {mepid:`${ns}.Q000.PULS`,dbmDtm:from,dbmTijd:'06:00',demDtm:until,demTijd:'06:00',mwdWaarde:`${Number(z.pulse||0)}`,mwdWaardeAN:'',nMwd:'',mwdOpmerk:'template'}\n ]\n }]\n }\n};\nmsg.headers=msg.headers||{};\nif(token){msg.headers.authorization='Bearer '+token;}\nmsg.headers['content-type']='application/json';\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 1830,
|
||||
"y": 320,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_zinfo_import_put"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_zinfo_import_put",
|
||||
"type": "http request",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Z-Info import PUT",
|
||||
"method": "PUT",
|
||||
"ret": "txt",
|
||||
"paytoqs": "ignore",
|
||||
"url": "https://__SET_ZINFO_HOST__/WSR/zi_wsr.svc/json/NL.25/importmwd/pa/?gebruiker=__SET_ZINFO_USER__",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"insecureHTTPParser": false,
|
||||
"authType": "",
|
||||
"senderr": false,
|
||||
"headers": [],
|
||||
"x": 2040,
|
||||
"y": 320,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_dbg_zinfo"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_dbg_zinfo",
|
||||
"type": "debug",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Z-Info response",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "false",
|
||||
"targetType": "full",
|
||||
"x": 2250,
|
||||
"y": 320,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_parse_output",
|
||||
"type": "function",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Parse output for dashboard",
|
||||
"func": "const p=(msg&&msg.payload&&typeof msg.payload==='object')?msg.payload:{};\nconst now=Date.now();\nconst m3PerPuls=Number(p.m3PerPuls||p.m3PerPulse);\nreturn [\n Number.isFinite(Number(p.q))?{topic:'q_m3h',payload:Number(p.q),timestamp:now}:null,\n Number.isFinite(Number(p.m3Total))?{topic:'m3_total',payload:Number(p.m3Total),timestamp:now}:null,\n Number.isFinite(Number(p.bucketVol))?{topic:'bucket_l',payload:Number(p.bucketVol),timestamp:now}:null,\n Number.isFinite(m3PerPuls)?{topic:'m3_per_pulse',payload:m3PerPuls,timestamp:now}:null,\n {topic:'status',payload:`running=${Boolean(p.running)} | pulse=${Boolean(p.pulse)} | m3PerPuls=${Number.isFinite(m3PerPuls)?m3PerPuls:'n/a'} | missed=${Number(p.missedSamples||0)}`}\n];",
|
||||
"outputs": 5,
|
||||
"noerr": 0,
|
||||
"x": 1240,
|
||||
"y": 220,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_chart_q"
|
||||
],
|
||||
[
|
||||
"monster_api_chart_total"
|
||||
],
|
||||
[
|
||||
"monster_api_chart_bucket"
|
||||
],
|
||||
[
|
||||
"monster_api_chart_pulse"
|
||||
],
|
||||
[
|
||||
"monster_api_text_status"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_chart_q",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_obs",
|
||||
"name": "q",
|
||||
"label": "Flow q (m3/h)",
|
||||
"order": 1,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisProperty": "payload",
|
||||
"yAxisPropertyType": "msg",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1470,
|
||||
"y": 120,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_chart_total",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_obs",
|
||||
"name": "m3Total",
|
||||
"label": "m3Total",
|
||||
"order": 2,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisProperty": "payload",
|
||||
"yAxisPropertyType": "msg",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1480,
|
||||
"y": 180,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_chart_bucket",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_obs",
|
||||
"name": "bucket",
|
||||
"label": "Bucket (L)",
|
||||
"order": 3,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisProperty": "payload",
|
||||
"yAxisPropertyType": "msg",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1480,
|
||||
"y": 240,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_chart_pulse",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_obs",
|
||||
"name": "m3PerPuls",
|
||||
"label": "m3PerPuls",
|
||||
"order": 4,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisProperty": "payload",
|
||||
"yAxisPropertyType": "msg",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1490,
|
||||
"y": 300,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_text_status",
|
||||
"type": "ui-text",
|
||||
"z": "monster_api_tab",
|
||||
"group": "ui_group_monster_api_obs",
|
||||
"name": "status",
|
||||
"label": "Status",
|
||||
"order": 5,
|
||||
"width": 12,
|
||||
"height": 1,
|
||||
"format": "{{msg.payload}}",
|
||||
"layout": "row-spread",
|
||||
"x": 1460,
|
||||
"y": 360,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_dashboardapi",
|
||||
"type": "dashboardapi",
|
||||
"z": "monster_api_tab",
|
||||
"name": "dashboard template",
|
||||
"x": 1430,
|
||||
"y": 420,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_grafana_post"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_grafana_post",
|
||||
"type": "http request",
|
||||
"z": "monster_api_tab",
|
||||
"name": "Grafana dashboard API",
|
||||
"method": "POST",
|
||||
"ret": "txt",
|
||||
"paytoqs": "ignore",
|
||||
"url": "https://__SET_GRAFANA_HOST__/api/dashboards/db",
|
||||
"tls": "",
|
||||
"persist": false,
|
||||
"proxy": "",
|
||||
"insecureHTTPParser": false,
|
||||
"authType": "",
|
||||
"senderr": false,
|
||||
"headers": [],
|
||||
"x": 1650,
|
||||
"y": 420,
|
||||
"wires": [
|
||||
[
|
||||
"monster_api_dbg_dashboard"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_api_dbg_dashboard",
|
||||
"type": "debug",
|
||||
"z": "monster_api_tab",
|
||||
"name": "dashboard API response",
|
||||
"active": false,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "false",
|
||||
"targetType": "full",
|
||||
"x": 1870,
|
||||
"y": 420,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_dbg_influx",
|
||||
"type": "debug",
|
||||
"z": "monster_api_tab",
|
||||
"name": "influx output",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "true",
|
||||
"targetType": "full",
|
||||
"x": 1240,
|
||||
"y": 460,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_dbg_parent",
|
||||
"type": "debug",
|
||||
"z": "monster_api_tab",
|
||||
"name": "parent output",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "true",
|
||||
"targetType": "full",
|
||||
"x": 1230,
|
||||
"y": 500,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_api_sftp_cfg",
|
||||
"type": "sftp",
|
||||
"host": "__SET_AQUON_SFTP_HOST__",
|
||||
"port": "22",
|
||||
"username": "__SET_AQUON_SFTP_USERNAME__",
|
||||
"password": "__SET_AQUON_SFTP_PASSWORD__",
|
||||
"hmac": [],
|
||||
"cipher": []
|
||||
}
|
||||
]
|
||||
@@ -1,483 +0,0 @@
|
||||
[
|
||||
{
|
||||
"id": "monster_tab_demo",
|
||||
"type": "tab",
|
||||
"label": "Monster Dashboard Demo",
|
||||
"disabled": false,
|
||||
"info": "Dashboard-focused example for monster output visualization"
|
||||
},
|
||||
{
|
||||
"id": "ui_base_monster_demo",
|
||||
"type": "ui-base",
|
||||
"name": "EVOLV Demo",
|
||||
"path": "/dashboard",
|
||||
"appIcon": "",
|
||||
"includeClientData": true,
|
||||
"acceptsClientConfig": [
|
||||
"ui-notification",
|
||||
"ui-control"
|
||||
],
|
||||
"showPathInSidebar": false,
|
||||
"headerContent": "page",
|
||||
"navigationStyle": "default",
|
||||
"titleBarStyle": "default"
|
||||
},
|
||||
{
|
||||
"id": "ui_theme_monster_demo",
|
||||
"type": "ui-theme",
|
||||
"name": "EVOLV Monster Theme",
|
||||
"colors": {
|
||||
"surface": "#ffffff",
|
||||
"primary": "#4f8582",
|
||||
"bgPage": "#efefef",
|
||||
"groupBg": "#ffffff",
|
||||
"groupOutline": "#d8d8d8"
|
||||
},
|
||||
"sizes": {
|
||||
"density": "default",
|
||||
"pagePadding": "14px",
|
||||
"groupGap": "14px",
|
||||
"groupBorderRadius": "6px",
|
||||
"widgetGap": "12px"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ui_page_monster_demo",
|
||||
"type": "ui-page",
|
||||
"name": "Monster Demo",
|
||||
"ui": "ui_base_monster_demo",
|
||||
"path": "/monster-demo",
|
||||
"icon": "science",
|
||||
"layout": "grid",
|
||||
"theme": "ui_theme_monster_demo",
|
||||
"breakpoints": [
|
||||
{
|
||||
"name": "Default",
|
||||
"px": "0",
|
||||
"cols": "12"
|
||||
}
|
||||
],
|
||||
"order": 1,
|
||||
"className": ""
|
||||
},
|
||||
{
|
||||
"id": "ui_group_monster_ctrl",
|
||||
"type": "ui-group",
|
||||
"name": "Monster Inputs",
|
||||
"page": "ui_page_monster_demo",
|
||||
"width": "6",
|
||||
"height": "1",
|
||||
"order": 1,
|
||||
"showTitle": true,
|
||||
"className": ""
|
||||
},
|
||||
{
|
||||
"id": "ui_group_monster_obs",
|
||||
"type": "ui-group",
|
||||
"name": "Monster Output",
|
||||
"page": "ui_page_monster_demo",
|
||||
"width": "12",
|
||||
"height": "1",
|
||||
"order": 2,
|
||||
"showTitle": true,
|
||||
"className": ""
|
||||
},
|
||||
{
|
||||
"id": "monster_node_demo",
|
||||
"type": "monster",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Monster Demo",
|
||||
"samplingtime": "24",
|
||||
"minvolume": "5",
|
||||
"maxweight": "23",
|
||||
"nominalFlowMin": "1000",
|
||||
"flowMax": "6000",
|
||||
"maxRainRef": "10",
|
||||
"minSampleIntervalSec": "60",
|
||||
"emptyWeightBucket": "8.3",
|
||||
"aquon_sample_name": "112150",
|
||||
"uuid": "",
|
||||
"supplier": "monster",
|
||||
"category": "monster",
|
||||
"assetType": "sampling-cabinet",
|
||||
"model": "monster-standard",
|
||||
"unit": "m3/h",
|
||||
"enableLog": false,
|
||||
"logLevel": "error",
|
||||
"positionVsParent": "atEquipment",
|
||||
"positionIcon": "⊥",
|
||||
"hasDistance": false,
|
||||
"distance": "",
|
||||
"x": 900,
|
||||
"y": 260,
|
||||
"wires": [
|
||||
[
|
||||
"monster_parse_output"
|
||||
],
|
||||
[
|
||||
"monster_debug_influx"
|
||||
],
|
||||
[
|
||||
"monster_debug_parent"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_flow_inject",
|
||||
"type": "inject",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_ctrl",
|
||||
"name": "Flow 1800 m3/h",
|
||||
"props": [
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "5",
|
||||
"crontab": "",
|
||||
"once": true,
|
||||
"onceDelay": "1",
|
||||
"topic": "",
|
||||
"payload": "1800",
|
||||
"payloadType": "num",
|
||||
"x": 170,
|
||||
"y": 180,
|
||||
"wires": [
|
||||
[
|
||||
"monster_build_flow"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_build_flow",
|
||||
"type": "function",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Build input_q",
|
||||
"func": "msg.topic = 'input_q';\nmsg.payload = { value: Number(msg.payload), unit: 'm3/h' };\nreturn Number.isFinite(msg.payload.value) ? msg : null;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 380,
|
||||
"y": 180,
|
||||
"wires": [
|
||||
[
|
||||
"monster_node_demo"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_start_inject",
|
||||
"type": "inject",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_ctrl",
|
||||
"name": "Manual Start",
|
||||
"props": [
|
||||
{
|
||||
"p": "topic",
|
||||
"vt": "str"
|
||||
},
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": false,
|
||||
"onceDelay": "0.1",
|
||||
"topic": "i_start",
|
||||
"payload": "true",
|
||||
"payloadType": "bool",
|
||||
"x": 160,
|
||||
"y": 240,
|
||||
"wires": [
|
||||
[
|
||||
"monster_node_demo"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_rain_inject",
|
||||
"type": "inject",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_ctrl",
|
||||
"name": "Seed rain_data",
|
||||
"props": [
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": true,
|
||||
"onceDelay": "2",
|
||||
"topic": "",
|
||||
"payload": "",
|
||||
"payloadType": "date",
|
||||
"x": 160,
|
||||
"y": 300,
|
||||
"wires": [
|
||||
[
|
||||
"monster_build_rain"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_build_rain",
|
||||
"type": "function",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Build rain_data",
|
||||
"func": "const now = new Date();\nconst mk = (offset, rain, prob) => {\n const d = new Date(now.getTime() + offset * 3600 * 1000);\n return { t: d.toISOString().slice(0, 13) + ':00', rain, prob };\n};\nconst rows = [mk(-1, 0.2, 20), mk(0, 0.8, 40), mk(1, 1.1, 60), mk(2, 0.5, 30)];\nmsg.topic = 'rain_data';\nmsg.payload = [\n {\n latitude: 51.71,\n longitude: 4.81,\n hourly: {\n time: rows.map(r => r.t),\n precipitation: rows.map(r => r.rain),\n precipitation_probability: rows.map(r => r.prob)\n }\n }\n];\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 380,
|
||||
"y": 300,
|
||||
"wires": [
|
||||
[
|
||||
"monster_node_demo"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_schedule_inject",
|
||||
"type": "inject",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_ctrl",
|
||||
"name": "Seed monsternametijden",
|
||||
"props": [
|
||||
{
|
||||
"p": "payload"
|
||||
}
|
||||
],
|
||||
"repeat": "",
|
||||
"crontab": "",
|
||||
"once": true,
|
||||
"onceDelay": "3",
|
||||
"topic": "",
|
||||
"payload": "",
|
||||
"payloadType": "date",
|
||||
"x": 190,
|
||||
"y": 360,
|
||||
"wires": [
|
||||
[
|
||||
"monster_build_schedule"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_build_schedule",
|
||||
"type": "function",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Build monsternametijden",
|
||||
"func": "const now = new Date();\nconst next = new Date(now.getTime() + 24 * 3600 * 1000);\nconst end = new Date(next.getTime() + 24 * 3600 * 1000);\nmsg.topic = 'monsternametijden';\nmsg.payload = [\n {\n SAMPLE_NAME: '112150',\n DESCRIPTION: 'demo schedule',\n SAMPLED_DATE: next.toISOString().slice(0, 19).replace('T', ' '),\n START_DATE: next.toISOString().slice(0, 19).replace('T', ' '),\n END_DATE: end.toISOString().slice(0, 19).replace('T', ' ')\n }\n];\nreturn msg;",
|
||||
"outputs": 1,
|
||||
"noerr": 0,
|
||||
"x": 410,
|
||||
"y": 360,
|
||||
"wires": [
|
||||
[
|
||||
"monster_node_demo"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_parse_output",
|
||||
"type": "function",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Parse monster output",
|
||||
"func": "const p = (msg && msg.payload && typeof msg.payload === 'object') ? msg.payload : {};\nconst now = Date.now();\nconst q = Number(p.q);\nconst total = Number(p.m3Total);\nconst bucket = Number(p.bucketVol);\nconst rem = Number(p.pulsesRemaining);\nconst m3PerPulse = Number(p.m3PerPuls || p.m3PerPulse);\nconst status = `running=${Boolean(p.running)} | pulse=${Boolean(p.pulse)} | m3PerPuls=${Number.isFinite(m3PerPulse) ? m3PerPulse : 'n/a'} | missed=${Number(p.missedSamples || 0)}`;\nreturn [\n Number.isFinite(q) ? { topic: 'q_m3h', payload: q, timestamp: now } : null,\n Number.isFinite(total) ? { topic: 'm3_total', payload: total, timestamp: now } : null,\n Number.isFinite(bucket) ? { topic: 'bucket_l', payload: bucket, timestamp: now } : null,\n Number.isFinite(rem) ? { topic: 'pulses_remaining', payload: rem, timestamp: now } : null,\n Number.isFinite(m3PerPulse) ? { topic: 'm3_per_pulse', payload: m3PerPulse, timestamp: now } : null,\n { topic: 'status', payload: status }\n];",
|
||||
"outputs": 6,
|
||||
"noerr": 0,
|
||||
"x": 1130,
|
||||
"y": 260,
|
||||
"wires": [
|
||||
[
|
||||
"monster_chart_q"
|
||||
],
|
||||
[
|
||||
"monster_chart_m3total"
|
||||
],
|
||||
[
|
||||
"monster_chart_bucket"
|
||||
],
|
||||
[
|
||||
"monster_chart_remaining"
|
||||
],
|
||||
[
|
||||
"monster_chart_m3pulse"
|
||||
],
|
||||
[
|
||||
"monster_text_status"
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "monster_chart_q",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_obs",
|
||||
"name": "Flow q",
|
||||
"label": "Flow q (m3/h)",
|
||||
"order": 1,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisPropertyType": "msg",
|
||||
"yAxisProperty": "payload",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1370,
|
||||
"y": 120,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_chart_m3total",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_obs",
|
||||
"name": "m3 Total",
|
||||
"label": "m3Total (m3)",
|
||||
"order": 2,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisPropertyType": "msg",
|
||||
"yAxisProperty": "payload",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1380,
|
||||
"y": 180,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_chart_bucket",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_obs",
|
||||
"name": "Bucket Volume",
|
||||
"label": "Bucket (L)",
|
||||
"order": 3,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisPropertyType": "msg",
|
||||
"yAxisProperty": "payload",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1380,
|
||||
"y": 240,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_chart_remaining",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_obs",
|
||||
"name": "Pulses Remaining",
|
||||
"label": "Pulses Remaining",
|
||||
"order": 4,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisPropertyType": "msg",
|
||||
"yAxisProperty": "payload",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1400,
|
||||
"y": 300,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_chart_m3pulse",
|
||||
"type": "ui-chart",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_obs",
|
||||
"name": "m3 per pulse",
|
||||
"label": "m3PerPuls",
|
||||
"order": 5,
|
||||
"width": 6,
|
||||
"height": 4,
|
||||
"chartType": "line",
|
||||
"category": "topic",
|
||||
"categoryType": "msg",
|
||||
"xAxisType": "time",
|
||||
"xAxisPropertyType": "timestamp",
|
||||
"yAxisPropertyType": "msg",
|
||||
"yAxisProperty": "payload",
|
||||
"removeOlder": "30",
|
||||
"removeOlderUnit": "60",
|
||||
"showLegend": false,
|
||||
"action": "append",
|
||||
"x": 1390,
|
||||
"y": 360,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_text_status",
|
||||
"type": "ui-text",
|
||||
"z": "monster_tab_demo",
|
||||
"group": "ui_group_monster_obs",
|
||||
"name": "Sampling status",
|
||||
"label": "Status",
|
||||
"order": 6,
|
||||
"width": 12,
|
||||
"height": 1,
|
||||
"format": "{{msg.payload}}",
|
||||
"layout": "row-spread",
|
||||
"x": 1380,
|
||||
"y": 420,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_debug_influx",
|
||||
"type": "debug",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Influx output",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "true",
|
||||
"targetType": "full",
|
||||
"x": 1130,
|
||||
"y": 320,
|
||||
"wires": []
|
||||
},
|
||||
{
|
||||
"id": "monster_debug_parent",
|
||||
"type": "debug",
|
||||
"z": "monster_tab_demo",
|
||||
"name": "Parent output",
|
||||
"active": true,
|
||||
"tosidebar": true,
|
||||
"console": false,
|
||||
"tostatus": false,
|
||||
"complete": "true",
|
||||
"targetType": "full",
|
||||
"x": 1130,
|
||||
"y": 360,
|
||||
"wires": []
|
||||
}
|
||||
]
|
||||
@@ -4,7 +4,10 @@
|
||||
"description": "Control module Monsternamekast",
|
||||
"main": "monster.js",
|
||||
"scripts": {
|
||||
"test": "node --test test/basic/*.test.js test/integration/*.test.js test/edge/*.test.js"
|
||||
"test": "node --test test/basic/*.test.js test/integration/*.test.js test/edge/*.test.js",
|
||||
"wiki:contract": "node ../generalFunctions/scripts/wikiGen.js contract ./src/commands/index.js --write ./wiki/Home.md",
|
||||
"wiki:datamodel": "node ../generalFunctions/scripts/wikiGen.js datamodel ./src/specificClass.js --write ./wiki/Home.md",
|
||||
"wiki:all": "npm run wiki:contract && npm run wiki:datamodel"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
54
src/commands/handlers.js
Normal file
54
src/commands/handlers.js
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
// Handlers for monster input topics. Each is a pure function over the
|
||||
// domain (source). Unit conversion for incoming flow happens in the
|
||||
// handler (the legacy nodeClass did it inline) — anything else inbound
|
||||
// is passed straight through to source.handleInput.
|
||||
|
||||
const { convert } = require('generalFunctions');
|
||||
|
||||
exports.cmdStart = (source, msg) => {
|
||||
source.handleInput('i_start', Boolean(msg.payload));
|
||||
};
|
||||
|
||||
exports.setSchedule = (source, msg) => {
|
||||
source.handleInput('monsternametijden', msg.payload);
|
||||
};
|
||||
|
||||
exports.setRain = (source, msg) => {
|
||||
source.handleInput('rain_data', msg.payload);
|
||||
};
|
||||
|
||||
exports.dataFlow = (source, msg, ctx) => {
|
||||
const log = ctx?.logger || source.logger;
|
||||
const value = Number(msg.payload?.value);
|
||||
const unit = msg.payload?.unit;
|
||||
if (!Number.isFinite(value) || !unit) {
|
||||
log?.warn?.('data.flow payload must include numeric value and unit.');
|
||||
return;
|
||||
}
|
||||
let converted = value;
|
||||
try { converted = convert(value).from(unit).to('m3/h'); }
|
||||
catch (err) { log?.warn?.(`data.flow unit conversion failed: ${err.message}`); return; }
|
||||
source.handleInput('input_q', { value: converted, unit: 'm3/h' });
|
||||
};
|
||||
|
||||
exports.setMode = (source, msg) => {
|
||||
if (typeof source.setMode === 'function') source.setMode(msg.payload);
|
||||
};
|
||||
|
||||
exports.setModelPrediction = (source, msg) => {
|
||||
if (typeof source.setModelPrediction === 'function') source.setModelPrediction(msg.payload);
|
||||
};
|
||||
|
||||
// Inbound child registration from a measurement (or other) child node.
|
||||
// Ported from the legacy `case 'registerChild'` branch in nodeClass.
|
||||
exports.childRegister = (source, msg, ctx) => {
|
||||
const childId = msg.payload;
|
||||
const childObj = ctx?.RED?.nodes?.getNode?.(childId);
|
||||
if (!childObj?.source) {
|
||||
(ctx?.logger || source.logger)?.warn?.(`child.register skipped: missing child/source for id=${childId}`);
|
||||
return;
|
||||
}
|
||||
source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent, msg.distance);
|
||||
};
|
||||
63
src/commands/index.js
Normal file
63
src/commands/index.js
Normal file
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
|
||||
// monster command registry. Canonical names follow CONTRACTS.md §1.
|
||||
// Legacy names (i_start, monsternametijden, rain_data, input_q, setMode,
|
||||
// model_prediction) are surfaced as aliases — they log a one-time
|
||||
// deprecation warning on first use and are removed in Phase 7.
|
||||
|
||||
const handlers = require('./handlers');
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
topic: 'cmd.start',
|
||||
aliases: ['i_start'],
|
||||
payloadSchema: { type: 'any' },
|
||||
description: 'Trigger / release the sampler start gate.',
|
||||
handler: handlers.cmdStart,
|
||||
},
|
||||
{
|
||||
topic: 'set.schedule',
|
||||
aliases: ['monsternametijden'],
|
||||
payloadSchema: { type: 'any' },
|
||||
description: 'Replace the sampling-times schedule.',
|
||||
handler: handlers.setSchedule,
|
||||
},
|
||||
{
|
||||
topic: 'set.rain',
|
||||
aliases: ['rain_data'],
|
||||
payloadSchema: { type: 'any' },
|
||||
description: 'Push current rain-event data into the sampler logic.',
|
||||
handler: handlers.setRain,
|
||||
},
|
||||
{
|
||||
topic: 'data.flow',
|
||||
aliases: ['input_q'],
|
||||
payloadSchema: { type: 'object' },
|
||||
// Compound payload `{value, unit}` — handler converts internally to m3/h.
|
||||
// Registry-level normalisation is skipped (the handler reads payload.value /
|
||||
// payload.unit directly; flattening would break it).
|
||||
description: 'Push the upstream flow measurement (payload: {value, unit}).',
|
||||
handler: handlers.dataFlow,
|
||||
},
|
||||
{
|
||||
topic: 'set.mode',
|
||||
aliases: ['setMode'],
|
||||
payloadSchema: { type: 'any' },
|
||||
description: 'Switch the monster between auto / manual modes.',
|
||||
handler: handlers.setMode,
|
||||
},
|
||||
{
|
||||
topic: 'set.model-prediction',
|
||||
aliases: ['model_prediction'],
|
||||
payloadSchema: { type: 'any' },
|
||||
description: 'Push the upstream rain-prediction snapshot used by the sampler.',
|
||||
handler: handlers.setModelPrediction,
|
||||
},
|
||||
{
|
||||
topic: 'child.register',
|
||||
aliases: ['registerChild'],
|
||||
payloadSchema: { type: 'string' },
|
||||
description: 'Register a child node (typically a measurement) with this monster.',
|
||||
handler: handlers.childRegister,
|
||||
},
|
||||
];
|
||||
59
src/flow/flowTracker.js
Normal file
59
src/flow/flowTracker.js
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
// Flow tracking — manual override + measured-child fan-in + effective
|
||||
// blend (mean of the two when both present). Wraps the
|
||||
// MeasurementContainer so the domain stays read-only on flow state.
|
||||
|
||||
const POSITIONS = ['upstream', 'downstream', 'atequipment'];
|
||||
|
||||
class FlowTracker {
|
||||
constructor({ measurements, logger }) {
|
||||
this.measurements = measurements;
|
||||
this.logger = logger;
|
||||
this.manualFlow = null;
|
||||
}
|
||||
|
||||
updateManualFlow(payload = {}) {
|
||||
const value = Number(payload.value);
|
||||
if (!Number.isFinite(value)) return;
|
||||
const unit = payload.unit || 'm3/h';
|
||||
this.manualFlow = value;
|
||||
this.measurements.type('flow').variant('manual').position('atequipment')
|
||||
.value(value, Date.now(), unit);
|
||||
}
|
||||
|
||||
handleMeasuredFlow(eventData) {
|
||||
const value = Number(eventData?.value);
|
||||
if (!Number.isFinite(value)) return;
|
||||
const position = String(eventData.position || 'atequipment').toLowerCase();
|
||||
const unit = eventData.unit || 'm3/h';
|
||||
this.measurements.type('flow').variant('measured').position(position)
|
||||
.value(value, eventData.timestamp || Date.now(), unit);
|
||||
}
|
||||
|
||||
getMeasuredFlow() {
|
||||
const values = [];
|
||||
for (const pos of POSITIONS) {
|
||||
const v = this.measurements.type('flow').variant('measured').position(pos).getCurrentValue();
|
||||
if (Number.isFinite(v)) values.push(v);
|
||||
}
|
||||
if (!values.length) return null;
|
||||
return values.reduce((s, c) => s + c, 0) / values.length;
|
||||
}
|
||||
|
||||
getManualFlow() {
|
||||
const v = this.measurements.type('flow').variant('manual').position('atequipment').getCurrentValue();
|
||||
return Number.isFinite(v) ? v : null;
|
||||
}
|
||||
|
||||
getEffectiveFlow() {
|
||||
const measured = this.getMeasuredFlow();
|
||||
const manual = this.getManualFlow();
|
||||
if (measured != null && manual != null) return (measured + manual) / 2;
|
||||
if (measured != null) return measured;
|
||||
if (manual != null) return manual;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FlowTracker;
|
||||
70
src/io/output.js
Normal file
70
src/io/output.js
Normal file
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
// Output formatter — assembles the snapshot shape getOutput returns each
|
||||
// tick. Heavy on derived fields (timeToNextPulse, targetDelta, ...) but
|
||||
// every value is read-only on the domain, so this can stay a pure function.
|
||||
|
||||
const params = require('../parameters/parameters');
|
||||
|
||||
function buildOutput(m) {
|
||||
const output = m.measurements.getFlattenedOutput();
|
||||
const flowRate = Number(m.q) || 0;
|
||||
const m3PerPulse = Number(m.m3PerPuls) || 0;
|
||||
const pulseFraction = Number(m.temp_pulse) || 0;
|
||||
const targetVolumeL = Number(m.targetVolume) > 0 ? m.targetVolume : 0;
|
||||
const targetVolumeM3 = targetVolumeL > 0 ? targetVolumeL / 1000 : 0;
|
||||
const flowToNextPulseM3 = m3PerPulse > 0 ? Math.max(0, (1 - pulseFraction) * m3PerPulse) : 0;
|
||||
const timeToNextPulseSec = flowRate > 0 && flowToNextPulseM3 > 0
|
||||
? Math.round((flowToNextPulseM3 / (flowRate / 3600)) * 100) / 100
|
||||
: 0;
|
||||
const targetProgressPct = targetVolumeL > 0
|
||||
? Math.round((m.bucketVol / targetVolumeL) * 10000) / 100
|
||||
: 0;
|
||||
const targetDeltaL = targetVolumeL > 0
|
||||
? Math.round((m.bucketVol - targetVolumeL) * 100) / 100
|
||||
: 0;
|
||||
const targetDeltaM3 = targetVolumeL > 0
|
||||
? Math.round((targetDeltaL / 1000) * 10000) / 10000
|
||||
: 0;
|
||||
|
||||
Object.assign(output, {
|
||||
pulse: m.pulse,
|
||||
running: m.running,
|
||||
bucketVol: m.bucketVol,
|
||||
bucketWeight: m.bucketWeight,
|
||||
sumPuls: m.sumPuls,
|
||||
predFlow: m.predFlow,
|
||||
predM3PerSec: m.predM3PerSec,
|
||||
timePassed: m.timePassed,
|
||||
timeLeft: m.timeLeft,
|
||||
m3Total: m.m3Total,
|
||||
q: m.q,
|
||||
nominalFlowMin: m.nominalFlowMin,
|
||||
flowMax: m.flowMax,
|
||||
invalidFlowBounds: m.invalidFlowBounds,
|
||||
minSampleIntervalSec: m.minSampleIntervalSec,
|
||||
missedSamples: m.missedSamples,
|
||||
sampleCooldownMs: params.getSampleCooldownMs(m),
|
||||
maxVolume: m.maxVolume,
|
||||
minVolume: m.minVolume,
|
||||
nextDate: m.nextDate,
|
||||
daysPerYear: m.daysPerYear,
|
||||
m3PerPuls: m.m3PerPuls,
|
||||
m3PerPulse: m.m3PerPuls,
|
||||
pulsesRemaining: Math.max(0, (m.targetPuls || 0) - (m.sumPuls || 0)),
|
||||
pulseFraction,
|
||||
flowToNextPulseM3,
|
||||
timeToNextPulseSec,
|
||||
targetVolumeM3,
|
||||
targetProgressPct,
|
||||
targetDeltaL,
|
||||
targetDeltaM3,
|
||||
predictedRateM3h: params.getPredictedFlowRate(m),
|
||||
sumRain: m.rainAggregator?.sumRain ?? 0,
|
||||
avgRain: m.rainAggregator?.avgRain ?? 0,
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = { buildOutput };
|
||||
28
src/io/statusBadge.js
Normal file
28
src/io/statusBadge.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
// Status-badge composition. Three states the editor cares about:
|
||||
// - red ring : config error (flow bounds invalid)
|
||||
// - yellow ring: sampling but cooldown is gating the next pulse
|
||||
// - green dot : sampling normally
|
||||
// - grey ring : idle
|
||||
// Shape mirrors the legacy nodeClass._updateNodeStatus output verbatim.
|
||||
|
||||
const { statusBadge } = require('generalFunctions');
|
||||
const params = require('../parameters/parameters');
|
||||
|
||||
function buildStatusBadge(m) {
|
||||
if (m.invalidFlowBounds) {
|
||||
return statusBadge.error(`Config error: nominalFlowMin (${m.nominalFlowMin}) >= flowMax (${m.flowMax})`);
|
||||
}
|
||||
if (m.running) {
|
||||
const levelText = `${m.bucketVol}/${m.maxVolume} L`;
|
||||
const cooldownMs = params.getSampleCooldownMs(m);
|
||||
if (cooldownMs > 0) {
|
||||
return statusBadge.compose([`SAMPLING (${Math.ceil(cooldownMs / 1000)}s)`, levelText], { fill: 'yellow', shape: 'ring' });
|
||||
}
|
||||
return statusBadge.compose([`AI: RUNNING`, levelText], { fill: 'green', shape: 'dot' });
|
||||
}
|
||||
return statusBadge.idle('AI: IDLE');
|
||||
}
|
||||
|
||||
module.exports = { buildStatusBadge };
|
||||
240
src/nodeClass.js
240
src/nodeClass.js
@@ -1,51 +1,19 @@
|
||||
/**
|
||||
* node class.js
|
||||
*
|
||||
* Encapsulates all node logic in a reusable class. In future updates we can split this into multiple generic classes and use the config to specifiy which ones to use.
|
||||
* This allows us to keep the Node-RED node clean and focused on wiring up the UI and event handlers.
|
||||
*/
|
||||
const { outputUtils, configManager, convert } = require('generalFunctions');
|
||||
const Specific = require('./specificClass');
|
||||
'use strict';
|
||||
|
||||
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.
|
||||
*/
|
||||
constructor(uiConfig, RED, nodeInstance, nameOfNode) {
|
||||
this.node = nodeInstance;
|
||||
this.RED = RED;
|
||||
this.name = nameOfNode;
|
||||
this.source = null;
|
||||
this.config = null;
|
||||
const { BaseNodeAdapter } = require('generalFunctions');
|
||||
const Monster = require('./specificClass');
|
||||
const commands = require('./commands');
|
||||
|
||||
// Load default & UI config
|
||||
this._loadConfig(uiConfig);
|
||||
class nodeClass extends BaseNodeAdapter {
|
||||
static DomainClass = Monster;
|
||||
static commands = commands;
|
||||
// Tick-driven: sampling integrator (m3PerTick → temp_pulse) needs
|
||||
// wall-clock delta-time once per second.
|
||||
static tickInterval = 1000;
|
||||
static statusInterval = 1000;
|
||||
|
||||
// Instantiate core class
|
||||
this._setupSpecificClass(uiConfig);
|
||||
|
||||
// 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.
|
||||
* Uses ConfigManager.buildConfig() for base sections, then adds monster-specific domain config.
|
||||
* @param {object} uiConfig - Raw config from Node-RED UI.
|
||||
*/
|
||||
_loadConfig(uiConfig) {
|
||||
const cfgMgr = new configManager();
|
||||
|
||||
// Build config: base sections + monster-specific domain config
|
||||
this.config = cfgMgr.buildConfig(this.name, uiConfig, this.node.id, {
|
||||
buildDomainConfig(uiConfig) {
|
||||
return {
|
||||
constraints: {
|
||||
samplingtime: Number(uiConfig.samplingtime) || 0,
|
||||
minVolume: Number(uiConfig.minvolume ?? uiConfig.minVolume) || 5,
|
||||
@@ -55,186 +23,14 @@ class nodeClass {
|
||||
maxRainRef: Number(uiConfig.maxRainRef) || 10,
|
||||
minSampleIntervalSec: Number(uiConfig.minSampleIntervalSec) || 60,
|
||||
},
|
||||
});
|
||||
|
||||
this.config.functionality = {
|
||||
...this.config.functionality,
|
||||
role: 'samplingCabinet',
|
||||
aquonSampleName: uiConfig.aquon_sample_name || undefined,
|
||||
functionality: { role: 'samplingCabinet', aquonSampleName: uiConfig.aquon_sample_name || undefined },
|
||||
asset: { emptyWeightBucket: Number(uiConfig.emptyWeightBucket) || 3 },
|
||||
};
|
||||
|
||||
this.config.asset = {
|
||||
...this.config.asset,
|
||||
emptyWeightBucket: Number(uiConfig.emptyWeightBucket) || 3,
|
||||
};
|
||||
|
||||
// Utility for formatting outputs
|
||||
this._output = new outputUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate the core logic and store as source.
|
||||
*/
|
||||
_setupSpecificClass(uiConfig) {
|
||||
this.source = new Specific(this.config);
|
||||
|
||||
if (uiConfig?.aquon_sample_name) {
|
||||
this.source.aquonSampleName = uiConfig.aquon_sample_name;
|
||||
}
|
||||
|
||||
this.node.source = this.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind events to Node-RED status updates.
|
||||
*/
|
||||
_bindEvents() {}
|
||||
|
||||
_updateNodeStatus() {
|
||||
const m = this.source;
|
||||
try {
|
||||
const bucketVol = m.bucketVol;
|
||||
const maxVolume = m.maxVolume;
|
||||
const state = m.running;
|
||||
const mode = 'AI';
|
||||
const flowMin = m.nominalFlowMin;
|
||||
const flowMax = m.flowMax;
|
||||
|
||||
if (m.invalidFlowBounds) {
|
||||
return {
|
||||
fill: 'red',
|
||||
shape: 'ring',
|
||||
text: `Config error: nominalFlowMin (${flowMin}) >= flowMax (${flowMax})`,
|
||||
};
|
||||
}
|
||||
|
||||
if (state) {
|
||||
const levelText = `${bucketVol}/${maxVolume} L`;
|
||||
const cooldownMs = typeof m.getSampleCooldownMs === 'function'
|
||||
? m.getSampleCooldownMs()
|
||||
: 0;
|
||||
|
||||
if (cooldownMs > 0) {
|
||||
const cooldownSec = Math.ceil(cooldownMs / 1000);
|
||||
return { fill: 'yellow', shape: 'ring', text: `SAMPLING (${cooldownSec}s) ${levelText}` };
|
||||
}
|
||||
|
||||
return { fill: 'green', shape: 'dot', text: `${mode}: RUNNING ${levelText}` };
|
||||
}
|
||||
|
||||
return { fill: 'grey', shape: 'ring', text: `${mode}: IDLE` };
|
||||
} catch (error) {
|
||||
this.node.error(`Error in updateNodeStatus: ${error.message}`);
|
||||
return { fill: 'red', shape: 'ring', text: 'Status Error' };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this node as a child upstream and downstream.
|
||||
* Delayed to avoid Node-RED startup race conditions.
|
||||
*/
|
||||
_registerChild() {
|
||||
setTimeout(() => {
|
||||
this.node.send([
|
||||
null,
|
||||
null,
|
||||
{ topic: 'registerChild', payload: this.config.general.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' },
|
||||
]);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the periodic tick loop.
|
||||
*/
|
||||
_startTickLoop() {
|
||||
setTimeout(() => {
|
||||
this._tickInterval = setInterval(() => this._tick(), 1000);
|
||||
this._statusInterval = setInterval(() => {
|
||||
this.node.status(this._updateNodeStatus());
|
||||
}, 1000);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a single tick: update measurement, format and send outputs.
|
||||
*/
|
||||
_tick() {
|
||||
this.source.tick();
|
||||
|
||||
const raw = this.source.getOutput();
|
||||
const processMsg = this._output.formatMsg(raw, this.source.config, 'process');
|
||||
const influxMsg = this._output.formatMsg(raw, this.source.config, 'influxdb');
|
||||
|
||||
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) => {
|
||||
const m = this.source;
|
||||
try {
|
||||
switch (msg.topic) {
|
||||
case 'input_q': {
|
||||
const value = Number(msg.payload?.value);
|
||||
const unit = msg.payload?.unit;
|
||||
if (!Number.isFinite(value) || !unit) {
|
||||
this.node.warn('input_q payload must include numeric value and unit.');
|
||||
break;
|
||||
}
|
||||
let converted = value;
|
||||
try {
|
||||
converted = convert(value).from(unit).to('m3/h');
|
||||
} catch (error) {
|
||||
this.node.warn(`input_q unit conversion failed: ${error.message}`);
|
||||
break;
|
||||
}
|
||||
m.handleInput('input_q', { value: converted, unit: 'm3/h' });
|
||||
break;
|
||||
}
|
||||
case 'i_start':
|
||||
case 'monsternametijden':
|
||||
case 'rain_data':
|
||||
m.handleInput(msg.topic, msg.payload);
|
||||
break;
|
||||
case 'registerChild': {
|
||||
const childId = msg.payload;
|
||||
const childObj = this.RED.nodes.getNode(childId);
|
||||
if (childObj?.source) {
|
||||
m.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'setMode':
|
||||
m.setMode(msg.payload);
|
||||
break;
|
||||
case 'model_prediction':
|
||||
if (typeof m.setModelPrediction === 'function') {
|
||||
m.setModelPrediction(msg.payload);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
m.logger?.warn(`Unknown topic: ${msg.topic}`);
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
this.node.error(`Error handling input (${msg?.topic}): ${error?.message || error}`);
|
||||
} finally {
|
||||
if (typeof done === 'function') done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up timers and intervals when Node-RED stops the node.
|
||||
*/
|
||||
_attachCloseHandler() {
|
||||
this.node.on('close', (done) => {
|
||||
clearInterval(this._tickInterval);
|
||||
clearInterval(this._statusInterval);
|
||||
if (typeof done === 'function') done();
|
||||
});
|
||||
extraSetup() {
|
||||
const uiSampleName = this.config?.functionality?.aquonSampleName;
|
||||
if (uiSampleName) this.source.aquonSampleName = uiSampleName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
60
src/parameters/parameters.js
Normal file
60
src/parameters/parameters.js
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
// Sampling-cabinet boundary + target math + rain-scaled flow prediction.
|
||||
// All operations are pure given a domain handle — the domain owns the
|
||||
// mutable fields (maxVolume, targetPuls, …) so legacy tests that read
|
||||
// `monster.maxVolume` keep working.
|
||||
|
||||
const RAIN_STALE_MS = 2 * 60 * 60 * 1000;
|
||||
|
||||
function applyBoundsAndTargets(m) {
|
||||
m.maxVolume = m.maxWeight - m.emptyWeightBucket;
|
||||
m.minPuls = Math.round(m.minVolume / m.volume_pulse);
|
||||
m.maxPuls = Math.round(m.maxVolume / m.volume_pulse);
|
||||
m.absMaxPuls = Math.round(m.cap_volume / m.volume_pulse);
|
||||
m.targetVolume = m.minVolume * Math.sqrt(m.maxVolume / m.minVolume);
|
||||
m.targetPuls = Math.round(m.targetVolume / m.volume_pulse);
|
||||
}
|
||||
|
||||
function validateFlowBounds(m) {
|
||||
// nominalFlowMin / flowMax must be declared in monster.json's `constraints`
|
||||
// section. If they aren't, configUtils strips them as unknown keys and the
|
||||
// bounds collapse to undefined → NaN → invalid here, which silently blocks
|
||||
// every sampling run. (Fixed 2026-05-11.)
|
||||
const min = Number(m.nominalFlowMin);
|
||||
const max = Number(m.flowMax);
|
||||
const valid = Number.isFinite(min) && Number.isFinite(max) && min >= 0 && max > 0 && min < max;
|
||||
m.invalidFlowBounds = !valid;
|
||||
if (!valid) m.logger.warn(`Invalid flow bounds. nominalFlowMin=${m.nominalFlowMin}, flowMax=${m.flowMax}`);
|
||||
return valid;
|
||||
}
|
||||
|
||||
function getRainIndex(m) {
|
||||
if (!m.lastRainUpdate) return 0;
|
||||
if (Date.now() - m.lastRainUpdate > RAIN_STALE_MS) return 0;
|
||||
return Number.isFinite(m.avgRain) ? m.avgRain : 0;
|
||||
}
|
||||
|
||||
function getPredictedFlowRate(m) {
|
||||
const min = Number(m.nominalFlowMin);
|
||||
const max = Number(m.flowMax);
|
||||
if (!Number.isFinite(min) || !Number.isFinite(max) || min < 0 || max <= 0 || min >= max) return 0;
|
||||
const rainIndex = getRainIndex(m);
|
||||
const scale = Math.max(0, Math.min(1, m.rainMaxRef > 0 ? rainIndex / m.rainMaxRef : 0));
|
||||
return min + (max - min) * scale;
|
||||
}
|
||||
|
||||
function getSampleCooldownMs(m) {
|
||||
if (!m.lastSampleTime) return 0;
|
||||
const remaining = (m.minSampleIntervalSec * 1000) - (Date.now() - m.lastSampleTime);
|
||||
return Math.max(0, remaining);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
applyBoundsAndTargets,
|
||||
validateFlowBounds,
|
||||
getRainIndex,
|
||||
getPredictedFlowRate,
|
||||
getSampleCooldownMs,
|
||||
RAIN_STALE_MS,
|
||||
};
|
||||
58
src/rain/rainAggregator.js
Normal file
58
src/rain/rainAggregator.js
Normal file
@@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
|
||||
// Rain-data aggregator — sums per-location hourly precipitation, weighted
|
||||
// by per-hour probability, and stores both the raw and probability-weighted
|
||||
// values keyed by timestamp. sumRain/avgRain feed parameters.getRainIndex
|
||||
// which scales the predicted flow rate between nominalFlowMin and flowMax.
|
||||
|
||||
class RainAggregator {
|
||||
constructor({ logger } = {}) {
|
||||
this.logger = logger;
|
||||
this.aggregatedOutput = {};
|
||||
this.sumRain = 0;
|
||||
this.avgRain = 0;
|
||||
}
|
||||
|
||||
// Returns the aggregated per-location object so callers can chain.
|
||||
// Mutates this.aggregatedOutput / sumRain / avgRain in place.
|
||||
update(value) {
|
||||
if (!value) return this.aggregatedOutput;
|
||||
|
||||
const totalRaw = {};
|
||||
const totalProb = {};
|
||||
let numberOfLocations = 0;
|
||||
|
||||
Object.entries(value).forEach(([locationKey, location]) => {
|
||||
numberOfLocations++;
|
||||
const slot = (this.aggregatedOutput[locationKey] = {
|
||||
tag: { latitude: location.latitude, longitude: location.longitude },
|
||||
precipationRaw: {},
|
||||
precipationProb: {},
|
||||
});
|
||||
|
||||
Object.entries(location.hourly.time).forEach(([key, time]) => {
|
||||
const currTimestamp = new Date(time).getTime();
|
||||
let probability = 100;
|
||||
if (typeof location.hourly.precipitation_probability !== 'undefined') {
|
||||
probability = location.hourly.precipitation_probability[key];
|
||||
}
|
||||
if (probability > 0) probability /= 100;
|
||||
|
||||
if (totalRaw[currTimestamp] === undefined) totalRaw[currTimestamp] = 0;
|
||||
if (totalProb[currTimestamp] === undefined) totalProb[currTimestamp] = 0;
|
||||
|
||||
totalRaw[currTimestamp] += location.hourly.precipitation[key];
|
||||
totalProb[currTimestamp] += location.hourly.precipitation[key] * probability;
|
||||
|
||||
slot.precipationRaw[key] = { val: location.hourly.precipitation[key], time: currTimestamp };
|
||||
slot.precipationProb[key] = { val: probability, time: currTimestamp };
|
||||
});
|
||||
});
|
||||
|
||||
this.sumRain = Object.values(totalProb).reduce((s, v) => s + v, 0);
|
||||
this.avgRain = numberOfLocations > 0 ? this.sumRain / numberOfLocations : 0;
|
||||
return this.aggregatedOutput;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RainAggregator;
|
||||
113
src/sampling/samplingProgram.js
Normal file
113
src/sampling/samplingProgram.js
Normal file
@@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
|
||||
// Sampling program — the time-driven core. Each tick:
|
||||
// 1. on i_start or scheduled date → init a sampling run (m3PerPuls, stop_time)
|
||||
// 2. while running: integrate m3PerTick into temp_pulse; emit a pulse when
|
||||
// it crosses 1 unless the cooldown guard blocks it
|
||||
// 3. after stop_time: clear running state.
|
||||
// flowCalc derives m3PerTick from the latest q (m3/h) and the wall-clock
|
||||
// delta since the last call — runs once per tick before sampling_program.
|
||||
|
||||
const params = require('../parameters/parameters');
|
||||
const { regNextDate } = require('../schedule/schedule');
|
||||
|
||||
function getModelPrediction(m) {
|
||||
const samplingHours = Number(m.sampling_time) || 0;
|
||||
const predictedRate = params.getPredictedFlowRate(m);
|
||||
const fallbackRate = m.flowTracker.getEffectiveFlow();
|
||||
const flowM3PerHour = predictedRate > 0 ? predictedRate : fallbackRate;
|
||||
m.predFlow = Math.max(0, flowM3PerHour * samplingHours);
|
||||
return m.predFlow;
|
||||
}
|
||||
|
||||
function flowCalc(m) {
|
||||
const timePassed = m.flowTime > 0 ? (Date.now() - m.flowTime) / 1000 : 0;
|
||||
m.m3PerTick = (m.q / 60 / 60) * timePassed;
|
||||
m.flowTime = Date.now();
|
||||
}
|
||||
|
||||
function _beginRun(m) {
|
||||
m.running = true;
|
||||
m.temp_pulse = 0;
|
||||
m.pulse = false;
|
||||
m.updateBucketVol(0);
|
||||
m.sumPuls = 0;
|
||||
m.m3Total = 0;
|
||||
m.timePassed = 0;
|
||||
m.timeLeft = 0;
|
||||
m.predM3PerSec = 0;
|
||||
|
||||
getModelPrediction(m);
|
||||
m.m3PerPuls = Math.round(m.predFlow / m.targetPuls);
|
||||
m.predM3PerSec = m.predFlow / m.sampling_time / 60 / 60;
|
||||
m.start_time = Date.now();
|
||||
m.stop_time = Date.now() + (m.sampling_time * 60 * 60 * 1000);
|
||||
|
||||
regNextDate(m, m.monsternametijden);
|
||||
m.i_start = false;
|
||||
}
|
||||
|
||||
function _endRun(m) {
|
||||
m.m3PerPuls = 0;
|
||||
m.temp_pulse = 0;
|
||||
m.pulse = false;
|
||||
m.updateBucketVol(0);
|
||||
m.sumPuls = 0;
|
||||
m.timePassed = 0;
|
||||
m.timeLeft = 0;
|
||||
m.predFlow = 0;
|
||||
m.predM3PerSec = 0;
|
||||
m.m3Total = 0;
|
||||
m.running = false;
|
||||
}
|
||||
|
||||
function _maybeEmitPulse(m) {
|
||||
if (!(m.temp_pulse >= 1 && m.sumPuls < m.absMaxPuls)) {
|
||||
if (m.pulse) m.pulse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const cooldownMs = m.minSampleIntervalSec * 1000;
|
||||
const blocked = m.lastSampleTime && (now - m.lastSampleTime) < cooldownMs;
|
||||
|
||||
if (blocked) {
|
||||
m.missedSamples++;
|
||||
m.pulse = false;
|
||||
m.temp_pulse = Math.min(m.temp_pulse, 1);
|
||||
if (!m.lastSampleWarnTime || (now - m.lastSampleWarnTime) > cooldownMs) {
|
||||
m.lastSampleWarnTime = now;
|
||||
m.logger.warn(`Sampling too fast. Cooldown active for ${Math.ceil((cooldownMs - (now - m.lastSampleTime)) / 1000)}s.`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m.temp_pulse -= 1;
|
||||
m.pulse = true;
|
||||
m.lastSampleTime = now;
|
||||
m.sumPuls++;
|
||||
m.updateBucketVol(Math.round(m.sumPuls * m.volume_pulse * 100) / 100);
|
||||
}
|
||||
|
||||
function samplingProgram(m) {
|
||||
if (((m.i_start) || (Date.now() >= m.nextDate)) && !m.running) {
|
||||
if (!params.validateFlowBounds(m)) {
|
||||
m.running = false;
|
||||
m.i_start = false;
|
||||
return;
|
||||
}
|
||||
_beginRun(m);
|
||||
}
|
||||
|
||||
if (m.stop_time > Date.now()) {
|
||||
m.timePassed = Math.round((Date.now() - m.start_time) / 1000);
|
||||
m.timeLeft = Math.round((m.stop_time - Date.now()) / 1000);
|
||||
m.temp_pulse += m.m3PerTick / m.m3PerPuls;
|
||||
m.m3Total += m.m3PerTick;
|
||||
_maybeEmitPulse(m);
|
||||
} else if (m.running) {
|
||||
_endRun(m);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { samplingProgram, flowCalc, getModelPrediction };
|
||||
42
src/schedule/schedule.js
Normal file
42
src/schedule/schedule.js
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
// AQUON sample schedule helpers. updateMonsternametijden validates the
|
||||
// row shape before storing; regNextDate walks the rows to find the next
|
||||
// future START_DATE for the configured aquonSampleName and counts how
|
||||
// many of those fall in the current calendar year.
|
||||
|
||||
function updateMonsternametijden(m, value) {
|
||||
if (!m.init || !value || Object.keys(value).length === 0) return;
|
||||
if (
|
||||
typeof value[0]?.SAMPLE_NAME !== 'undefined' &&
|
||||
typeof value[0]?.DESCRIPTION !== 'undefined' &&
|
||||
typeof value[0]?.SAMPLED_DATE !== 'undefined' &&
|
||||
typeof value[0]?.START_DATE !== 'undefined' &&
|
||||
typeof value[0]?.END_DATE !== 'undefined'
|
||||
) {
|
||||
m.monsternametijden = value;
|
||||
regNextDate(m, value);
|
||||
}
|
||||
}
|
||||
|
||||
function regNextDate(m, monsternametijden) {
|
||||
let next_date = new Date(new Date().setFullYear(new Date().getFullYear() + 1));
|
||||
let n_days_remaining = 0;
|
||||
|
||||
if (typeof monsternametijden !== 'undefined') {
|
||||
Object.values(monsternametijden).forEach((line) => {
|
||||
if (line.START_DATE === 'NULL') return;
|
||||
const curr_date_conv = new Date(line.START_DATE);
|
||||
const curr_date = curr_date_conv.getTime();
|
||||
if (line.SAMPLE_NAME === m.aquonSampleName && curr_date > Date.now()) {
|
||||
if (curr_date < next_date) next_date = curr_date;
|
||||
if (new Date().getFullYear() === curr_date_conv.getFullYear()) n_days_remaining++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
m.daysPerYear = n_days_remaining;
|
||||
m.nextDate = next_date;
|
||||
}
|
||||
|
||||
module.exports = { updateMonsternametijden, regNextDate };
|
||||
File diff suppressed because it is too large
Load Diff
318
wiki/Home.md
Normal file
318
wiki/Home.md
Normal file
@@ -0,0 +1,318 @@
|
||||
# monster
|
||||
|
||||
> **Reflects code as of `8540328` · regenerated `2026-05-11` via `npm run wiki:all`**
|
||||
> If this banner is stale, the page may be out of date. Treat as informative, not authoritative.
|
||||
|
||||
## 1. What this node is
|
||||
|
||||
**monster** is an S88 Unit that runs an AQUON-scheduled flow-proportional sampling program. It aggregates measured + manual flow, blends a rain-scaled prediction, and emits a `pulse` whenever the integrated volume crosses `m³ per pulse`. Drives the physical "monsternamekast" (composite sampling cabinet) on a wastewater treatment plant.
|
||||
|
||||
## 2. Position in the platform
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
parent[plant parent<br/>Process Cell]:::pc
|
||||
monster[monster<br/>Unit]:::unit
|
||||
flow_up[measurement<br/>type=flow<br/>position=upstream]:::ctrl
|
||||
flow_at[measurement<br/>type=flow<br/>position=atequipment]:::ctrl
|
||||
op[(operator / AQUON)]
|
||||
weather[(Open-Meteo)]
|
||||
|
||||
flow_up -->|flow.measured.upstream| monster
|
||||
flow_at -->|flow.measured.atequipment| monster
|
||||
op -->|set.schedule / data.flow / cmd.start| monster
|
||||
weather -->|set.rain| monster
|
||||
monster -->|child.register| parent
|
||||
monster -.evt.output.-> parent
|
||||
classDef pc fill:#0c99d9,color:#fff
|
||||
classDef unit fill:#50a8d9,color:#000
|
||||
classDef ctrl fill:#a9daee,color:#000
|
||||
```
|
||||
|
||||
S88 colours: Process Cell `#0c99d9`, Unit `#50a8d9`, Control Module `#a9daee`. Source of truth: `.claude/rules/node-red-flow-layout.md`.
|
||||
|
||||
## 3. Capability matrix
|
||||
|
||||
| Capability | Status | Notes |
|
||||
|---|---|---|
|
||||
| Flow-proportional sampling pulse | ✅ | Triggered when integrated `temp_pulse` ≥ 1. |
|
||||
| Time-bounded sampling run | ✅ | Run length governed by `constraints.samplingtime` (hours). |
|
||||
| AQUON schedule auto-start | ✅ | `set.schedule` parses AQUON rows; `nextDate` arms the next run. |
|
||||
| Rain-scaled flow prediction | ✅ | `set.rain` aggregates Open-Meteo hourly precipitation into `sumRain` / `avgRain`. |
|
||||
| Measured + manual flow blend | ✅ | `flowTracker.getEffectiveFlow()` picks measured if recent, else manual. |
|
||||
| Minimum sample-interval cooldown | ✅ | Skips pulses inside `minSampleIntervalSec` window. |
|
||||
| Bucket / weight tracking | ✅ | `bucketVol`, `bucketWeight` track the composite container. |
|
||||
| Sub-sample volume override | ❌ | `subSampleVolume` fixed at 50 mL per schema. |
|
||||
| Stateful FSM | ❌ | Monster is run/idle only — no formal state machine. |
|
||||
|
||||
## 4. Code map
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph nodeRED["nodeClass.js — adapter (BaseNodeAdapter)"]
|
||||
nc["buildDomainConfig()<br/>static DomainClass = Monster<br/>static commands"]
|
||||
end
|
||||
subgraph domain["specificClass.js — orchestrator (BaseDomain)"]
|
||||
sc["Monster.configure()<br/>wires concerns, ChildRouter rules<br/>tick() → flowCalc → samplingProgram"]
|
||||
end
|
||||
subgraph concerns["src/ concern modules"]
|
||||
parameters["parameters/<br/>bounds + targets + rain index"]
|
||||
flow["flow/<br/>FlowTracker (measured + manual)"]
|
||||
rain["rain/<br/>RainAggregator (sum + avg)"]
|
||||
schedule["schedule/<br/>AQUON next-date parser"]
|
||||
sampling["sampling/<br/>samplingProgram + flowCalc"]
|
||||
io["io/<br/>output + statusBadge"]
|
||||
commands["commands/<br/>topic registry + handlers"]
|
||||
end
|
||||
nc --> sc
|
||||
sc --> parameters
|
||||
sc --> flow
|
||||
sc --> rain
|
||||
sc --> schedule
|
||||
sc --> sampling
|
||||
sc --> io
|
||||
nc --> commands
|
||||
```
|
||||
|
||||
| Module | Owns | Read first if you're changing… |
|
||||
|---|---|---|
|
||||
| `parameters/` | Bounds (`minPuls`, `absMaxPuls`, `targetPuls`), rain-index lookup, predicted-flow rate. | Sampling bounds, rain scaling math. |
|
||||
| `flow/` | `FlowTracker` — measured-child latch + manual flow + effective-flow pick. | Flow source priority, dead-band logic. |
|
||||
| `rain/` | `RainAggregator` — fold hourly Open-Meteo rows into `sumRain` / `avgRain`. | Rain inputs, forecast horizon. |
|
||||
| `schedule/` | AQUON schedule parsing, `nextDate` + `daysPerYear` derivation. | Schedule arming, sample-name filtering. |
|
||||
| `sampling/` | `_beginRun` / `_endRun` / `_maybeEmitPulse` — pulse integrator + cooldown guard. | Pulse timing, cooldown behaviour. |
|
||||
| `io/` | `buildOutput`, `buildStatusBadge`. | Port-0 payload shape, status badge text. |
|
||||
| `commands/` | Topic registry + payload validation + unit conversion. | New input topics, alias deprecation. |
|
||||
|
||||
## 5. Topic contract
|
||||
|
||||
> **Auto-generated** from `src/commands/index.js`. Do NOT hand-edit between the markers. Re-run `npm run wiki:contract`.
|
||||
|
||||
<!-- BEGIN AUTOGEN: topic-contract -->
|
||||
|
||||
| Canonical topic | Aliases | Payload | Unit | Effect |
|
||||
|---|---|---|---|---|
|
||||
| `cmd.start` | `i_start` | `any` | — | Trigger / release the sampler start gate. |
|
||||
| `set.schedule` | `monsternametijden` | `any` | — | Replace the sampling-times schedule. |
|
||||
| `set.rain` | `rain_data` | `any` | — | Push current rain-event data into the sampler logic. |
|
||||
| `data.flow` | `input_q` | `object` | — | Push the upstream flow measurement (payload: {value, unit}). |
|
||||
| `set.mode` | `setMode` | `any` | — | Switch the monster between auto / manual modes. |
|
||||
| `set.model-prediction` | `model_prediction` | `any` | — | Push the upstream rain-prediction snapshot used by the sampler. |
|
||||
| `child.register` | `registerChild` | `string` | — | Register a child node (typically a measurement) with this monster. |
|
||||
|
||||
<!-- END AUTOGEN: topic-contract -->
|
||||
|
||||
## 6. Child registration
|
||||
|
||||
Mirrors the `ChildRouter` declaration in `specificClass.js → configure()`. Monster only accepts `measurement` children whose `asset.type` is `flow` (or unset).
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph kids["accepted children (softwareType)"]
|
||||
m_up["measurement<br/>asset.type=flow<br/>position=upstream"]:::ctrl
|
||||
m_at["measurement<br/>asset.type=flow<br/>position=atequipment"]:::ctrl
|
||||
m_dn["measurement<br/>asset.type=flow<br/>position=downstream"]:::ctrl
|
||||
end
|
||||
m_up -->|flow.measured.upstream| ft[FlowTracker.handleMeasuredFlow]
|
||||
m_at -->|flow.measured.atequipment| ft
|
||||
m_dn -->|flow.measured.downstream| ft
|
||||
ft --> eff[getEffectiveFlow]
|
||||
classDef ctrl fill:#a9daee,color:#000
|
||||
```
|
||||
|
||||
| softwareType | filter | wired to | side-effect |
|
||||
|---|---|---|---|
|
||||
| `measurement` | `asset.type=flow` (or missing) | `flowTracker.handleMeasuredFlow` | Latches latest measured flow for `getEffectiveFlow`. |
|
||||
| `measurement` | `asset.type` anything else | _ignored_ | Logged once at register. |
|
||||
|
||||
## 7. Lifecycle — the sampling-program loop
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant child as measurement child
|
||||
participant ops as operator / AQUON
|
||||
participant monster as monster
|
||||
participant ft as flowTracker
|
||||
participant sp as samplingProgram
|
||||
participant out as Port-0 output
|
||||
|
||||
child->>monster: flow.measured.<position>
|
||||
ops->>monster: set.schedule / cmd.start / data.flow
|
||||
Note over monster: every 1000 ms tick
|
||||
monster->>ft: getEffectiveFlow()
|
||||
monster->>monster: flowCalc → m3PerTick
|
||||
monster->>sp: samplingProgram
|
||||
alt cmd.start OR Date.now() ≥ nextDate
|
||||
sp->>sp: validateFlowBounds → _beginRun
|
||||
end
|
||||
alt running AND stop_time > now
|
||||
sp->>sp: integrate temp_pulse += m3PerTick / m3PerPuls
|
||||
sp->>sp: _maybeEmitPulse (cooldown-guarded)
|
||||
else stop_time elapsed
|
||||
sp->>sp: _endRun
|
||||
end
|
||||
monster->>out: msg{topic, payload (delta-compressed)}
|
||||
```
|
||||
|
||||
One pulse per integrated `m³ per pulse`. The cooldown guard suppresses pulses inside `minSampleIntervalSec` and increments `missedSamples`.
|
||||
|
||||
## 8. Data model — `getOutput()`
|
||||
|
||||
What lands on Port 0. Built in `buildOutput()` from `m.measurements.getFlattenedOutput()` plus the sampling-run snapshot.
|
||||
|
||||
<!-- BEGIN AUTOGEN: data-model -->
|
||||
|
||||
| Key | Type | Unit | Sample |
|
||||
|---|---|---|---|
|
||||
| `avgRain` | number | — | `0` |
|
||||
| `bucketVol` | number | — | `0` |
|
||||
| `bucketWeight` | number | — | `0` |
|
||||
| `daysPerYear` | number | — | `0` |
|
||||
| `flowMax` | number | — | `0` |
|
||||
| `flowToNextPulseM3` | number | — | `0` |
|
||||
| `invalidFlowBounds` | boolean | — | `false` |
|
||||
| `m3PerPuls` | number | — | `0` |
|
||||
| `m3PerPulse` | number | — | `0` |
|
||||
| `m3Total` | number | — | `0` |
|
||||
| `maxVolume` | number | — | `20` |
|
||||
| `minSampleIntervalSec` | number | — | `60` |
|
||||
| `minVolume` | number | — | `5` |
|
||||
| `missedSamples` | number | — | `0` |
|
||||
| `nextDate` | undefined | — | `null` |
|
||||
| `nominalFlowMin` | number | — | `0` |
|
||||
| `predFlow` | number | — | `0` |
|
||||
| `predM3PerSec` | number | — | `0` |
|
||||
| `predictedRateM3h` | number | — | `0` |
|
||||
| `pulse` | boolean | — | `false` |
|
||||
| `pulseFraction` | number | — | `0` |
|
||||
| `pulsesRemaining` | number | — | `200` |
|
||||
| `q` | number | — | `0` |
|
||||
| `running` | boolean | — | `false` |
|
||||
| `sampleCooldownMs` | number | — | `0` |
|
||||
| `sumPuls` | number | — | `0` |
|
||||
| `sumRain` | number | — | `0` |
|
||||
| `targetDeltaL` | number | — | `-10` |
|
||||
| `targetDeltaM3` | number | — | `-0.01` |
|
||||
| `targetProgressPct` | number | — | `0` |
|
||||
| `targetVolumeM3` | number | — | `0.01` |
|
||||
| `timeLeft` | number | — | `0` |
|
||||
| `timePassed` | number | — | `0` |
|
||||
| `timeToNextPulseSec` | number | — | `0` |
|
||||
|
||||
<!-- END AUTOGEN: data-model -->
|
||||
|
||||
**Concrete sample** (mid-run snapshot):
|
||||
|
||||
```json
|
||||
{
|
||||
"pulse": false,
|
||||
"running": true,
|
||||
"bucketVol": 1.25,
|
||||
"sumPuls": 25,
|
||||
"predFlow": 240.0,
|
||||
"m3PerPuls": 4,
|
||||
"q": 215.4,
|
||||
"timeLeft": 12340,
|
||||
"targetVolumeM3": 0.005,
|
||||
"targetProgressPct": 41.6,
|
||||
"sumRain": 3.2,
|
||||
"avgRain": 0.13,
|
||||
"nextDate": 1746940800000
|
||||
}
|
||||
```
|
||||
|
||||
Concrete samples must come from a known-good test run. Regenerate when concern modules change shape.
|
||||
|
||||
## 9. Configuration — editor form ↔ config keys
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph editor["Node-RED editor form"]
|
||||
f1[Sampling time hr]
|
||||
f2[Sampling period hr]
|
||||
f3[Min volume L]
|
||||
f4[Max weight kg]
|
||||
f5[Empty bucket weight kg]
|
||||
f6[Flowmeter on/off]
|
||||
f7[Min sample interval s]
|
||||
end
|
||||
subgraph config["Domain config slice"]
|
||||
c1[constraints.samplingtime]
|
||||
c2[constraints.samplingperiod]
|
||||
c3[constraints.minVolume]
|
||||
c4[constraints.maxWeight]
|
||||
c5[asset.emptyWeightBucket]
|
||||
c6[constraints.flowmeter]
|
||||
c7[constraints.minSampleIntervalSec]
|
||||
end
|
||||
f1 --> c1
|
||||
f2 --> c2
|
||||
f3 --> c3
|
||||
f4 --> c4
|
||||
f5 --> c5
|
||||
f6 --> c6
|
||||
f7 --> c7
|
||||
```
|
||||
|
||||
| Form field | Config key | Default | Range | Where used |
|
||||
|---|---|---|---|---|
|
||||
| Sampling time (hr) | `constraints.samplingtime` | `0` | ≥ 0 | run length, `predFlow` |
|
||||
| Sampling period (hr) | `constraints.samplingperiod` | `24` | ≥ 1 | schedule arming |
|
||||
| Min volume (L) | `constraints.minVolume` | `5` | ≥ 5 | bounds + invalid-flow guard |
|
||||
| Max weight (kg) | `constraints.maxWeight` | `23` | ≤ 23 | bucket overload |
|
||||
| Empty bucket weight (kg) | `asset.emptyWeightBucket` | `3` | ≥ 0 | `bucketWeight` |
|
||||
| Sub-sample volume (mL) | `constraints.subSampleVolume` | `50` | fixed | per-pulse volume |
|
||||
| Flowmeter present | `constraints.flowmeter` | `true` | bool | ⚠️ In schema but NOT wired in `buildDomainConfig` — effectively always `true` at runtime. |
|
||||
| Min sample interval (s) | `constraints.minSampleIntervalSec` | `60` | ≥ 0 | cooldown guard |
|
||||
| Nominal flow min (m³/h) | `constraints.nominalFlowMin` | `0` | ≥ 0 | lower bound for rain-driven flow prediction band |
|
||||
| Flow max (m³/h) | `constraints.flowMax` | `0` | ≥ 0 | upper bound for rain-driven flow prediction band |
|
||||
| Max rain reference | `constraints.maxRainRef` | `10` | > 0 | rain-index that maps to `flowMax` |
|
||||
| Intake speed (m/s) | `constraints.intakeSpeed` | `0.3` | ≥ 0 | informational |
|
||||
| Intake diameter (mm) | `constraints.intakeDiameter` | `12` | ≥ 0 | informational |
|
||||
|
||||
## 10. State chart
|
||||
|
||||
Skipped — monster has no formal state machine. The `running` boolean toggles when `_beginRun` / `_endRun` fire. See section 7 for the sampling-program sequence, which is the closest analogue.
|
||||
|
||||
## 11. Examples
|
||||
|
||||
| Tier | File | What it shows | Status |
|
||||
|---|---|---|---|
|
||||
| Basic | `examples/basic.flow.json` | Inject + manual flow + dashboard, no parent | ✅ in repo |
|
||||
| Integration | `examples/integration.flow.json` | monster + measurement child + AQUON schedule | ✅ in repo |
|
||||
| Dashboard | `examples/monster-dashboard.flow.json` | Live FlowFuse charts (pulse, bucket, predFlow) | ✅ in repo |
|
||||
| Edge | `examples/edge.flow.json` | Cooldown guard + invalid-flow bounds | ✅ in repo |
|
||||
| API | `examples/monster-api-dashboard.flow.json` | dashboardAPI consumer wired in | ✅ in repo |
|
||||
|
||||
One screenshot per tier where helpful. PNG ≤ 200 KB under `wiki/_partial-screenshots/monster/`.
|
||||
|
||||
## 12. Debug recipes
|
||||
|
||||
| Symptom | First thing to check | Where to look |
|
||||
|---|---|---|
|
||||
| `pulse` never fires | Is `running` true? Check `validateFlowBounds` log — invalid bounds short-circuits the run. | `parameters/parameters.js` |
|
||||
| Pulses arrive too fast / skipped | Cooldown guard active. Inspect `missedSamples` + `minSampleIntervalSec`. | `sampling/samplingProgram.js → _maybeEmitPulse` |
|
||||
| `q` always zero | Measured-flow child not registered, manual flow not pushed. Watch Port 2 + `data.flow` history. | `flow/flowTracker.js` |
|
||||
| Measurement child ignored at register | Child's `config.asset.type` is set to something other than `"flow"` (e.g. `"flow-electromagnetic"`). Monster only accepts `asset.type = "flow"` or unset. Set `asset.type: "flow"` on the measurement node. | `specificClass.js → _wireMeasurementChild` |
|
||||
| `nextDate` not arming | `set.schedule` payload didn't include matching `aquonSampleName` row. | `schedule/schedule.js → regNextDate` |
|
||||
| `sumRain` zero with rain input | `rainAggregator.update` ran while `running=true` (skipped). | `specificClass.js → updateRainData` |
|
||||
| Bucket overfilled before `stop_time` | `m3PerPuls` rounded down; check `predFlow` vs effective `q`. | `sampling/samplingProgram.js → _beginRun` |
|
||||
| `flowmeter=false` has no effect | `constraints.flowmeter` is in the schema but not wired in `buildDomainConfig`. The sampling program always runs in proportional mode. | `src/nodeClass.js → buildDomainConfig` |
|
||||
|
||||
> Never ship `enableLog: 'debug'` in a demo — fills the container log within seconds and obscures real errors. Use only for live debugging.
|
||||
|
||||
## 13. When you would NOT use this node
|
||||
|
||||
- Use monster for **AQUON-scheduled composite sampling** on a wastewater plant. For a single grab sample on demand, fire `cmd.start` once and tear it down — monster is overkill for ad-hoc work.
|
||||
- Don't use monster as a generic flow totaliser. Use a `measurement` child with the right type/variant for raw flow integration.
|
||||
- Skip monster if you don't need pulse-proportional dosing — the time-mode (`flowmeter=false`) is currently informational only.
|
||||
|
||||
## 14. Known limitations / current issues
|
||||
|
||||
| # | Issue | Tracked in |
|
||||
|---|---|---|
|
||||
| 1 | Edge test `sampling-guards.edge.test.js` cooldown-guard case is a pre-existing failure — the cooldown skip increments `missedSamples` but the assertion expects a different timing. | `test/edge/sampling-guards.edge.test.js` |
|
||||
| 2 | `set.mode` and `set.model-prediction` are reserved — handlers delegate to optional methods that don't exist yet. | `commands/handlers.js` |
|
||||
| 3 | Time-only mode (`flowmeter=false`) is not exercised — the sampling program assumes a flow source. `constraints.flowmeter` is also not forwarded in `buildDomainConfig`. | `sampling/samplingProgram.js`, `src/nodeClass.js` |
|
||||
| 4 | Sub-sample volume hard-coded at 50 mL (schema enforces `min=max=50`). | `generalFunctions/src/configs/monster.json` |
|
||||
| 5 | S88 colour cleanup pending: node editor colour is `#4f8582` (teal) in `monster.html`. Correct Unit-level colour is `#50a8d9`. Section 2 diagram already uses the correct colour. The editor node tile must be updated separately. | `monster.html` → `color:` field |
|
||||
Reference in New Issue
Block a user