Compare commits

..

29 Commits

Author SHA1 Message Date
znetsixe
c60aa40666 update 2026-02-23 13:17:47 +01:00
znetsixe
1cfb36f604 agent updates 2026-02-12 10:14:56 +01:00
znetsixe
105a3082ab updates 2026-01-29 13:32:20 +01:00
znetsixe
cde331246c updates for asset registration 2026-01-29 10:22:12 +01:00
znetsixe
15c33d650b updates 2026-01-29 09:16:41 +01:00
znetsixe
a536c6ed5e update fetch function 2026-01-28 14:25:12 +01:00
znetsixe
266a6ed4a3 updates 2026-01-28 14:04:22 +01:00
znetsixe
37796c3e3b Merge remote-tracking branch 'origin/main' into dev-Rene 2025-12-19 11:50:14 +01:00
znetsixe
067017f2ea bug fix 2025-11-30 17:45:45 +01:00
znetsixe
52f1cf73b4 bug fixes 2025-11-30 09:24:29 +01:00
pimmoerman
858189d6da Update get_all_assets.php vanaf tagcode.app 2025-11-21 03:00:01 +00:00
pimmoerman
ec42ebcb25 Update get_all_assets.php vanaf tagcode.app 2025-11-20 12:15:55 +00:00
pimmoerman
f4629e5fcc Update get_all_assets.php vanaf extern endpoint 2025-11-17 15:57:29 +00:00
pimmoerman
dafe4c5336 Delete datasets/tagcodeapp_product_models.json 2025-11-17 15:57:15 +00:00
pimmoerman
5439d5111a Delete datasets/tagcodeapp_assets.json 2025-11-17 15:57:08 +00:00
pimmoerman
1e5ef47a4d Delete datasets/get_all_assets.php 2025-11-17 15:57:02 +00:00
pimmoerman
2b87c67876 Update get_all_assets.php vanaf extern endpoint 2025-11-17 15:00:01 +00:00
pimmoerman
0db90c0e4b Delete data/get_all_assets.php 2025-11-17 14:58:33 +00:00
pimmoerman
1e07093101 Update get_all_assets.php vanaf extern endpoint 2025-11-17 14:58:01 +00:00
p.vanderwilt
ce25ee930a Add ammonium and NOx quantity sensors to assetData 2025-11-12 10:47:41 +01:00
p.vanderwilt
a293e0286a Merge pull request 'Add addtional and updated configs' (#12) from dev-Pieter into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/generalFunctions/pulls/12
2025-11-06 14:01:32 +00:00
012b8a7ff6 Merge pull request 'Merging to latest updates' (#10) from dev-Rene into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/generalFunctions/pulls/10
2025-11-03 14:24:58 +00:00
p.vanderwilt
d5d078413c Add flowNumber configuration to define effluent flow handling 2025-10-31 14:03:54 +01:00
p.vanderwilt
17662ef7cb Add total suspended solids sensor to assetData 2025-10-31 13:53:35 +01:00
p.vanderwilt
9d8da15d0e Merge pull request 'Register multiple parents during child registration' (#9) from dev-Pieter into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/generalFunctions/pulls/9
2025-10-31 10:36:28 +00:00
d503cf5dc9 Merge pull request 'Added does measurement exist in measurement' (#8) from dev-Rene into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/generalFunctions/pulls/8
2025-10-24 19:20:31 +00:00
p.vanderwilt
f653a1e98c Refactor child setup to support multiple parents consistently 2025-10-24 13:37:26 +02:00
p.vanderwilt
3886277616 Fix bug in parent registration code block 2025-09-29 17:13:34 +02:00
p.vanderwilt
83018fabe0 Allow for multiple parents 2025-09-29 16:06:06 +02:00
49 changed files with 4158 additions and 1706 deletions

View File

@@ -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³"]
}
]
} }
] ]
} }

View File

@@ -11,39 +11,39 @@
"id": "temperature", "id": "temperature",
"name": "Temperature", "name": "Temperature",
"models": [ "models": [
{ "id": "vega-temp-10", "name": "VegaTemp 10", "units": ["degC", "degF"] }, { "id": "vega-temp-10", "name": "VegaTemp 10", "units": ["degC", "degF"], "product_model_id": 1001, "product_model_uuid": "vega-temp-10" },
{ "id": "vega-temp-20", "name": "VegaTemp 20", "units": ["degC", "degF"] } { "id": "vega-temp-20", "name": "VegaTemp 20", "units": ["degC", "degF"], "product_model_id": 1002, "product_model_uuid": "vega-temp-20" }
] ]
}, },
{ {
"id": "pressure", "id": "pressure",
"name": "Pressure", "name": "Pressure",
"models": [ "models": [
{ "id": "vega-pressure-10", "name": "VegaPressure 10", "units": ["bar", "mbar", "psi"] }, { "id": "vega-pressure-10", "name": "VegaPressure 10", "units": ["bar", "mbar", "psi"], "product_model_id": 1003, "product_model_uuid": "vega-pressure-10" },
{ "id": "vega-pressure-20", "name": "VegaPressure 20", "units": ["bar", "mbar", "psi"] } { "id": "vega-pressure-20", "name": "VegaPressure 20", "units": ["bar", "mbar", "psi"], "product_model_id": 1004, "product_model_uuid": "vega-pressure-20" }
] ]
}, },
{ {
"id": "flow", "id": "flow",
"name": "Flow", "name": "Flow",
"models": [ "models": [
{ "id": "vega-flow-10", "name": "VegaFlow 10", "units": ["m3/h", "gpm", "l/min"] }, { "id": "vega-flow-10", "name": "VegaFlow 10", "units": ["m3/h", "gpm", "l/min"], "product_model_id": 1005, "product_model_uuid": "vega-flow-10" },
{ "id": "vega-flow-20", "name": "VegaFlow 20", "units": ["m3/h", "gpm", "l/min"] } { "id": "vega-flow-20", "name": "VegaFlow 20", "units": ["m3/h", "gpm", "l/min"], "product_model_id": 1006, "product_model_uuid": "vega-flow-20" }
] ]
}, },
{ {
"id": "level", "id": "level",
"name": "Level", "name": "Level",
"models": [ "models": [
{ "id": "vega-level-10", "name": "VegaLevel 10", "units": ["m", "ft", "mm"] }, { "id": "vega-level-10", "name": "VegaLevel 10", "units": ["m", "ft", "mm"], "product_model_id": 1007, "product_model_uuid": "vega-level-10" },
{ "id": "vega-level-20", "name": "VegaLevel 20", "units": ["m", "ft", "mm"] } { "id": "vega-level-20", "name": "VegaLevel 20", "units": ["m", "ft", "mm"], "product_model_id": 1008, "product_model_uuid": "vega-level-20" }
] ]
}, },
{ {
"id": "oxygen", "id": "oxygen",
"name": "Quantity (oxygen)", "name": "Quantity (oxygen)",
"models": [ "models": [
{ "id": "vega-oxy-10", "name": "VegaOxySense 10", "units": ["g/m3", "mol/m3"] } { "id": "vega-oxy-10", "name": "VegaOxySense 10", "units": ["g/m3", "mol/m3"], "product_model_id": 1009, "product_model_uuid": "vega-oxy-10" }
] ]
} }
] ]

View File

@@ -0,0 +1,716 @@
{
"samples": [
{
"code": "106100",
"description": "Baarle Nassau influent totaal"
},
{
"code": "106100C",
"description": "RWZI Baarle Nassau influent - Monstername influent COVID-19"
},
{
"code": "106120",
"description": "Baarle Nassau inhoud beluchtingsruimte"
},
{
"code": "106150",
"description": "Baarle Nassau effluent"
},
{
"code": "106209",
"description": "Baarle Nassau slibafvoer voorindikker"
},
{
"code": "106400",
"description": "Baarle Nassau slibafvoer slibbufferput"
},
{
"code": "109100",
"description": "RWZI Chaam influent totaal"
},
{
"code": "109100C",
"description": "RWZI Chaam influent - Monstername influent COVID-19"
},
{
"code": "109120",
"description": "RWZI Chaam inhoud beluchtingstank"
},
{
"code": "109150",
"description": "RWZI Chaam effluent"
},
{
"code": "109153",
"description": "RWZI Chaam afloop cascade"
},
{
"code": "109400",
"description": "Chaam slib afvoer slibbufferput"
},
{
"code": "112004",
"description": "RWZI Dongemond diverse onderzoeken"
},
{
"code": "112062",
"description": "RWZI Dongemond RUWE(geleverde) PE zeefbandpers"
},
{
"code": "112100",
"description": "RWZI Dongemond influent totaal"
},
{
"code": "112100C",
"description": "RWZI Dongemond influent - Monstername influent COVID-19"
},
{
"code": "112110",
"description": "RWZI Dongemond afloop voorbezinktank"
},
{
"code": "112121",
"description": "RWZI Dongemond inhoud beluchtingstank 1"
},
{
"code": "112122",
"description": "RWZI Dongemond inhoud beluchtingstank 2"
},
{
"code": "112123",
"description": "RWZI Dongemond inhoud beluchtingstank 3"
},
{
"code": "112124",
"description": "RWZI Dongemond inhoud beluchtingstank 4"
},
{
"code": "112150",
"description": "RWZI Dongemond effluent"
},
{
"code": "112203",
"description": "RWZI Dongemond inhoud container zandvanger"
},
{
"code": "112206",
"description": "RWZI Dongemond ingedikt primair slib"
},
{
"code": "112211",
"description": "RWZI Dongemond ingedikt secundair slib"
},
{
"code": "112231",
"description": "RWZI Dongemond afvoer bandindikker"
},
{
"code": "112244",
"description": "RWZI Dongemond inhoud gistingstank"
},
{
"code": "112287",
"description": "RWZI Dongemond waterafvoer zeefbandpers totaal"
},
{
"code": "112425",
"description": "RWZI Dongemond afvoer slibkoek silo"
},
{
"code": "112569",
"description": "RWZI Dongemond Al2(SO4)3"
},
{
"code": "115100",
"description": "RWZI Kaatsheuvel influent totaal"
},
{
"code": "115100C",
"description": "RWZI Kaatsheuvel influent - Monstername influent COVID-19"
},
{
"code": "115120",
"description": "RWZI Kaatsheuvel inhoud beluchtingsruimte"
},
{
"code": "115150",
"description": "RWZI Kaatsheuvel effluent"
},
{
"code": "115155",
"description": "RWZI Kaatsheuvel toevoer zandfilter"
},
{
"code": "115156",
"description": "RWZI Kaatsheuvel afvoer zandfilter"
},
{
"code": "115157",
"description": "RWZI Kaatsheuvel afvoer waswater zandfilter"
},
{
"code": "115166",
"description": "RWZI Kaatsheuvel Voor UV filter"
},
{
"code": "115167",
"description": "RWZI Kaatsheuvel Na UV filter"
},
{
"code": "115203",
"description": "RWZI Kaatsheuvel inhoud container zandvanger"
},
{
"code": "115209",
"description": "RWZI Kaatsheuvel slibafvoer voorindikker"
},
{
"code": "115400",
"description": "RWZI Kaatsheuvel slibafvoer slibbufferput"
},
{
"code": "116100",
"description": "RWZI Lage-Zwaluwe influent totaal"
},
{
"code": "116100C",
"description": "RWZI Lage-Zwaluwe influent - Monstername influent COVID-19"
},
{
"code": "116120",
"description": "RWZI Lage-Zwaluwe inhoud beluchtingsruimte"
},
{
"code": "116150",
"description": "RWZI Lage-Zwaluwe effluent"
},
{
"code": "116400",
"description": "RWZI Lage-Zwaluwe slibafvoer slibbufferput"
},
{
"code": "121100",
"description": "RWZI Riel influent totaal"
},
{
"code": "121100C",
"description": "RWZI Riel influent - Monstername influent COVID-19"
},
{
"code": "121120",
"description": "RWZI Riel inhoud beluchtingruimte"
},
{
"code": "121150",
"description": "RWZI Riel effluent"
},
{
"code": "121203",
"description": "RWZI Riel inhoud container zandvanger"
},
{
"code": "121400",
"description": "RWZI Riel slibafvoer slibbufferput"
},
{
"code": "124089",
"description": "RWZI Rijen aanvoer kolkenzuigermateriaal"
},
{
"code": "124100",
"description": "RWZI Rijen influent totaal"
},
{
"code": "124100C",
"description": "RWZI Rijen influent - Monstername influent COVID-19"
},
{
"code": "124110",
"description": "RWZI Rijen afloop voorbezinktank"
},
{
"code": "124120",
"description": "RWZI Rijen inhoud beluchtingsruimte"
},
{
"code": "124150",
"description": "RWZI Rijen effluent"
},
{
"code": "124151",
"description": "RWZI Rijen effluent voor legionella"
},
{
"code": "124203",
"description": "RWZI Rijen inhoud container zandvanger"
},
{
"code": "124206",
"description": "RWZI Rijen ingedikt primair slib"
},
{
"code": "124211",
"description": "RWZI Rijen ingedikt secundair slib"
},
{
"code": "124350",
"description": "RWZI Rijen Toevoer bandindikker"
},
{
"code": "124351",
"description": "RWZI Rijen Afvoer bandindikker"
},
{
"code": "124352",
"description": "RWZI Rijen waterafvoer bandindikker"
},
{
"code": "124400",
"description": "RWZI Rijen slibafvoer"
},
{
"code": "124540",
"description": "RWZI Rijen RUWE(geleverde) PE bandindikker"
},
{
"code": "127100",
"description": "RWZI Waalwijk influent totaal"
},
{
"code": "127100C",
"description": "RWZI Waalwijk influent - Monstername influent COVID-19"
},
{
"code": "127110",
"description": "RWZI Waalwijk afloop VBT"
},
{
"code": "127121",
"description": "RWZI Waalwijk inhoud beluchtingsruimte 1"
},
{
"code": "127122",
"description": "RWZI Waalwijk inhoud beluchtingsruimte 2"
},
{
"code": "127150",
"description": "RWZI Waalwijk effluent"
},
{
"code": "127203",
"description": "RWZI Waalwijk inhoud container zandvanger"
},
{
"code": "127206",
"description": "RWZI Waalwijk ingedikt primair slib"
},
{
"code": "127211",
"description": "RWZI Waalwijk ingedikt secundair slib"
},
{
"code": "127244",
"description": "RWZI Waalwijk inhoud gistingstank"
},
{
"code": "127450",
"description": "RWZI Waalwijk slibafvoer indiklagune"
},
{
"code": "131100",
"description": "RWZI Waspik industrie & dorp influent totaal"
},
{
"code": "131100C",
"description": "RWZI Waspik influent - Monstername influent COVID-19"
},
{
"code": "131120",
"description": "RWZI Waspik inhoud beluchtingsruimte"
},
{
"code": "131150",
"description": "RWZI Waspik effluent"
},
{
"code": "131400",
"description": "RWZI Waspik slibafvoer slibbufferput"
},
{
"code": "131581",
"description": "Waspik Levering Aluminiumchloride 9%"
},
{
"code": "142062",
"description": "RWZI Nieuwveer RUWE(geleverde) PE zeefbandpers"
},
{
"code": "142078",
"description": "RWZI Nieuwveer Cloetta suikerwater"
},
{
"code": "142089",
"description": "RWZI Nieuwveer aanvoer kolkenzuigermateriaal"
},
{
"code": "142105",
"description": "RWZI Nieuwveer afloop influentvijzels"
},
{
"code": "142105C",
"description": "RWZI Nieuwveer afloop influentvijzels - Monstername influent COVID-19"
},
{
"code": "142110",
"description": "RWZI Nieuwveer afloop TBT"
},
{
"code": "142121",
"description": "RWZI Nieuwveer inhoud beluchtingsruimte 1"
},
{
"code": "142122",
"description": "RWZI Nieuwveer inhoud beluchtingsruimte 2"
},
{
"code": "142123",
"description": "RWZI Nieuwveer inhoud beluchtingsruimte 3"
},
{
"code": "142124",
"description": "RWZI Nieuwveer inhoud beluchtingsruimte 4"
},
{
"code": "142150",
"description": "RWZI Nieuwveer effluent"
},
{
"code": "142174",
"description": "RWZI Nieuwveer secundair spuislib"
},
{
"code": "142203",
"description": "RWZI Nieuwveer inhoud container zandvanger"
},
{
"code": "142301",
"description": "RWZI Nieuwveer slibafvoer Bandindikker 1"
},
{
"code": "142302",
"description": "RWZI Nieuwveer slibafvoer Bandindikker 2"
},
{
"code": "142303",
"description": "RWZI Nieuwveer slibafvoer Bandindikker 3"
},
{
"code": "142310",
"description": "RWZI Nieuwveer monitor slibafvoer ESOMT"
},
{
"code": "142311",
"description": "RWZI Nieuwveer afloop Gisting"
},
{
"code": "142325",
"description": "RWZI Nieuwveer Influent DEMON"
},
{
"code": "142326",
"description": "RWZI Nieuwveer Inhoud DEMON"
},
{
"code": "142327",
"description": "RWZI Nieuwveer Effluent DEMON"
},
{
"code": "142332",
"description": "RWZI Nieuwveer retourwater slibverwerking"
},
{
"code": "142425",
"description": "RWZI Nieuwveer afvoer slibkoek silo"
},
{
"code": "142571",
"description": "RWZI Nieuwveer ijzersulfaat levering totaal"
},
{
"code": "144007",
"description": "Bouvigne Toevoer helofytenfilter"
},
{
"code": "144008",
"description": "Bouvigne Afvoer helofytenfilter"
},
{
"code": "144061",
"description": "144061 (toevoer verticale helofytenfilters)"
},
{
"code": "144062",
"description": "144062 (afvoer verticale helofytenfilters)"
},
{
"code": "144063",
"description": "144063 (afvoer horizontale helofytenfilters)"
},
{
"code": "144064",
"description": "144064 (kwaliteit voorberging)"
},
{
"code": "160061",
"description": "RWZI Bath RUWE(geleverde) PE bandindikker"
},
{
"code": "160062",
"description": "RWZI Bath RUWE(geleverde) PE zeefbandpers"
},
{
"code": "160100",
"description": "Bath influent totaal"
},
{
"code": "160100C",
"description": "RWZI Bath influent - Monstername influent COVID-19"
},
{
"code": "160110",
"description": "Bath Afloop Voorbezinktank West (1 en 3)"
},
{
"code": "160112",
"description": "Bath Afloop Voorbezinktank Oost (2 en 4)"
},
{
"code": "160121",
"description": "Bath inhoud beluchtingsruimte 1, sectie 4"
},
{
"code": "160122",
"description": "Bath inhoud beluchtingsruimte 2, sectie 4"
},
{
"code": "160123",
"description": "Bath inhoud beluchtingsruimte 3, sectie 4"
},
{
"code": "160124",
"description": "Bath inhoud beluchtingsruimte 4, sectie 4"
},
{
"code": "160125",
"description": "Bath inhoud beluchtingsruimte 5, sectie 4"
},
{
"code": "160126",
"description": "Bath inhoud beluchtingsruimte 6, sectie 4"
},
{
"code": "160127",
"description": "Bath inhoud beluchtingsruimte 7, sectie 4"
},
{
"code": "160128",
"description": "Bath inhoud beluchtingsruimte 8, sectie 4"
},
{
"code": "160129",
"description": "Bath inhoud beluchtingsruimte 9, sectie 4"
},
{
"code": "160130",
"description": "Bath inhoud beluchtingsruimte 10, sectie 4"
},
{
"code": "160150",
"description": "Bath effluent"
},
{
"code": "160206",
"description": "Bath ingedikt primair slib"
},
{
"code": "160245",
"description": "Bath inhoud gistingstank 1 ZB"
},
{
"code": "160246",
"description": "Bath inhoud gistingstank 2 ZB"
},
{
"code": "160415",
"description": "Bath 160415 Ingedikt Sec.slib BI 1-4 (Buffer)"
},
{
"code": "160425",
"description": "Bath afvoer slibkoek silo"
},
{
"code": "169100",
"description": "RWZI Dinteloord influent totaal"
},
{
"code": "169100C",
"description": "RWZI Dinteloord influent - Monstername influent COVID-19"
},
{
"code": "169120",
"description": "RWZI Dinteloord inhoud beluchtingsruimte"
},
{
"code": "169150",
"description": "RWZI Dinteloord effluent"
},
{
"code": "169209",
"description": "RWZI Dinteloord slibafvoer voorindikker"
},
{
"code": "169400",
"description": "RWZI Dinteloord slibafvoer slibbufferput"
},
{
"code": "169700",
"description": "RWZI Dinteloord Peilbuis ref 01"
},
{
"code": "169705",
"description": "RWZI Dinteloord Peilbuis ref 02"
},
{
"code": "169710",
"description": "RWZI Dinteloord Peilbuis 03"
},
{
"code": "169715",
"description": "RWZI Dinteloord Peilbuis 04"
},
{
"code": "169720",
"description": "RWZI Dinteloord Peilbuis 05"
},
{
"code": "172100",
"description": "RWZI Halsteren influent"
},
{
"code": "172100C",
"description": "RWZI Halsteren influent - Monstername influent COVID-19"
},
{
"code": "172120",
"description": "RWZI Halsteren inhoud beluchtingsruimte"
},
{
"code": "172150",
"description": "RWZI Halsteren effluent"
},
{
"code": "172209",
"description": "RWZI Halsteren slibafvoer voorindikker"
},
{
"code": "172400",
"description": "RWZI Halsteren slibafvoer slibbufferput"
},
{
"code": "181100",
"description": "RWZI Nieuw-Vossemeer influent totaal"
},
{
"code": "181100C",
"description": "RWZI Nieuw-Vossemeer influent - Monstername influent COVID-19"
},
{
"code": "181120",
"description": "RWZI Nieuw-Vossemeer inhoud beluchtingsruimte"
},
{
"code": "181150",
"description": "RWZI Nieuw-Vossemeer Effluent steekmonster"
},
{
"code": "181156",
"description": "RWZI Nieuw-Vossemeer Effluent waterharmonica steekmonster"
},
{
"code": "181400",
"description": "Nieuw Vossemeer slibafvoer slibbufferput"
},
{
"code": "184100",
"description": "RWZI Ossendrecht influent totaal"
},
{
"code": "184100C",
"description": "RWZI Ossendrecht influent - Monstername influent COVID-19"
},
{
"code": "184120",
"description": "RWZI Ossendrecht inhoud beluchtingsruimte"
},
{
"code": "184150",
"description": "RWZI Ossendrecht effluent"
},
{
"code": "184460",
"description": "RWZI Ossendrecht afvoer slibpersleiding naar AWP"
},
{
"code": "191100",
"description": "RWZI Putte influent totaal"
},
{
"code": "191100C",
"description": "RWZI Putte influent - Monstername influent COVID-19"
},
{
"code": "191120",
"description": "RWZI Putte inhoud beluchtingsruimte"
},
{
"code": "191150",
"description": "RWZI Putte effluent"
},
{
"code": "191460",
"description": "RWZI Putte afvoer slibpersleiding naar AWP"
},
{
"code": "196100",
"description": "RWZI Willemstad influent totaal"
},
{
"code": "196100C",
"description": "RWZI Willemstad influent - Monstername influent COVID-19"
},
{
"code": "196120",
"description": "RWZI Willemstad inhoud beluchtingsruimte"
},
{
"code": "196150",
"description": "RWZI Willemstad effluent"
},
{
"code": "196400",
"description": "RWZI Willemstad slibafvoer slibbufferput"
},
{
"code": "303203",
"description": "Persstation Bergen op Zoom inh. container zandvang"
},
{
"code": "312203",
"description": "AWP persstation Roosendaal inh. container zandvang"
},
{
"code": "WSBD Toeslag Weekendbemonsteri",
"description": "WSBD Toeslag Weekendbemonsteringen"
}
]
}

File diff suppressed because it is too large Load Diff

View 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

View File

@@ -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": []
}
]
}

View File

@@ -8,24 +8,27 @@
*/ */
// Core helper modules // Core helper modules
const outputUtils = require('./src/helper/outputUtils.js'); const helper = require('./src/helper/index.js');
const logger = require('./src/helper/logger.js'); const {
const validation = require('./src/helper/validationUtils.js'); outputUtils,
const configUtils = require('./src/helper/configUtils.js'); logger,
const assertions = require('./src/helper/assertionUtils.js') validation,
configUtils,
assertions,
childRegistrationUtils,
gravity,
} = helper;
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') const assetApiConfig = require('./src/configs/assetApiConfig.js');
// Domain-specific modules // Domain-specific modules
const { MeasurementContainer } = require('./src/measurements/index.js'); const { MeasurementContainer } = require('./src/measurements/index.js');
const configManager = require('./src/configs/index.js'); const configManager = require('./src/configs/index.js');
const nrmse = require('./src/nrmse/errorMetrics.js'); const { nrmse } = require('./src/nrmse/index.js');
const state = require('./src/state/state.js'); const { state } = require('./src/state/index.js');
const convert = require('./src/convert/index.js'); const convert = require('./src/convert/index.js');
const MenuManager = require('./src/menu/index.js'); const MenuManager = require('./src/menu/index.js');
const predict = require('./src/predict/predict_class.js'); const { predict, interpolation } = require('./src/predict/index.js');
const interpolation = require('./src/predict/interpolation.js');
const childRegistrationUtils = require('./src/helper/childRegistrationUtils.js');
const { loadCurve } = require('./datasets/assetData/curves/index.js'); //deprecated replace with load model data const { loadCurve } = require('./datasets/assetData/curves/index.js'); //deprecated replace with load model data
const { loadModel } = require('./datasets/assetData/modelData/index.js'); const { loadModel } = require('./datasets/assetData/modelData/index.js');
@@ -34,6 +37,7 @@ module.exports = {
predict, predict,
interpolation, interpolation,
configManager, configManager,
assetApiConfig,
outputUtils, outputUtils,
configUtils, configUtils,
logger, logger,

View File

@@ -9,11 +9,16 @@
"./menuUtils": "./src/helper/menuUtils.js", "./menuUtils": "./src/helper/menuUtils.js",
"./mathUtils": "./src/helper/mathUtils.js", "./mathUtils": "./src/helper/mathUtils.js",
"./assetUtils": "./src/helper/assetUtils.js", "./assetUtils": "./src/helper/assetUtils.js",
"./outputUtils": "./src/helper/outputUtils.js" "./outputUtils": "./src/helper/outputUtils.js",
"./helper": "./src/helper/index.js",
"./state": "./src/state/index.js",
"./predict": "./src/predict/index.js",
"./nrmse": "./src/nrmse/index.js",
"./outliers": "./src/outliers/index.js"
}, },
"scripts": { "scripts": {
"test": "node test.js" "test": "node --test test/*.test.js src/nrmse/errorMetric.test.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -26,4 +31,4 @@
], ],
"author": "Rene de Ren", "author": "Rene de Ren",
"license": "SEE LICENSE" "license": "SEE LICENSE"
} }

View File

@@ -0,0 +1,16 @@
const BASE_URL = 'http://localhost:8000';
const AUTHORIZATION = '4a49332a-fc3e-11f0-bf0a-9457f8d645d9';
const CSRF_TOKEN = 'dcWLY6luSVuQu4mIlKNCGlk3i9VzG9n3p2pxihcm';
module.exports = {
baseUrl: BASE_URL,
registerPath: '/assets/store',
updatePath: (tag) => `/assets/${encodeURIComponent(tag)}/edit`,
updateMethod: 'POST',
headers: {
accept: 'application/json',
Authorization: AUTHORIZATION,
'Content-Type': 'application/json',
'X-CSRF-TOKEN': CSRF_TOKEN
}
};

View File

@@ -117,6 +117,14 @@
"description": "Asset tag code which is a unique identifier for this asset. May be null if not assigned." "description": "Asset tag code which is a unique identifier for this asset. May be null if not assigned."
} }
}, },
"tagNumber": {
"default": null,
"rules": {
"type": "string",
"nullable": true,
"description": "Asset tag number assigned by the asset registry. May be null if not assigned."
}
},
"geoLocation": { "geoLocation": {
"default": { "default": {
"x": 0, "x": 0,
@@ -166,6 +174,10 @@
{ {
"value": "sensor", "value": "sensor",
"description": "A device that detects or measures a physical property and responds to it (e.g. temperature sensor)." "description": "A device that detects or measures a physical property and responds to it (e.g. temperature sensor)."
},
{
"value": "measurement",
"description": "Measurement software category used by the asset menu for this node."
} }
] ]
} }
@@ -208,6 +220,52 @@
} }
} }
}, },
"assetRegistration": {
"default": {
"profileId": 1,
"locationId": 1,
"processId": 1,
"status": "actief",
"childAssets": []
},
"rules": {
"type": "object",
"schema": {
"profileId": {
"default": 1,
"rules": {
"type": "number"
}
},
"locationId": {
"default": 1,
"rules": {
"type": "number"
}
},
"processId": {
"default": 1,
"rules": {
"type": "number"
}
},
"status": {
"default": "actief",
"rules": {
"type": "string"
}
},
"childAssets": {
"default": [],
"rules": {
"type": "array",
"itemType": "string",
"minLength": 0
}
}
}
}
},
"scaling": { "scaling": {
"enabled": { "enabled": {
"default": false, "default": false,

View File

@@ -16,7 +16,7 @@
} }
}, },
"unit": { "unit": {
"default": "m3/s", "default": "l/s",
"rules": { "rules": {
"type": "string", "type": "string",
"description": "The default measurement unit for this configuration (e.g., 'meters', 'seconds', 'unitless')." "description": "The default measurement unit for this configuration (e.g., 'meters', 'seconds', 'unitless')."
@@ -435,6 +435,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."
}
} }
} }

View File

@@ -16,7 +16,7 @@ class Assertions {
assertNoNaN(arr, label = "array") { assertNoNaN(arr, label = "array") {
if (Array.isArray(arr)) { if (Array.isArray(arr)) {
for (const el of arr) { for (const el of arr) {
assertNoNaN(el, label); this.assertNoNaN(el, label);
} }
} else { } else {
if (Number.isNaN(arr)) { if (Number.isNaN(arr)) {
@@ -26,4 +26,4 @@ class Assertions {
} }
} }
module.exports = Assertions; module.exports = Assertions;

View File

@@ -1,3 +1,244 @@
export function getAssetVariables() { const http = require('node:http');
const https = require('node:https');
const { URL } = require('node:url');
const { assetCategoryManager } = require('../../datasets/assetData');
} function toNumber(value, fallback = 1) {
const result = Number(value);
return Number.isFinite(result) && result > 0 ? result : fallback;
}
function toArray(value = []) {
if (Array.isArray(value)) {
return value.filter((item) => typeof item !== 'undefined' && item !== null);
}
if (typeof value === 'string' && value.trim()) {
return [value.trim()];
}
if (typeof value === 'number') {
return [value];
}
return [];
}
function findModelMetadata(selection = {}) {
if (!selection) {
return null;
}
const categoryKey = selection.softwareType || 'measurement';
if (!assetCategoryManager.hasCategory(categoryKey)) {
return null;
}
const suppliers = assetCategoryManager.getCategory(categoryKey).suppliers || [];
const supplierMatch = (entry, value) => {
if (!entry || !value) return false;
const key = value.toString().toLowerCase();
return (
(entry.id && entry.id.toLowerCase() === key) ||
(entry.name && entry.name.toLowerCase() === key)
);
};
const supplier = suppliers.find((item) => supplierMatch(item, selection.supplier));
const types = supplier?.types || [];
const type = types.find((item) => supplierMatch(item, selection.assetType));
const models = type?.models || [];
const model = models.find((item) => supplierMatch(item, selection.model));
return model || null;
}
function buildAssetPayload({ assetSelection = {}, registrationDefaults = {} }) {
const defaults = {
profileId: 1,
locationId: 1,
processId: 1,
status: 'actief',
childAssets: [],
...registrationDefaults
};
const metadata = assetSelection.modelMetadata || findModelMetadata(assetSelection) || {};
const rawName = assetSelection.assetName || assetSelection.name || assetSelection.assetType || assetSelection.model;
const assetName = (rawName || 'Measurement asset').toString();
const assetDescription = (assetSelection.assetDescription || assetSelection.description || assetName).toString();
const modelId = metadata.product_model_id ?? metadata.id ?? assetSelection.modelId ?? assetSelection.model ?? null;
const payload = {
profile_id: toNumber(defaults.profileId, 1),
location_id: toNumber(defaults.locationId, 1),
process_id: toNumber(defaults.processId, 1),
asset_name: assetName,
asset_description: assetDescription,
asset_status: (assetSelection.assetStatus || defaults.status || 'actief').toString(),
product_model_id: modelId,
product_model_uuid: metadata.product_model_uuid || metadata.uuid || null,
child_assets: toArray(defaults.childAssets)
};
const validation = [];
const missing = [];
const tooLong = [];
const invalid = [];
if (!payload.asset_name) {
missing.push('asset_name');
} else if (payload.asset_name.length > 100) {
tooLong.push('asset_name');
}
if (!payload.asset_status) {
missing.push('asset_status');
} else if (payload.asset_status.length > 20) {
tooLong.push('asset_status');
}
if (!Number.isInteger(payload.location_id)) {
invalid.push('location_id');
}
if (!Number.isInteger(payload.process_id)) {
invalid.push('process_id');
}
if (!Number.isInteger(payload.profile_id)) {
invalid.push('profile_id');
}
if (!Number.isInteger(payload.product_model_id)) {
invalid.push('product_model_id');
}
if (!Array.isArray(payload.child_assets)) {
invalid.push('child_assets');
}
if (missing.length) {
validation.push(`missing: ${missing.join(', ')}`);
}
if (tooLong.length) {
validation.push(`too long: ${tooLong.join(', ')}`);
}
if (invalid.length) {
validation.push(`invalid type: ${invalid.join(', ')}`);
}
if (validation.length) {
console.warn('[assetUtils] payload validation', validation.join(' | '));
} else {
console.info('[assetUtils] payload validation ok');
}
const tagNumber = typeof assetSelection.tagNumber === 'string' && assetSelection.tagNumber.trim()
? assetSelection.tagNumber.trim()
: null;
return {
payload,
tagNumber,
isUpdate: Boolean(tagNumber)
};
}
function normalizeHeaders(headers = {}, body = '') {
const normalized = { ...headers };
if (!Object.prototype.hasOwnProperty.call(normalized, 'Content-Length')) {
normalized['Content-Length'] = Buffer.byteLength(body);
}
return normalized;
}
function prepareUrl(baseUrl = '', path = '') {
const trimmedBase = (baseUrl || '').replace(/\/+$/g, '').replace(/\\/g, '/');
const trimmedPath = path.startsWith('/') ? path : `/${path}`;
if (!trimmedBase) {
return trimmedPath;
}
return `${trimmedBase}${trimmedPath}`;
}
function sendHttpRequest(url, method, headers = {}, body = '') {
const parsedUrl = new URL(url, 'http://localhost');
const agent = parsedUrl.protocol === 'https:' ? https : http;
const requestOptions = {
method,
hostname: parsedUrl.hostname,
port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
path: `${parsedUrl.pathname}${parsedUrl.search}`,
headers: normalizeHeaders(headers, body)
};
return new Promise((resolve, reject) => {
const req = agent.request(requestOptions, (res) => {
let raw = '';
res.setEncoding('utf8');
res.on('data', (chunk) => { raw += chunk; });
res.on('end', () => resolve({ status: res.statusCode, body: raw }));
});
req.on('error', reject);
if (body) {
req.write(body);
}
req.end();
});
}
function parseApiResponse(raw, status) {
try {
const parsed = JSON.parse(raw);
return {
success: parsed.success === true,
data: parsed.data || null,
message: parsed.message || (status >= 400 ? `HTTP ${status}` : 'Result returned')
};
} catch (error) {
return {
success: false,
data: raw,
message: `Unable to decode asset API response: ${error.message}`
};
}
}
async function syncAsset({ assetSelection = {}, registrationDefaults = {}, apiConfig = {}, nodeContext = {} }) {
const { payload, tagNumber, isUpdate } = buildAssetPayload({ assetSelection, registrationDefaults });
if (!apiConfig || !apiConfig.baseUrl) {
const message = 'Asset API configuration is missing';
console.warn('[assetUtils] ' + message, { nodeContext });
return { success: false, data: null, message };
}
const path = isUpdate && tagNumber && typeof apiConfig.updatePath === 'function'
? apiConfig.updatePath(tagNumber)
: apiConfig.registerPath;
const url = prepareUrl(apiConfig.baseUrl, path);
const method = isUpdate ? (apiConfig.updateMethod || 'PUT') : 'POST';
const headers = apiConfig.headers || {};
console.info('[assetUtils] Sending asset update', { nodeContext, method, url });
try {
const response = await sendHttpRequest(url, method, headers, JSON.stringify(payload));
const parsed = parseApiResponse(response.body, response.status);
return {
success: parsed.success,
data: parsed.data,
message: parsed.message
};
} catch (error) {
console.error('[assetUtils] Asset API request failed', error, { nodeContext });
return {
success: false,
data: null,
message: `Asset API request error: ${error.message}`
};
}
}
module.exports = {
syncAsset,
buildAssetPayload,
findModelMetadata
};

View File

@@ -6,13 +6,27 @@ class ChildRegistrationUtils {
} }
async registerChild(child, positionVsParent, distance) { async registerChild(child, positionVsParent, distance) {
const { softwareType } = child.config.functionality; if (!child || typeof child !== 'object') {
const { name, id } = child.config.general; this.logger?.warn('registerChild skipped: invalid child payload');
return false;
}
if (!child.config?.functionality || !child.config?.general) {
this.logger?.warn('registerChild skipped: missing child config/functionality/general');
return false;
}
const softwareType = child.config.functionality.softwareType;
const name = child.config.general.name || child.config.general.id || 'unknown';
const id = child.config.general.id || name;
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
@@ -39,19 +53,21 @@ class ChildRegistrationUtils {
} }
this.logger.info(`✅ Child ${name} registered successfully`); this.logger.info(`✅ Child ${name} registered successfully`);
return true;
} }
_storeChild(child, softwareType) { _storeChild(child, softwareType) {
// Maintain your existing structure // Maintain your existing structure
if (!this.mainClass.child) this.mainClass.child = {}; if (!this.mainClass.child) this.mainClass.child = {};
if (!this.mainClass.child[softwareType]) this.mainClass.child[softwareType] = {}; const typeKey = softwareType || 'unknown';
if (!this.mainClass.child[typeKey]) this.mainClass.child[typeKey] = {};
const { category = "sensor" } = child.config.asset || {}; const { category = "sensor" } = child.config.asset || {};
if (!this.mainClass.child[softwareType][category]) { if (!this.mainClass.child[typeKey][category]) {
this.mainClass.child[softwareType][category] = []; this.mainClass.child[typeKey][category] = [];
} }
this.mainClass.child[softwareType][category].push(child); this.mainClass.child[typeKey][category].push(child);
} }
// NEW: Utility methods for parent to use // NEW: Utility methods for parent to use
@@ -91,4 +107,4 @@ class ChildRegistrationUtils {
} }
} }
module.exports = ChildRegistrationUtils; module.exports = ChildRegistrationUtils;

View File

@@ -39,8 +39,8 @@ const Logger = require("./logger");
class ConfigUtils { class ConfigUtils {
constructor(defaultConfig, IloggerEnabled , IloggerLevel) { constructor(defaultConfig, IloggerEnabled , IloggerLevel) {
const loggerEnabled = IloggerEnabled || true; const loggerEnabled = IloggerEnabled ?? true;
const loggerLevel = IloggerLevel || "warn"; const loggerLevel = IloggerLevel ?? "warn";
this.logger = new Logger(loggerEnabled, loggerLevel, 'ConfigUtils'); this.logger = new Logger(loggerEnabled, loggerLevel, 'ConfigUtils');
this.defaultConfig = defaultConfig; this.defaultConfig = defaultConfig;
this.validationUtils = new ValidationUtils(loggerEnabled, loggerLevel); this.validationUtils = new ValidationUtils(loggerEnabled, loggerLevel);
@@ -73,17 +73,25 @@ class ConfigUtils {
return updatedConfig; return updatedConfig;
} }
_isPlainObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
}
// loop through objects and merge them obj1 will be updated with obj2 values // loop through objects and merge them obj1 will be updated with obj2 values
mergeObjects(obj1, obj2) { mergeObjects(obj1, obj2) {
for (let key in obj2) { for (let key in obj2) {
if (obj2.hasOwnProperty(key)) { if (obj2.hasOwnProperty(key)) {
if (typeof obj2[key] === 'object') { const nextValue = obj2[key];
if (!obj1[key]) {
if (Array.isArray(nextValue)) {
obj1[key] = [...nextValue];
} else if (this._isPlainObject(nextValue)) {
if (!this._isPlainObject(obj1[key])) {
obj1[key] = {}; obj1[key] = {};
} }
this.mergeObjects(obj1[key], obj2[key]); this.mergeObjects(obj1[key], nextValue);
} else { } else {
obj1[key] = obj2[key]; obj1[key] = nextValue;
} }
} }
} }

View File

@@ -18,13 +18,102 @@ class EndpointUtils {
* @param {string} nodeName the name of the node (used in the URL) * @param {string} nodeName the name of the node (used in the URL)
* @param {object} customHelpers additional helper functions to inject * @param {object} customHelpers additional helper functions to inject
*/ */
createMenuUtilsEndpoint(RED, nodeName, customHelpers = {}) { createMenuUtilsEndpoint(RED, nodeName, customHelpers = {}, options = {}) {
RED.httpAdmin.get(`/${nodeName}/resources/menuUtils.js`, (req, res) => { const basePath = `/${nodeName}/resources`;
console.log(`Serving menuUtils.js for ${nodeName} node`);
res.set('Content-Type', 'application/javascript'); RED.httpAdmin.get(`${basePath}/menuUtilsData.json`, (req, res) => {
const browserCode = this.generateMenuUtilsCode(nodeName, customHelpers); res.json(this.generateMenuUtilsData(nodeName, customHelpers, options));
res.send(browserCode);
}); });
RED.httpAdmin.get(`${basePath}/menuUtils.legacy.js`, (req, res) => {
res.set('Content-Type', 'application/javascript');
res.send(this.generateLegacyMenuUtilsCode(nodeName, customHelpers));
});
RED.httpAdmin.get(`${basePath}/menuUtils.js`, (req, res) => {
res.set('Content-Type', 'application/javascript');
res.send(this.generateMenuUtilsBootstrap(nodeName));
});
}
generateMenuUtilsData(nodeName, customHelpers = {}, options = {}) {
const defaultHelpers = {
validateRequired: `function(value) {
return value != null && value.toString().trim() !== '';
}`,
formatDisplayValue: `function(value, unit) {
return \`${'${'}value} ${'${'}unit || ''}\`.trim();
}`,
validateScaling: `function(min, max) {
return !isNaN(min) && !isNaN(max) && Number(min) < Number(max);
}`,
validateUnit: `function(unit) {
return typeof unit === 'string' && unit.trim() !== '';
}`,
};
return {
nodeName,
helpers: { ...defaultHelpers, ...customHelpers },
options: {
autoLoadLegacy: options.autoLoadLegacy !== false,
},
};
}
generateMenuUtilsBootstrap(nodeName) {
return `
// Stable bootstrap for EVOLV menu utils (${nodeName})
(function() {
const nodeName = ${JSON.stringify(nodeName)};
const basePath = '/' + nodeName + '/resources';
window.EVOLV = window.EVOLV || {};
window.EVOLV.nodes = window.EVOLV.nodes || {};
window.EVOLV.nodes[nodeName] = window.EVOLV.nodes[nodeName] || {};
window.EVOLV.nodes[nodeName].utils = window.EVOLV.nodes[nodeName].utils || {};
function parseHelper(fnBody) {
try {
return (new Function('return (' + fnBody + ')'))();
} catch (error) {
console.error('[menuUtils] helper parse failed:', error);
return function() { return null; };
}
}
function loadLegacyIfNeeded(autoLoadLegacy) {
if (!autoLoadLegacy || typeof window.MenuUtils === 'function') return Promise.resolve();
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = basePath + '/menuUtils.legacy.js';
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
fetch(basePath + '/menuUtilsData.json')
.then(function(res) { return res.json(); })
.then(function(payload) {
const helperFns = {};
Object.entries(payload.helpers || {}).forEach(function(entry) {
helperFns[entry[0]] = parseHelper(entry[1]);
});
window.EVOLV.nodes[nodeName].utils.helpers = helperFns;
return loadLegacyIfNeeded(payload.options && payload.options.autoLoadLegacy);
})
.then(function() {
if (typeof window.MenuUtils === 'function' && !window.EVOLV.nodes[nodeName].utils.menuUtils) {
window.EVOLV.nodes[nodeName].utils.menuUtils = new window.MenuUtils();
}
})
.catch(function(error) {
console.error('[menuUtils] bootstrap failed for ' + nodeName, error);
});
})();
`;
} }
/** /**
@@ -33,7 +122,7 @@ class EndpointUtils {
* @param {object} customHelpers map of name: functionString pairs * @param {object} customHelpers map of name: functionString pairs
* @returns {string} a JS snippet to run in the browser * @returns {string} a JS snippet to run in the browser
*/ */
generateMenuUtilsCode(nodeName, customHelpers = {}) { generateLegacyMenuUtilsCode(nodeName, customHelpers = {}) {
// Default helper implementations to expose alongside MenuUtils // Default helper implementations to expose alongside MenuUtils
const defaultHelpers = { const defaultHelpers = {
validateRequired: `function(value) { validateRequired: `function(value) {
@@ -101,6 +190,11 @@ ${helpersCode}
console.log('Loaded EVOLV.nodes.${nodeName}.utils.menuUtils'); console.log('Loaded EVOLV.nodes.${nodeName}.utils.menuUtils');
`; `;
} }
// Backward-compatible alias.
generateMenuUtilsCode(nodeName, customHelpers = {}) {
return this.generateLegacyMenuUtilsCode(nodeName, customHelpers);
}
} }
module.exports = EndpointUtils; module.exports = EndpointUtils;

25
src/helper/index.js Normal file
View File

@@ -0,0 +1,25 @@
const assertions = require('./assertionUtils.js');
const assetUtils = require('./assetUtils.js');
const childRegistrationUtils = require('./childRegistrationUtils.js');
const configUtils = require('./configUtils.js');
const endpointUtils = require('./endpointUtils.js');
const gravity = require('./gravity.js');
const logger = require('./logger.js');
const menuUtils = require('./menuUtils.js');
const nodeTemplates = require('./nodeTemplates.js');
const outputUtils = require('./outputUtils.js');
const validation = require('./validationUtils.js');
module.exports = {
assertions,
assetUtils,
childRegistrationUtils,
configUtils,
endpointUtils,
gravity,
logger,
menuUtils,
nodeTemplates,
outputUtils,
validation,
};

View File

@@ -44,7 +44,7 @@ class Logger {
if (this.levels.includes(level)) { if (this.levels.includes(level)) {
this.logLevel = level; this.logLevel = level;
} else { } else {
console.error(`[ERROR ${nameModule}]: Invalid log level: ${level}`); console.error(`[ERROR] -> ${this.nameModule}: Invalid log level: ${level}`);
} }
} }
@@ -54,4 +54,4 @@ class Logger {
} }
} }
module.exports = Logger; module.exports = Logger;

View File

@@ -480,17 +480,26 @@ generateHtml(htmlElement, options, savedValue) {
} }
} }
createMenuUtilsEndpoint(RED, nodeName, customHelpers = {}) { createMenuUtilsEndpoint(RED, nodeName, customHelpers = {}, options = {}) {
RED.httpAdmin.get(`/${nodeName}/resources/menuUtils.js`, function(req, res) { const basePath = `/${nodeName}/resources`;
console.log(`Serving menuUtils.js for ${nodeName} node`);
RED.httpAdmin.get(`${basePath}/menuUtilsData.json`, function(req, res) {
res.json(this.generateMenuUtilsData(nodeName, customHelpers, options));
}.bind(this));
RED.httpAdmin.get(`${basePath}/menuUtils.legacy.js`, function(req, res) {
res.set('Content-Type', 'application/javascript'); res.set('Content-Type', 'application/javascript');
const browserCode = this.generateLegacyMenuUtilsCode(nodeName, customHelpers);
const browserCode = this.generateMenuUtilsCode(nodeName, customHelpers);
res.send(browserCode); res.send(browserCode);
}.bind(this)); }.bind(this));
RED.httpAdmin.get(`${basePath}/menuUtils.js`, function(req, res) {
res.set('Content-Type', 'application/javascript');
res.send(this.generateMenuUtilsBootstrap(nodeName));
}.bind(this));
} }
generateMenuUtilsCode(nodeName, customHelpers = {}) { generateMenuUtilsData(nodeName, customHelpers = {}, options = {}) {
const defaultHelpers = { const defaultHelpers = {
validateRequired: `function(value) { validateRequired: `function(value) {
return value && value.toString().trim() !== ''; return value && value.toString().trim() !== '';
@@ -500,7 +509,71 @@ generateMenuUtilsCode(nodeName, customHelpers = {}) {
}` }`
}; };
const allHelpers = { ...defaultHelpers, ...customHelpers }; return {
nodeName,
helpers: { ...defaultHelpers, ...customHelpers },
options: {
autoLoadLegacy: options.autoLoadLegacy !== false,
},
};
}
generateMenuUtilsBootstrap(nodeName) {
return `
// Stable bootstrap for EVOLV menu utils (${nodeName})
(function() {
const nodeName = ${JSON.stringify(nodeName)};
const basePath = '/' + nodeName + '/resources';
window.EVOLV = window.EVOLV || {};
window.EVOLV.nodes = window.EVOLV.nodes || {};
window.EVOLV.nodes[nodeName] = window.EVOLV.nodes[nodeName] || {};
window.EVOLV.nodes[nodeName].utils = window.EVOLV.nodes[nodeName].utils || {};
function parseHelper(fnBody) {
try {
return (new Function('return (' + fnBody + ')'))();
} catch (error) {
console.error('[menuUtils] helper parse failed:', error);
return function() { return null; };
}
}
function loadLegacyIfNeeded(autoLoadLegacy) {
if (!autoLoadLegacy || typeof window.MenuUtils === 'function') return Promise.resolve();
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = basePath + '/menuUtils.legacy.js';
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
fetch(basePath + '/menuUtilsData.json')
.then(function(res) { return res.json(); })
.then(function(payload) {
const helperFns = {};
Object.entries(payload.helpers || {}).forEach(function(entry) {
helperFns[entry[0]] = parseHelper(entry[1]);
});
window.EVOLV.nodes[nodeName].utils.helpers = helperFns;
return loadLegacyIfNeeded(payload.options && payload.options.autoLoadLegacy);
})
.then(function() {
if (typeof window.MenuUtils === 'function' && !window.EVOLV.nodes[nodeName].utils.menuUtils) {
window.EVOLV.nodes[nodeName].utils.menuUtils = new window.MenuUtils();
}
})
.catch(function(error) {
console.error('[menuUtils] bootstrap failed for ' + nodeName, error);
});
})();
`;
}
generateLegacyMenuUtilsCode(nodeName, customHelpers = {}) {
const allHelpers = { ...this.generateMenuUtilsData(nodeName).helpers, ...customHelpers };
const helpersCode = Object.entries(allHelpers) const helpersCode = Object.entries(allHelpers)
.map(([name, func]) => ` ${name}: ${func}`) .map(([name, func]) => ` ${name}: ${func}`)
@@ -533,6 +606,11 @@ ${helpersCode}
`; `;
} }
// Backward-compatible alias
generateMenuUtilsCode(nodeName, customHelpers = {}) {
return this.generateLegacyMenuUtilsCode(nodeName, customHelpers);
} }
module.exports = MenuUtils; }
module.exports = MenuUtils;

View File

@@ -53,4 +53,4 @@ const nodeTemplates = {
// …add more node “templates” here… // …add more node “templates” here…
}; };
export default nodeTemplates; module.exports = nodeTemplates;

View File

@@ -7,6 +7,9 @@ class OutputUtils {
} }
checkForChanges(output, format) { checkForChanges(output, format) {
if (!output || typeof output !== 'object') {
return {};
}
const changedFields = {}; const changedFields = {};
for (const key in output) { for (const key in output) {
if (output.hasOwnProperty(key) && output[key] !== this.output[format][key]) { if (output.hasOwnProperty(key) && output[key] !== this.output[format][key]) {
@@ -54,11 +57,11 @@ class OutputUtils {
break; break;
default: default:
console.log('Unknown format in output utils'); return null;
break;
} }
return msg; return msg;
} }
return null;
} }

View File

@@ -36,8 +36,8 @@ const Logger = require("./logger");
class ValidationUtils { class ValidationUtils {
constructor(IloggerEnabled, IloggerLevel) { constructor(IloggerEnabled, IloggerLevel) {
const loggerEnabled = IloggerEnabled || true; const loggerEnabled = IloggerEnabled ?? true;
const loggerLevel = IloggerLevel || "warn"; const loggerLevel = IloggerLevel ?? "warn";
this.logger = new Logger(loggerEnabled, loggerLevel, 'ValidationUtils'); this.logger = new Logger(loggerEnabled, loggerLevel, 'ValidationUtils');
} }
@@ -191,7 +191,7 @@ class ValidationUtils {
continue; continue;
} }
if("default" in v){ if(v && typeof v === "object" && "default" in v){
//put the default value in the object //put the default value in the object
newObj[k] = v.default; newObj[k] = v.default;
continue; continue;
@@ -496,6 +496,11 @@ class ValidationUtils {
return fieldSchema.default; return fieldSchema.default;
} }
if (typeof configValue !== "string") {
this.logger.warn(`${name}.${key} is not a valid enum string. Using default value.`);
return fieldSchema.default;
}
const validValues = rules.values.map(e => e.value.toLowerCase()); const validValues = rules.values.map(e => e.value.toLowerCase());
//remove caps //remove caps

View File

@@ -69,8 +69,10 @@ class Measurement {
} }
getLaggedValue(lag){ getLaggedValue(lag){
if(this.values.length <= lag) return null; if (lag < 0) throw new Error('lag must be >= 0');
return this.values[this.values.length - lag]; const index = this.values.length - 1 - lag;
if (index < 0) return null;
return this.values[index];
} }
getLaggedSample(lag){ getLaggedSample(lag){
@@ -178,7 +180,7 @@ class Measurement {
try { try {
const convertedValues = this.values.map(value => const convertedValues = this.values.map(value =>
convertModule.convert(value).from(this.unit).to(targetUnit) convertModule(value).from(this.unit).to(targetUnit)
); );
const newMeasurement = new Measurement( const newMeasurement = new Measurement(

View File

@@ -4,6 +4,7 @@ const convertModule = require('../convert/index');
class MeasurementContainer { class MeasurementContainer {
constructor(options = {},logger) { constructor(options = {},logger) {
this.logger = logger || null;
this.emitter = new EventEmitter(); this.emitter = new EventEmitter();
this.measurements = {}; this.measurements = {};
this.windowSize = options.windowSize || 10; // Default window size this.windowSize = options.windowSize || 10; // Default window size
@@ -90,25 +91,32 @@ class MeasurementContainer {
this._currentType = typeName; this._currentType = typeName;
this._currentVariant = null; this._currentVariant = null;
this._currentPosition = null; this._currentPosition = null;
this._currentChildId = null;
return this; return this;
} }
variant(variantName) { variant(variantName) {
if (!this._currentType) { if (!this._currentType) {
throw new Error('Type must be specified before variant'); if (this.logger) {
this.logger.warn('variant() ignored: type must be specified before variant');
}
return this;
} }
this._currentVariant = variantName; this._currentVariant = variantName;
this._currentPosition = null; this._currentPosition = null;
this._currentChildId = null;
return this; return this;
} }
position(positionValue) { position(positionValue) {
if (!this._currentVariant) { if (!this._currentVariant) {
throw new Error('Variant must be specified before position'); if (this.logger) {
this.logger.warn('position() ignored: variant must be specified before position');
}
return this;
} }
this._currentPosition = positionValue.toString().toLowerCase();
this._currentPosition = positionValue.toString().toLowerCase();;
return this; return this;
} }
@@ -225,8 +233,6 @@ class MeasurementContainer {
return requireValues ? measurement.values?.length > 0 : true; return requireValues ? measurement.values?.length > 0 : true;
} }
unit(unitName) { unit(unitName) {
if (!this._ensureChainIsValid()) return this; if (!this._ensureChainIsValid()) return this;
@@ -332,7 +338,7 @@ class MeasurementContainer {
// Convert if needed // Convert if needed
if (measurement.unit && requestedUnit !== measurement.unit) { if (measurement.unit && requestedUnit !== measurement.unit) {
try { try {
const convertedValue = convertModule(value).from(measurement.unit).to(requestedUnit); const convertedValue = convertModule(sample.value).from(measurement.unit).to(requestedUnit);
//replace old value in sample and return obj //replace old value in sample and return obj
sample.value = convertedValue ; sample.value = convertedValue ;
sample.unit = requestedUnit; sample.unit = requestedUnit;
@@ -364,7 +370,7 @@ class MeasurementContainer {
// Convert if needed // Convert if needed
if (measurement.unit && requestedUnit !== measurement.unit) { if (measurement.unit && requestedUnit !== measurement.unit) {
try { try {
const convertedValue = convertModule(value).from(measurement.unit).to(requestedUnit); const convertedValue = convertModule(sample.value).from(measurement.unit).to(requestedUnit);
//replace old value in sample and return obj //replace old value in sample and return obj
sample.value = convertedValue ; sample.value = convertedValue ;
sample.unit = requestedUnit; sample.unit = requestedUnit;
@@ -429,7 +435,10 @@ class MeasurementContainer {
// Difference calculations between positions // Difference calculations between positions
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) { difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
if (!this._currentType || !this._currentVariant) { if (!this._currentType || !this._currentVariant) {
throw new Error("Type and variant must be specified for difference calculation"); if (this.logger) {
this.logger.warn('difference() ignored: type and variant must be specified');
}
return null;
} }
const get = pos => { const get = pos => {
@@ -510,7 +519,10 @@ class MeasurementContainer {
getVariants() { getVariants() {
if (!this._currentType) { if (!this._currentType) {
throw new Error('Type must be specified before listing variants'); if (this.logger) {
this.logger.warn('getVariants() ignored: type must be specified first');
}
return [];
} }
return this.measurements[this._currentType] ? return this.measurements[this._currentType] ?
Object.keys(this.measurements[this._currentType]) : []; Object.keys(this.measurements[this._currentType]) : [];
@@ -518,7 +530,10 @@ class MeasurementContainer {
getPositions() { getPositions() {
if (!this._currentType || !this._currentVariant) { if (!this._currentType || !this._currentVariant) {
throw new Error('Type and variant must be specified before listing positions'); if (this.logger) {
this.logger.warn('getPositions() ignored: type and variant must be specified first');
}
return [];
} }
if (!this.measurements[this._currentType] || if (!this.measurements[this._currentType] ||
@@ -619,16 +634,19 @@ class MeasurementContainer {
} }
_convertPositionNum2Str(positionValue) { _convertPositionNum2Str(positionValue) {
switch (positionValue) { if (positionValue === 0) {
case 0:
return "atEquipment"; return "atEquipment";
case (positionValue < 0):
return "upstream";
case (positionValue > 0):
return "downstream";
default:
console.log(`Invalid position provided: ${positionValue}`);
} }
if (positionValue < 0) {
return "upstream";
}
if (positionValue > 0) {
return "downstream";
}
if (this.logger) {
this.logger.warn(`Invalid position provided: ${positionValue}`);
}
return null;
} }
} }

41
src/menu/aquonSamples.js Normal file
View File

@@ -0,0 +1,41 @@
const fs = require('fs');
const path = require('path');
class AquonSamplesMenu {
constructor(relPath = '../../datasets/assetData') {
this.baseDir = path.resolve(__dirname, relPath);
this.samplePath = path.resolve(this.baseDir, 'monsterSamples.json');
this.specPath = path.resolve(this.baseDir, 'specs/monster/index.json');
this.cache = new Map();
}
_loadJSON(filePath, cacheKey) {
if (this.cache.has(cacheKey)) {
return this.cache.get(cacheKey);
}
if (!fs.existsSync(filePath)) {
throw new Error(`Aquon dataset not found: ${filePath}`);
}
const raw = fs.readFileSync(filePath, 'utf8');
const parsed = JSON.parse(raw);
this.cache.set(cacheKey, parsed);
return parsed;
}
getAllMenuData() {
const samples = this._loadJSON(this.samplePath, 'samples');
const specs = this._loadJSON(this.specPath, 'specs');
return {
samples: samples.samples || [],
specs: {
defaults: specs.defaults || {},
bySample: specs.bySample || {}
}
};
}
}
module.exports = AquonSamplesMenu;

View File

@@ -1,4 +1,5 @@
const { assetCategoryManager } = require('../../datasets/assetData'); const { assetCategoryManager } = require('../../datasets/assetData');
const assetApiConfig = require('../configs/assetApiConfig.js');
class AssetMenu { class AssetMenu {
constructor({ manager = assetCategoryManager, softwareType = null } = {}) { constructor({ manager = assetCategoryManager, softwareType = null } = {}) {
@@ -67,7 +68,11 @@ class AssetMenu {
return { return {
categories: selectedCategories, categories: selectedCategories,
defaultCategory: categoryKey defaultCategory: categoryKey,
apiConfig: {
url: `${assetApiConfig.baseUrl}/apis/products/PLC/integration/`,
headers: { ...assetApiConfig.headers }
}
}; };
} }
@@ -75,6 +80,7 @@ class AssetMenu {
const htmlCode = this.getHtmlInjectionCode(nodeName); const htmlCode = this.getHtmlInjectionCode(nodeName);
const dataCode = this.getDataInjectionCode(nodeName); const dataCode = this.getDataInjectionCode(nodeName);
const eventsCode = this.getEventInjectionCode(nodeName); const eventsCode = this.getEventInjectionCode(nodeName);
const syncCode = this.getSyncInjectionCode(nodeName);
const saveCode = this.getSaveInjectionCode(nodeName); const saveCode = this.getSaveInjectionCode(nodeName);
return ` return `
@@ -85,13 +91,16 @@ class AssetMenu {
${htmlCode} ${htmlCode}
${dataCode} ${dataCode}
${eventsCode} ${eventsCode}
${syncCode}
${saveCode} ${saveCode}
window.EVOLV.nodes.${nodeName}.assetMenu.initEditor = function(node) { window.EVOLV.nodes.${nodeName}.assetMenu.initEditor = function(node) {
console.log('Initializing asset properties for ${nodeName}'); console.log('Initializing asset properties for ${nodeName}');
this.injectHtml(); this.injectHtml();
this.wireEvents(node); this.wireEvents(node);
this.loadData(node); this.loadData(node).catch((error) =>
console.error('Asset menu load failed:', error)
);
}; };
`; `;
} }
@@ -99,10 +108,11 @@ class AssetMenu {
getDataInjectionCode(nodeName) { getDataInjectionCode(nodeName) {
return ` return `
// Asset data loader for ${nodeName} // Asset data loader for ${nodeName}
window.EVOLV.nodes.${nodeName}.assetMenu.loadData = function(node) { window.EVOLV.nodes.${nodeName}.assetMenu.loadData = async function(node) {
const menuAsset = window.EVOLV.nodes.${nodeName}.menuData.asset || {}; const menuAsset = window.EVOLV.nodes.${nodeName}.menuData.asset || {};
const categories = menuAsset.categories || {}; const categories = menuAsset.categories || {};
const defaultCategory = menuAsset.defaultCategory || Object.keys(categories)[0] || null; const defaultCategory = menuAsset.defaultCategory || Object.keys(categories)[0] || null;
const apiConfig = menuAsset.apiConfig || {};
const elems = { const elems = {
supplier: document.getElementById('node-input-supplier'), supplier: document.getElementById('node-input-supplier'),
type: document.getElementById('node-input-assetType'), type: document.getElementById('node-input-assetType'),
@@ -110,6 +120,79 @@ class AssetMenu {
unit: document.getElementById('node-input-unit') unit: document.getElementById('node-input-unit')
}; };
function resolveCategoryKey() {
if (node.softwareType && categories[node.softwareType]) {
return node.softwareType;
}
if (node.category && categories[node.category]) {
return node.category;
}
return defaultCategory;
}
function normalizeModel(model = {}) {
return {
id: model.id ?? model.name,
name: model.name,
units: model.units || []
};
}
function normalizeType(type = {}) {
return {
id: type.id || type.name,
name: type.name,
models: Array.isArray(type.models)
? type.models.map(normalizeModel)
: []
};
}
function normalizeSupplier(supplier = {}) {
const types = (supplier.categories || []).reduce((acc, category) => {
const categoryTypes = Array.isArray(category.types)
? category.types.map(normalizeType)
: [];
return acc.concat(categoryTypes);
}, []);
return {
id: supplier.id || supplier.name,
name: supplier.name,
types
};
}
function normalizeApiCategory(key, label, suppliers = []) {
const normalizedSuppliers = suppliers
.map(normalizeSupplier)
.filter((supplier) => supplier.types && supplier.types.length);
if (!normalizedSuppliers.length) {
return null;
}
return {
softwareType: key,
label: label || key,
suppliers: normalizedSuppliers
};
}
async function fetchCategoryFromApi(key) {
if (!apiConfig.url || !key) {
return null;
}
const response = await fetch(apiConfig.url, {
headers: apiConfig.headers || {}
});
if (!response.ok) {
throw new Error('Asset API request failed: ' + response.status);
}
const payload = await response.json();
if (!payload || payload.success === false || !Array.isArray(payload.data)) {
throw new Error(payload?.message || 'Unexpected asset API response');
}
return normalizeApiCategory(key, node.softwareType || key, payload.data);
}
function populate(selectEl, items = [], selectedValue, mapFn, placeholderText = 'Select...') { function populate(selectEl, items = [], selectedValue, mapFn, placeholderText = 'Select...') {
const previous = selectEl.value; const previous = selectEl.value;
const mapper = typeof mapFn === 'function' const mapper = typeof mapFn === 'function'
@@ -149,19 +232,23 @@ class AssetMenu {
} }
} }
const resolveCategoryKey = () => {
if (node.softwareType && categories[node.softwareType]) {
return node.softwareType;
}
if (node.category && categories[node.category]) {
return node.category;
}
return defaultCategory;
};
const categoryKey = resolveCategoryKey(); const categoryKey = resolveCategoryKey();
node.category = categoryKey; const resolvedCategoryKey = categoryKey || defaultCategory;
const activeCategory = categoryKey ? categories[categoryKey] : null; let activeCategory = resolvedCategoryKey ? categories[resolvedCategoryKey] : null;
if (resolvedCategoryKey) {
node.category = resolvedCategoryKey;
}
try {
const apiCategory = await fetchCategoryFromApi(resolvedCategoryKey);
if (apiCategory) {
categories[resolvedCategoryKey] = apiCategory;
activeCategory = apiCategory;
}
} catch (error) {
console.warn('[AssetMenu] API lookup failed for ${nodeName}, using local asset data', error);
}
const suppliers = activeCategory ? activeCategory.suppliers : []; const suppliers = activeCategory ? activeCategory.suppliers : [];
populate( populate(
@@ -173,7 +260,7 @@ class AssetMenu {
); );
const activeSupplier = suppliers.find( const activeSupplier = suppliers.find(
(supplier) => (supplier.id || supplier.name) === node.supplier (supplier) => String(supplier.id || supplier.name) === String(node.supplier)
); );
const types = activeSupplier ? activeSupplier.types : []; const types = activeSupplier ? activeSupplier.types : [];
populate( populate(
@@ -185,7 +272,7 @@ class AssetMenu {
); );
const activeType = types.find( const activeType = types.find(
(type) => (type.id || type.name) === node.assetType (type) => String(type.id || type.name) === String(node.assetType)
); );
const models = activeType ? activeType.models : []; const models = activeType ? activeType.models : [];
populate( populate(
@@ -197,8 +284,12 @@ class AssetMenu {
); );
const activeModel = models.find( const activeModel = models.find(
(model) => (model.id || model.name) === node.model (model) => String(model.id || model.name) === String(node.model)
); );
if (activeModel) {
node.modelMetadata = activeModel;
node.modelName = activeModel.name;
}
populate( populate(
elems.unit, elems.unit,
activeModel ? activeModel.units || [] : [], activeModel ? activeModel.units || [] : [],
@@ -206,6 +297,7 @@ class AssetMenu {
(unit) => ({ value: unit, label: unit }), (unit) => ({ value: unit, label: unit }),
activeModel ? 'Select...' : activeType ? 'Awaiting Model Selection' : 'Awaiting Type Selection' activeModel ? 'Select...' : activeType ? 'Awaiting Model Selection' : 'Awaiting Type Selection'
); );
this.setAssetTagNumber(node, node.assetTagNumber || '');
}; };
`; `;
} }
@@ -284,7 +376,7 @@ class AssetMenu {
const category = getActiveCategory(); const category = getActiveCategory();
const supplier = category const supplier = category
? category.suppliers.find( ? category.suppliers.find(
(item) => (item.id || item.name) === elems.supplier.value (item) => String(item.id || item.name) === String(elems.supplier.value)
) )
: null; : null;
const types = supplier ? supplier.types : []; const types = supplier ? supplier.types : [];
@@ -295,6 +387,7 @@ class AssetMenu {
(type) => ({ value: type.id || type.name, label: type.name }), (type) => ({ value: type.id || type.name, label: type.name }),
supplier ? 'Select...' : 'Awaiting Supplier Selection' supplier ? 'Select...' : 'Awaiting Supplier Selection'
); );
node.modelMetadata = null;
populate(elems.model, [], '', undefined, 'Awaiting Type Selection'); populate(elems.model, [], '', undefined, 'Awaiting Type Selection');
populate(elems.unit, [], '', undefined, 'Awaiting Type Selection'); populate(elems.unit, [], '', undefined, 'Awaiting Type Selection');
}); });
@@ -303,12 +396,12 @@ class AssetMenu {
const category = getActiveCategory(); const category = getActiveCategory();
const supplier = category const supplier = category
? category.suppliers.find( ? category.suppliers.find(
(item) => (item.id || item.name) === elems.supplier.value (item) => String(item.id || item.name) === String(elems.supplier.value)
) )
: null; : null;
const type = supplier const type = supplier
? supplier.types.find( ? supplier.types.find(
(item) => (item.id || item.name) === elems.type.value (item) => String(item.id || item.name) === String(elems.type.value)
) )
: null; : null;
const models = type ? type.models : []; const models = type ? type.models : [];
@@ -319,6 +412,7 @@ class AssetMenu {
(model) => ({ value: model.id || model.name, label: model.name }), (model) => ({ value: model.id || model.name, label: model.name }),
type ? 'Select...' : 'Awaiting Type Selection' type ? 'Select...' : 'Awaiting Type Selection'
); );
node.modelMetadata = null;
populate( populate(
elems.unit, elems.unit,
[], [],
@@ -332,19 +426,21 @@ class AssetMenu {
const category = getActiveCategory(); const category = getActiveCategory();
const supplier = category const supplier = category
? category.suppliers.find( ? category.suppliers.find(
(item) => (item.id || item.name) === elems.supplier.value (item) => String(item.id || item.name) === String(elems.supplier.value)
) )
: null; : null;
const type = supplier const type = supplier
? supplier.types.find( ? supplier.types.find(
(item) => (item.id || item.name) === elems.type.value (item) => String(item.id || item.name) === String(elems.type.value)
) )
: null; : null;
const model = type const model = type
? type.models.find( ? type.models.find(
(item) => (item.id || item.name) === elems.model.value (item) => String(item.id || item.name) === String(elems.model.value)
) )
: null; : null;
node.modelMetadata = model;
node.modelName = model ? model.name : '';
populate( populate(
elems.unit, elems.unit,
model ? model.units || [] : [], model ? model.units || [] : [],
@@ -357,6 +453,100 @@ class AssetMenu {
`; `;
} }
getSyncInjectionCode(nodeName) {
return `
// Asset synchronization helpers for ${nodeName}
window.EVOLV.nodes.${nodeName}.assetMenu.setAssetTagNumber = function(node, tag) {
const normalized = tag ? tag.toString() : '';
const input = document.getElementById('node-input-assetTagNumber');
const hint = document.getElementById('node-input-assetTagNumber-hint');
console.info('[AssetMenu] tag number update', {
nodeId: node && node.id ? node.id : null,
tag: normalized
});
if (input) {
input.value = normalized;
}
if (hint) {
hint.textContent = normalized ? 'Assigned tag ' + normalized : 'Not registered yet';
}
if (node) {
node.assetTagNumber = normalized;
}
};
window.EVOLV.nodes.${nodeName}.assetMenu.buildSyncRequest = function(node) {
const tagInput = document.getElementById('node-input-assetTagNumber');
const candidateTag = tagInput && tagInput.value ? tagInput.value.trim() : '';
const fallbackTag = node && node.assetTagNumber ? node.assetTagNumber : '';
const registrationDefaults =
(window.EVOLV.nodes.${nodeName}.config && window.EVOLV.nodes.${nodeName}.config.assetRegistration && window.EVOLV.nodes.${nodeName}.config.assetRegistration.default) || {};
const displayName = node && node.name ? node.name : node && node.id ? node.id : '${nodeName}';
console.info('[AssetMenu] build sync payload', {
nodeId: node && node.id ? node.id : null,
candidateTag,
fallbackTag,
status: registrationDefaults.status || 'actief'
});
return {
asset: {
tagNumber: candidateTag || fallbackTag,
supplier: node && node.supplier ? node.supplier : '',
assetType: node && node.assetType ? node.assetType : '',
model: node && node.model ? node.model : '',
unit: node && node.unit ? node.unit : '',
assetName: displayName,
assetDescription: displayName,
assetStatus: registrationDefaults.status || 'actief',
modelMetadata: node && node.modelMetadata ? node.modelMetadata : null
},
nodeId: node && node.id ? node.id : null,
nodeName: node && node.type ? node.type : '${nodeName}'
};
};
window.EVOLV.nodes.${nodeName}.assetMenu.syncAsset = function(node) {
const payload = this.buildSyncRequest(node);
const redSettings = window.RED && window.RED.settings;
const adminRoot = redSettings ? redSettings.httpAdminRoot : '';
const trimmedRoot = adminRoot && adminRoot.endsWith('/') ? adminRoot.slice(0, -1) : adminRoot || '';
const prefix = trimmedRoot || '';
const endpoint = (prefix || '') + '/${nodeName}/asset-reg';
console.info('[AssetMenu] sync request', {
endpoint,
nodeId: node && node.id ? node.id : null,
tagNumber: payload && payload.asset ? payload.asset.tagNumber : null
});
fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
})
.then((res) =>
res.json().catch((err) => {
console.warn('[AssetMenu] asset sync response is not JSON', err);
return { success: false, message: err.message || 'Invalid API response' };
})
)
.then((result) => {
console.info('[AssetMenu] sync response', result);
if (result && result.success) {
const newTag = (result.data && result.data.asset_tag_number) || payload.asset.tagNumber || '';
this.setAssetTagNumber(node, newTag);
if (window.RED && typeof window.RED.notify === 'function') {
window.RED.notify('Asset synced: ' + (newTag || 'no tag'), 'info');
}
} else {
console.warn('[AssetMenu] asset sync failed', result && result.message);
}
})
.catch((error) => {
console.error('[AssetMenu] asset sync error', error);
});
};
`;
}
getHtmlTemplate() { getHtmlTemplate() {
return ` return `
<!-- Asset Properties --> <!-- Asset Properties -->
@@ -378,6 +568,11 @@ class AssetMenu {
<label for="node-input-unit"><i class="fa fa-balance-scale"></i> Unit</label> <label for="node-input-unit"><i class="fa fa-balance-scale"></i> Unit</label>
<select id="node-input-unit" style="width:70%;"></select> <select id="node-input-unit" style="width:70%;"></select>
</div> </div>
<div class="form-row">
<label for="node-input-assetTagNumber"><i class="fa fa-hashtag"></i> Asset Tag</label>
<input type="text" id="node-input-assetTagNumber" readonly style="width:70%;" />
<div class="form-tips" id="node-input-assetTagNumber-hint">Not registered yet</div>
</div>
<hr /> <hr />
`; `;
} }
@@ -419,7 +614,7 @@ class AssetMenu {
node.category = resolveCategoryKey(); node.category = resolveCategoryKey();
const fields = ['supplier', 'assetType', 'model', 'unit']; const fields = ['supplier', 'assetType', 'model', 'unit', 'assetTagNumber'];
const errors = []; const errors = [];
fields.forEach((field) => { fields.forEach((field) => {
@@ -440,8 +635,15 @@ class AssetMenu {
acc[field] = node[field]; acc[field] = node[field];
return acc; return acc;
}, {}); }, {});
if (node.modelMetadata && typeof node.modelMetadata.id !== 'undefined') {
saved.modelId = node.modelMetadata.id;
}
console.log('[AssetMenu] save result:', saved); console.log('[AssetMenu] save result:', saved);
if (errors.length === 0 && this.syncAsset) {
this.syncAsset(node);
}
return errors.length === 0; return errors.length === 0;
}; };
`; `;

View File

@@ -2,6 +2,7 @@ const AssetMenu = require('./asset.js');
const { TagcodeApp, DynamicAssetMenu } = require('./tagcodeApp.js'); const { TagcodeApp, DynamicAssetMenu } = require('./tagcodeApp.js');
const LoggerMenu = require('./logger.js'); const LoggerMenu = require('./logger.js');
const PhysicalPositionMenu = require('./physicalPosition.js'); const PhysicalPositionMenu = require('./physicalPosition.js');
const AquonSamplesMenu = require('./aquonSamples.js');
const ConfigManager = require('../configs'); const ConfigManager = require('../configs');
class MenuManager { class MenuManager {
@@ -16,6 +17,7 @@ class MenuManager {
//this.registerMenu('asset', (nodeName) => new DynamicAssetMenu(nodeName, new TagcodeApp())); //this.registerMenu('asset', (nodeName) => new DynamicAssetMenu(nodeName, new TagcodeApp()));
this.registerMenu('logger', () => new LoggerMenu()); this.registerMenu('logger', () => new LoggerMenu());
this.registerMenu('position', () => new PhysicalPositionMenu()); this.registerMenu('position', () => new PhysicalPositionMenu());
this.registerMenu('aquon', () => new AquonSamplesMenu());
} }
/** /**
@@ -34,7 +36,21 @@ class MenuManager {
try { try {
const config = this.configManager.getConfig(nodeName); const config = this.configManager.getConfig(nodeName);
return config?.functionality?.softwareType || nodeName; const softwareType = config?.functionality?.softwareType;
if (typeof softwareType === 'string' && softwareType.trim()) {
return softwareType;
}
if (
softwareType &&
typeof softwareType === 'object' &&
typeof softwareType.default === 'string' &&
softwareType.default.trim()
) {
return softwareType.default;
}
return nodeName;
} catch (error) { } catch (error) {
console.warn(`Unable to determine softwareType for ${nodeName}: ${error.message}`); console.warn(`Unable to determine softwareType for ${nodeName}: ${error.message}`);
return nodeName; return nodeName;

7
src/nrmse/index.js Normal file
View File

@@ -0,0 +1,7 @@
const nrmse = require('./errorMetrics.js');
const nrmseConfig = require('./nrmseConfig.json');
module.exports = {
nrmse,
nrmseConfig,
};

5
src/outliers/index.js Normal file
View File

@@ -0,0 +1,5 @@
const outlierDetection = require('./outlierDetection.js');
module.exports = {
outlierDetection,
};

View File

@@ -61,6 +61,8 @@ class DynamicClusterDeviation {
} }
} }
module.exports = DynamicClusterDeviation;
// Rolling window simulation with outlier detection // Rolling window simulation with outlier detection
/* /*
const detector = new DynamicClusterDeviation(); const detector = new DynamicClusterDeviation();
@@ -86,4 +88,4 @@ dataStream.forEach((value, index) => {
}); });
console.log("\nFinal detector cluster states:", JSON.stringify(detector.clusters, null, 2)); console.log("\nFinal detector cluster states:", JSON.stringify(detector.clusters, null, 2));
*/ */

9
src/predict/index.js Normal file
View File

@@ -0,0 +1,9 @@
const predict = require('./predict_class.js');
const interpolation = require('./interpolation.js');
const predictConfig = require('./predictConfig.json');
module.exports = {
predict,
interpolation,
predictConfig,
};

11
src/state/index.js Normal file
View File

@@ -0,0 +1,11 @@
const state = require('./state.js');
const stateManager = require('./stateManager.js');
const movementManager = require('./movementManager.js');
const stateConfig = require('./stateConfig.json');
module.exports = {
state,
stateManager,
movementManager,
stateConfig,
};

View File

@@ -0,0 +1,42 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const barrel = require('../index.js');
test('barrel exports expected public members', () => {
const expected = [
'predict',
'interpolation',
'configManager',
'assetApiConfig',
'outputUtils',
'configUtils',
'logger',
'validation',
'assertions',
'MeasurementContainer',
'nrmse',
'state',
'coolprop',
'convert',
'MenuManager',
'childRegistrationUtils',
'loadCurve',
'loadModel',
'gravity',
];
for (const key of expected) {
assert.ok(key in barrel, `missing export: ${key}`);
}
});
test('barrel types are callable where expected', () => {
assert.equal(typeof barrel.logger, 'function');
assert.equal(typeof barrel.validation, 'function');
assert.equal(typeof barrel.configUtils, 'function');
assert.equal(typeof barrel.outputUtils, 'function');
assert.equal(typeof barrel.MeasurementContainer, 'function');
assert.equal(typeof barrel.convert, 'function');
assert.equal(typeof barrel.gravity.getStandardGravity, 'function');
});

14
test/assertions.test.js Normal file
View File

@@ -0,0 +1,14 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const Assertions = require('../src/helper/assertionUtils.js');
test('assertNoNaN does not throw for valid nested arrays', () => {
const assertions = new Assertions();
assert.doesNotThrow(() => assertions.assertNoNaN([1, [2, 3, [4]]]));
});
test('assertNoNaN throws when NaN exists in nested arrays', () => {
const assertions = new Assertions();
assert.throws(() => assertions.assertNoNaN([1, [2, NaN]]), /NaN detected/);
});

View File

@@ -0,0 +1,55 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const ChildRegistrationUtils = require('../src/helper/childRegistrationUtils.js');
function makeMainClass() {
return {
logger: {
debug() {},
info() {},
warn() {},
error() {},
},
child: {},
registerChildCalls: [],
registerChild(child, softwareType) {
this.registerChildCalls.push({ child, softwareType });
},
};
}
test('registerChild wires parent, measurement context, and storage', async () => {
const mainClass = makeMainClass();
const utils = new ChildRegistrationUtils(mainClass);
const measurementContext = {
childId: null,
childName: null,
parentRef: null,
setChildId(v) { this.childId = v; },
setChildName(v) { this.childName = v; },
setParentRef(v) { this.parentRef = v; },
};
const child = {
config: {
functionality: { softwareType: 'measurement' },
general: { name: 'PT1', id: 'child-1' },
asset: { category: 'sensor' },
},
measurements: measurementContext,
};
await utils.registerChild(child, 'upstream');
assert.deepEqual(child.parent, [mainClass]);
assert.equal(child.positionVsParent, 'upstream');
assert.equal(measurementContext.childId, 'child-1');
assert.equal(measurementContext.childName, 'PT1');
assert.equal(measurementContext.parentRef, mainClass);
assert.equal(mainClass.child.measurement.sensor.length, 1);
assert.equal(utils.getChildById('child-1'), child);
assert.equal(mainClass.registerChildCalls.length, 1);
});

View File

@@ -0,0 +1,33 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const ConfigManager = require('../src/configs/index.js');
test('can read known config and report existence', () => {
const manager = new ConfigManager('.');
assert.equal(manager.hasConfig('measurement'), true);
const config = manager.getConfig('measurement');
assert.ok(config.functionality);
assert.ok(config.functionality.softwareType);
});
test('getAvailableConfigs includes known names', () => {
const manager = new ConfigManager('.');
const configs = manager.getAvailableConfigs();
assert.ok(configs.includes('measurement'));
assert.ok(configs.includes('rotatingMachine'));
});
test('createEndpoint creates executable JS payload shell', () => {
const manager = new ConfigManager('.');
const script = manager.createEndpoint('measurement');
assert.match(script, /window\.EVOLV\.nodes\.measurement/);
assert.match(script, /config loaded and endpoint created/);
});
test('getConfig throws on missing config', () => {
const manager = new ConfigManager('.');
assert.throws(() => manager.getConfig('definitely-not-real'), /Failed to load config/);
});

51
test/config-utils.test.js Normal file
View File

@@ -0,0 +1,51 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const ConfigUtils = require('../src/helper/configUtils.js');
const defaultConfig = {
functionality: {
softwareType: {
default: 'measurement',
rules: { type: 'string' },
},
},
general: {
logging: {
enabled: { default: true, rules: { type: 'boolean' } },
logLevel: {
default: 'info',
rules: {
type: 'enum',
values: [{ value: 'debug' }, { value: 'info' }, { value: 'warn' }, { value: 'error' }],
},
},
},
name: { default: 'default-name', rules: { type: 'string' } },
},
scaling: {
absMin: { default: 0, rules: { type: 'number' } },
absMax: { default: 100, rules: { type: 'number' } },
},
};
test('initConfig applies defaults', () => {
const cfg = new ConfigUtils(defaultConfig, false, 'error');
const result = cfg.initConfig({});
assert.equal(result.general.name, 'default-name');
assert.equal(result.scaling.absMax, 100);
});
test('updateConfig merges nested overrides and revalidates', () => {
const cfg = new ConfigUtils(defaultConfig, false, 'error');
const base = cfg.initConfig({ general: { name: 'sensor-a' } });
const updated = cfg.updateConfig(base, { scaling: { absMax: 150 } });
assert.equal(updated.general.name, 'sensor-a');
assert.equal(updated.scaling.absMax, 150);
});
test('constructor respects explicit logger disabled flag', () => {
const cfg = new ConfigUtils(defaultConfig, false, 'error');
assert.equal(cfg.logger.logging, false);
});

View File

@@ -0,0 +1,26 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const EndpointUtils = require('../src/helper/endpointUtils.js');
test('generateMenuUtilsData returns helpers and compatibility options', () => {
const endpointUtils = new EndpointUtils();
const data = endpointUtils.generateMenuUtilsData('measurement', {
customCheck: 'function(value) { return !!value; }',
});
assert.equal(data.nodeName, 'measurement');
assert.equal(typeof data.helpers.validateRequired, 'string');
assert.equal(typeof data.helpers.customCheck, 'string');
assert.equal(data.options.autoLoadLegacy, true);
});
test('generateMenuUtilsBootstrap points to data and legacy endpoints', () => {
const endpointUtils = new EndpointUtils();
const script = endpointUtils.generateMenuUtilsBootstrap('measurement');
assert.match(script, /menuUtilsData\.json/);
assert.match(script, /menuUtils\.legacy\.js/);
assert.match(script, /window\.EVOLV\.nodes/);
});

21
test/gravity.test.js Normal file
View File

@@ -0,0 +1,21 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const gravity = require('../src/helper/gravity.js');
test('standard gravity constant is available', () => {
assert.ok(Math.abs(gravity.getStandardGravity() - 9.80665) < 1e-9);
});
test('local gravity decreases with elevation', () => {
const seaLevel = gravity.getLocalGravity(45, 0);
const high = gravity.getLocalGravity(45, 1000);
assert.ok(high < seaLevel);
});
test('pressureHead and weightForce use local gravity', () => {
const dp = gravity.pressureHead(1000, 5, 45, 0);
const force = gravity.weightForce(2, 45, 0);
assert.ok(dp > 0);
assert.ok(force > 0);
});

24
test/helpers.js Normal file
View File

@@ -0,0 +1,24 @@
const path = require('node:path');
function makeLogger() {
return {
debug() {},
info() {},
warn() {},
error() {},
};
}
function near(actual, expected, epsilon = 1e-6) {
return Math.abs(actual - expected) <= epsilon;
}
function fixturePath(...segments) {
return path.join(__dirname, ...segments);
}
module.exports = {
makeLogger,
near,
fixturePath,
};

65
test/logger.test.js Normal file
View File

@@ -0,0 +1,65 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const Logger = require('../src/helper/logger.js');
function withPatchedConsole(fn) {
const original = {
debug: console.debug,
info: console.info,
warn: console.warn,
error: console.error,
};
const calls = [];
console.debug = (...args) => calls.push(['debug', ...args]);
console.info = (...args) => calls.push(['info', ...args]);
console.warn = (...args) => calls.push(['warn', ...args]);
console.error = (...args) => calls.push(['error', ...args]);
try {
fn(calls);
} finally {
console.debug = original.debug;
console.info = original.info;
console.warn = original.warn;
console.error = original.error;
}
}
test('respects log level threshold', () => {
withPatchedConsole((calls) => {
const logger = new Logger(true, 'warn', 'T');
logger.debug('a');
logger.info('b');
logger.warn('c');
logger.error('d');
const levels = calls.map((c) => c[0]);
assert.deepEqual(levels, ['warn', 'error']);
});
});
test('toggleLogging disables output', () => {
withPatchedConsole((calls) => {
const logger = new Logger(true, 'debug', 'T');
logger.toggleLogging();
logger.debug('x');
logger.error('y');
assert.equal(calls.length, 0);
});
});
test('setLogLevel updates to valid level', () => {
const logger = new Logger(true, 'debug', 'T');
logger.setLogLevel('error');
assert.equal(logger.logLevel, 'error');
});
test('setLogLevel with invalid value should not throw', () => {
withPatchedConsole(() => {
const logger = new Logger(true, 'debug', 'T');
assert.doesNotThrow(() => logger.setLogLevel('invalid-level'));
assert.equal(logger.logLevel, 'debug');
});
});

View File

@@ -0,0 +1,29 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const MeasurementBuilder = require('../src/measurements/MeasurementBuilder.js');
test('builder requires mandatory fields', () => {
assert.throws(() => new MeasurementBuilder().build(), /Measurement type is required/);
assert.throws(() => new MeasurementBuilder().setType('flow').build(), /Measurement variant is required/);
assert.throws(
() => new MeasurementBuilder().setType('flow').setVariant('measured').build(),
/Measurement position is required/
);
});
test('builder creates measurement with provided config', () => {
const measurement = new MeasurementBuilder()
.setType('flow')
.setVariant('measured')
.setPosition('upstream')
.setWindowSize(25)
.setDistance(3.2)
.build();
assert.equal(measurement.type, 'flow');
assert.equal(measurement.variant, 'measured');
assert.equal(measurement.position, 'upstream');
assert.equal(measurement.windowSize, 25);
assert.equal(measurement.distance, 3.2);
});

View File

@@ -0,0 +1,61 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const MeasurementContainer = require('../src/measurements/MeasurementContainer.js');
function makeContainer() {
return new MeasurementContainer({
windowSize: 10,
defaultUnits: {
flow: 'm3/h',
pressure: 'mbar',
},
});
}
test('stores and retrieves measurements via chain API', () => {
const c = makeContainer();
c.type('flow').variant('measured').position('upstream').value(100, 1, 'm3/h');
assert.equal(c.type('flow').variant('measured').position('upstream').getCurrentValue(), 100);
assert.equal(c.type('flow').variant('measured').position('upstream').exists(), true);
});
test('distance(null) auto-derives from position mapping', () => {
const c = makeContainer();
c.type('pressure').variant('measured').position('upstream').distance(null).value(5, 1, 'mbar');
const m = c.type('pressure').variant('measured').position('upstream').get();
assert.equal(m.distance, Number.POSITIVE_INFINITY);
});
test('getLaggedSample with requested unit converts sample value', () => {
const c = makeContainer();
c.type('flow').variant('measured').position('upstream').value(3.6, 1, 'm3/h');
c.type('flow').variant('measured').position('upstream').value(7.2, 2, 'm3/h');
const previous = c.type('flow').variant('measured').position('upstream').getLaggedSample(1, 'm3/s');
assert.ok(previous);
assert.equal(previous.unit, 'm3/s');
assert.ok(Math.abs(previous.value - 0.001) < 1e-8);
});
test('difference computes current and average delta between positions', () => {
const c = makeContainer();
c.type('pressure').variant('measured').position('downstream').value(120, 1, 'mbar');
c.type('pressure').variant('measured').position('downstream').value(130, 2, 'mbar');
c.type('pressure').variant('measured').position('upstream').value(100, 1, 'mbar');
c.type('pressure').variant('measured').position('upstream').value(110, 2, 'mbar');
const diff = c.type('pressure').variant('measured').difference();
assert.equal(diff.value, 20);
assert.equal(diff.avgDiff, 20);
assert.equal(diff.unit, 'mbar');
});
test('_convertPositionNum2Str maps signs to labels', () => {
const c = makeContainer();
assert.equal(c._convertPositionNum2Str(0), 'atEquipment');
assert.equal(c._convertPositionNum2Str(1), 'downstream');
assert.equal(c._convertPositionNum2Str(-1), 'upstream');
});

49
test/measurement.test.js Normal file
View File

@@ -0,0 +1,49 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const Measurement = require('../src/measurements/Measurement.js');
const { near } = require('./helpers.js');
test('maintains rolling window and exposes stats', () => {
const m = new Measurement('flow', 'measured', 'upstream', 3);
m.setValue(10, 1).setValue(20, 2).setValue(30, 3).setValue(40, 4);
assert.deepEqual(m.getAllValues().values, [20, 30, 40]);
assert.deepEqual(m.getAllValues().timestamps, [2, 3, 4]);
assert.equal(m.getCurrentValue(), 40);
assert.equal(m.getAverage(), 30);
assert.equal(m.getMin(), 20);
assert.equal(m.getMax(), 40);
});
test('lag semantics: lag=1 is previous sample', () => {
const m = new Measurement('flow', 'measured', 'upstream', 5);
m.setValue(10, 100).setValue(20, 200).setValue(30, 300);
assert.equal(m.getLaggedSample(0).value, 30);
assert.equal(m.getLaggedSample(1).value, 20);
assert.equal(m.getLaggedValue(1), 20);
});
test('convertTo converts values to target unit', () => {
const m = new Measurement('flow', 'measured', 'upstream', 5);
m.setUnit('m3/h');
m.setValue(3.6, 1);
const converted = m.convertTo('m3/s');
assert.ok(near(converted.getCurrentValue(), 0.001, 1e-8));
assert.equal(converted.unit, 'm3/s');
assert.equal(converted.getLatestTimestamp(), 1);
});
test('createDifference aligns timestamps and subtracts downstream from upstream', () => {
const up = new Measurement('pressure', 'measured', 'upstream', 10).setUnit('mbar');
const down = new Measurement('pressure', 'measured', 'downstream', 10).setUnit('mbar');
up.setValue(120, 1).setValue(140, 2);
down.setValue(100, 2).setValue(95, 3);
const diff = Measurement.createDifference(up, down);
assert.deepEqual(diff.getAllValues().timestamps, [2]);
assert.deepEqual(diff.getAllValues().values, [40]);
});

20
test/menu-manager.test.js Normal file
View File

@@ -0,0 +1,20 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const MenuManager = require('../src/menu/index.js');
test('createEndpoint returns script including initEditor and menuData', () => {
const manager = new MenuManager();
const script = manager.createEndpoint('measurement', ['asset', 'logger', 'position']);
assert.match(script, /window\.EVOLV\.nodes\.measurement\.initEditor/);
assert.match(script, /window\.EVOLV\.nodes\.measurement\.menuData/);
});
test('_getSoftwareType resolves to string identifier', () => {
const manager = new MenuManager();
const softwareType = manager._getSoftwareType('measurement');
assert.equal(typeof softwareType, 'string');
assert.equal(softwareType, 'measurement');
});

37
test/nrmse.test.js Normal file
View File

@@ -0,0 +1,37 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const ErrorMetrics = require('../src/nrmse/errorMetrics.js');
const { makeLogger } = require('./helpers.js');
test('MSE and RMSE calculations are correct', () => {
const m = new ErrorMetrics({}, makeLogger());
const predicted = [1, 2, 3];
const measured = [1, 3, 5];
assert.ok(Math.abs(m.meanSquaredError(predicted, measured) - 5 / 3) < 1e-9);
assert.ok(Math.abs(m.rootMeanSquaredError(predicted, measured) - Math.sqrt(5 / 3)) < 1e-9);
});
test('normalizeUsingRealtime throws when range is zero', () => {
const m = new ErrorMetrics({}, makeLogger());
assert.throws(() => m.normalizeUsingRealtime([1, 1, 1], [1, 1, 1]), /Invalid process range/);
});
test('longTermNRMSD returns 0 before 100 samples and value after', () => {
const m = new ErrorMetrics({}, makeLogger());
for (let i = 0; i < 99; i++) {
assert.equal(m.longTermNRMSD(0.1), 0);
}
assert.notEqual(m.longTermNRMSD(0.2), 0);
});
test('assessDrift returns expected result envelope', () => {
const m = new ErrorMetrics({}, makeLogger());
const out = m.assessDrift([100, 101, 102], [99, 100, 103], 90, 110);
assert.equal(typeof out.nrmse, 'number');
assert.equal(typeof out.longTermNRMSD, 'number');
assert.ok('immediateLevel' in out);
assert.ok('longTermLevel' in out);
});

42
test/output-utils.test.js Normal file
View File

@@ -0,0 +1,42 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const OutputUtils = require('../src/helper/outputUtils.js');
const config = {
functionality: { softwareType: 'measurement', role: 'sensor' },
general: { id: 'abc', unit: 'mbar' },
asset: {
uuid: 'u1',
tagcode: 't1',
geoLocation: { lat: 51.6, lon: 4.7 },
category: 'measurement',
type: 'pressure',
model: 'M1',
},
};
test('process format emits message with changed fields only', () => {
const out = new OutputUtils();
const first = out.formatMsg({ a: 1, b: 2 }, config, 'process');
assert.equal(first.topic, 'measurement_abc');
assert.deepEqual(first.payload, { a: 1, b: 2 });
const second = out.formatMsg({ a: 1, b: 2 }, config, 'process');
assert.equal(second, null);
const third = out.formatMsg({ a: 1, b: 3, c: { x: 1 } }, config, 'process');
assert.deepEqual(third.payload, { b: 3, c: JSON.stringify({ x: 1 }) });
});
test('influx format flattens tags and stringifies tag values', () => {
const out = new OutputUtils();
const msg = out.formatMsg({ value: 10 }, config, 'influxdb');
assert.equal(msg.topic, 'measurement_abc');
assert.equal(msg.payload.measurement, 'measurement_abc');
assert.equal(msg.payload.tags.geoLocation_lat, '51.6');
assert.equal(msg.payload.tags.geoLocation_lon, '4.7');
assert.ok(msg.payload.timestamp instanceof Date);
});

View File

@@ -0,0 +1,62 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const ValidationUtils = require('../src/helper/validationUtils.js');
const schema = {
functionality: {
softwareType: {
default: 'measurement',
rules: { type: 'string' },
},
},
enabled: {
default: true,
rules: { type: 'boolean' },
},
mode: {
default: 'auto',
rules: {
type: 'enum',
values: [{ value: 'auto' }, { value: 'manual' }],
},
},
name: {
default: 'sensor',
rules: { type: 'string' },
},
};
test('validateSchema applies defaults and type coercion where supported', () => {
const validation = new ValidationUtils(false, 'error');
const result = validation.validateSchema({ enabled: 'true', name: 'SENSOR' }, schema, 'test');
assert.equal(result.enabled, true);
assert.equal(result.name, 'sensor');
assert.equal(result.mode, 'auto');
assert.equal(result.functionality.softwareType, 'measurement');
});
test('enum with non-string value falls back to default', () => {
const validation = new ValidationUtils(false, 'error');
const result = validation.validateSchema({ mode: 123 }, schema, 'test');
assert.equal(result.mode, 'auto');
});
test('curve validation falls back to default for invalid dimension structure', () => {
const validation = new ValidationUtils(false, 'error');
const defaultCurve = { 1: { x: [1, 2], y: [10, 20] } };
const invalid = { 1: { x: [2, 1], y: [20, 10] } };
const curve = validation.validateCurve(invalid, defaultCurve);
assert.deepEqual(curve, defaultCurve);
});
test('removeUnwantedKeys handles primitive values without throwing', () => {
const validation = new ValidationUtils(false, 'error');
const input = {
a: { default: 1, rules: { type: 'number' } },
b: 2,
c: 'x',
};
assert.doesNotThrow(() => validation.removeUnwantedKeys(input));
});