Compare commits
9 Commits
5df3881375
...
dev-Rene
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
067017f2ea | ||
|
|
52f1cf73b4 | ||
|
|
a81733c492 | ||
|
|
555d4d865b | ||
|
|
db85100c4d | ||
|
|
b884faf402 | ||
|
|
2c43d28f76 | ||
|
|
d52a1827e3 | ||
|
|
f2c9134b64 |
89
datasets/assetData/index.js
Normal file
89
datasets/assetData/index.js
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
class AssetCategoryManager {
|
||||||
|
constructor(relPath = '.') {
|
||||||
|
this.assetDir = path.resolve(__dirname, relPath);
|
||||||
|
this.cache = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
getCategory(softwareType) {
|
||||||
|
if (!softwareType) {
|
||||||
|
throw new Error('softwareType is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cache.has(softwareType)) {
|
||||||
|
return this.cache.get(softwareType);
|
||||||
|
}
|
||||||
|
|
||||||
|
const filePath = path.resolve(this.assetDir, `${softwareType}.json`);
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
throw new Error(`Asset data '${softwareType}' not found in ${this.assetDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const raw = fs.readFileSync(filePath, 'utf8');
|
||||||
|
const parsed = JSON.parse(raw);
|
||||||
|
this.cache.set(softwareType, parsed);
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasCategory(softwareType) {
|
||||||
|
const filePath = path.resolve(this.assetDir, `${softwareType}.json`);
|
||||||
|
return fs.existsSync(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
listCategories({ withMeta = false } = {}) {
|
||||||
|
const files = fs.readdirSync(this.assetDir, { withFileTypes: true });
|
||||||
|
|
||||||
|
return files
|
||||||
|
.filter(
|
||||||
|
(entry) =>
|
||||||
|
entry.isFile() &&
|
||||||
|
entry.name.endsWith('.json') &&
|
||||||
|
entry.name !== 'index.json' &&
|
||||||
|
entry.name !== 'assetData.json'
|
||||||
|
)
|
||||||
|
.map((entry) => path.basename(entry.name, '.json'))
|
||||||
|
.map((name) => {
|
||||||
|
if (!withMeta) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = this.getCategory(name);
|
||||||
|
return {
|
||||||
|
softwareType: data.softwareType || name,
|
||||||
|
label: data.label || name,
|
||||||
|
file: `${name}.json`
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
searchCategories(query) {
|
||||||
|
const term = (query || '').trim().toLowerCase();
|
||||||
|
if (!term) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.listCategories({ withMeta: true }).filter(
|
||||||
|
({ softwareType, label }) =>
|
||||||
|
softwareType.toLowerCase().includes(term) ||
|
||||||
|
label.toLowerCase().includes(term)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearCache() {
|
||||||
|
this.cache.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const assetCategoryManager = new AssetCategoryManager();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
AssetCategoryManager,
|
||||||
|
assetCategoryManager,
|
||||||
|
getCategory: (softwareType) => assetCategoryManager.getCategory(softwareType),
|
||||||
|
listCategories: (options) => assetCategoryManager.listCategories(options),
|
||||||
|
searchCategories: (query) => assetCategoryManager.searchCategories(query),
|
||||||
|
hasCategory: (softwareType) => assetCategoryManager.hasCategory(softwareType),
|
||||||
|
clearCache: () => assetCategoryManager.clearCache()
|
||||||
|
};
|
||||||
21
datasets/assetData/machine.json
Normal file
21
datasets/assetData/machine.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"id": "machine",
|
||||||
|
"label": "machine",
|
||||||
|
"softwareType": "machine",
|
||||||
|
"suppliers": [
|
||||||
|
{
|
||||||
|
"id": "hidrostal",
|
||||||
|
"name": "Hidrostal",
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"id": "pump-centrifugal",
|
||||||
|
"name": "Centrifugal",
|
||||||
|
"models": [
|
||||||
|
{ "id": "hidrostal-H05K-S03R", "name": "hidrostal-H05K-S03R", "units": ["l/s","m3/h"] },
|
||||||
|
{ "id": "hidrostal-C5-D03R-SHN1", "name": "hidrostal-C5-D03R-SHN1", "units": ["l/s"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
52
datasets/assetData/measurement.json
Normal file
52
datasets/assetData/measurement.json
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"id": "sensor",
|
||||||
|
"label": "Sensor",
|
||||||
|
"softwareType": "measurement",
|
||||||
|
"suppliers": [
|
||||||
|
{
|
||||||
|
"id": "vega",
|
||||||
|
"name": "Vega",
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"id": "temperature",
|
||||||
|
"name": "Temperature",
|
||||||
|
"models": [
|
||||||
|
{ "id": "vega-temp-10", "name": "VegaTemp 10", "units": ["degC", "degF"] },
|
||||||
|
{ "id": "vega-temp-20", "name": "VegaTemp 20", "units": ["degC", "degF"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "pressure",
|
||||||
|
"name": "Pressure",
|
||||||
|
"models": [
|
||||||
|
{ "id": "vega-pressure-10", "name": "VegaPressure 10", "units": ["bar", "mbar", "psi"] },
|
||||||
|
{ "id": "vega-pressure-20", "name": "VegaPressure 20", "units": ["bar", "mbar", "psi"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "flow",
|
||||||
|
"name": "Flow",
|
||||||
|
"models": [
|
||||||
|
{ "id": "vega-flow-10", "name": "VegaFlow 10", "units": ["m3/h", "gpm", "l/min"] },
|
||||||
|
{ "id": "vega-flow-20", "name": "VegaFlow 20", "units": ["m3/h", "gpm", "l/min"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "level",
|
||||||
|
"name": "Level",
|
||||||
|
"models": [
|
||||||
|
{ "id": "vega-level-10", "name": "VegaLevel 10", "units": ["m", "ft", "mm"] },
|
||||||
|
{ "id": "vega-level-20", "name": "VegaLevel 20", "units": ["m", "ft", "mm"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "oxygen",
|
||||||
|
"name": "Quantity (oxygen)",
|
||||||
|
"models": [
|
||||||
|
{ "id": "vega-oxy-10", "name": "VegaOxySense 10", "units": ["g/m3", "mol/m3"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
datasets/assetData/modelData/ECDV.json
Normal file
16
datasets/assetData/modelData/ECDV.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"1.204": {
|
||||||
|
"125": {
|
||||||
|
"x": [0,10,20,30,40,50,60,70,80,90,100],
|
||||||
|
"y": [0,18,50,95,150,216,337,564,882,1398,1870]
|
||||||
|
},
|
||||||
|
"150": {
|
||||||
|
"x": [0,10,20,30,40,50,60,70,80,90,100],
|
||||||
|
"y": [0,25,73,138,217,314,490,818,1281,2029,2715]
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"x": [0,10,20,30,40,50,60,70,80,90,100],
|
||||||
|
"y": [0,155,443,839,1322,1911,2982,4980,7795,12349,16524]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
838
datasets/assetData/modelData/hidrostal-C5-D03R-SHN1.json
Normal file
838
datasets/assetData/modelData/hidrostal-C5-D03R-SHN1.json
Normal file
@@ -0,0 +1,838 @@
|
|||||||
|
{
|
||||||
|
"np": {
|
||||||
|
"400": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5953611390998625,
|
||||||
|
1.6935085477165994,
|
||||||
|
3.801139124304824,
|
||||||
|
7.367829525776738,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.8497068236812997,
|
||||||
|
3.801139124304824,
|
||||||
|
7.367829525776738,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"600": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.7497197821018213,
|
||||||
|
3.801139124304824,
|
||||||
|
7.367829525776738,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"700": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.788320579602724,
|
||||||
|
3.9982668237045984,
|
||||||
|
7.367829525776738,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"800": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.7824519364844427,
|
||||||
|
3.9885060367793064,
|
||||||
|
7.367829525776738,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"900": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6934482683506376,
|
||||||
|
3.9879559558537054,
|
||||||
|
7.367829525776738,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1000": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6954385513069579,
|
||||||
|
4.0743508382926795,
|
||||||
|
7.422392692482345,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1100": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
4.160745720731654,
|
||||||
|
7.596626714476177,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1200": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
4.302551231007837,
|
||||||
|
7.637247864947884,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1300": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
4.37557913990704,
|
||||||
|
7.773442147000839,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1400": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
4.334434337766139,
|
||||||
|
7.940911352646818,
|
||||||
|
12.081735423116616
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1500": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
4.2327206586037995,
|
||||||
|
8.005238800611183,
|
||||||
|
12.254836577088351
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1600": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
4.195405588464695,
|
||||||
|
7.991827302945298,
|
||||||
|
12.423663269044452
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1700": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
14.255458319309813,
|
||||||
|
8.096768422220196,
|
||||||
|
12.584668380908582
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1800": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
31.54620347513727,
|
||||||
|
12.637080520201405
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1900": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
8.148423429611098,
|
||||||
|
12.74916725120127
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2000": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
8.146439484120116,
|
||||||
|
12.905178964345618
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2100": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
8.149576025637684,
|
||||||
|
13.006940917309247
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2200": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
8.126246430368305,
|
||||||
|
13.107503837410825
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2300": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
8.104379361635342,
|
||||||
|
13.223235973280122
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2400": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
8.135190080423746,
|
||||||
|
13.36128347785936
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2500": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
7.981219508598527,
|
||||||
|
13.473697427231842
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2600": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
7.863899404441271,
|
||||||
|
13.50303289156837
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2700": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
7.658860522528131,
|
||||||
|
13.485230880073107
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2800": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
7.44407948309266,
|
||||||
|
13.446135725634615
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2900": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
0.5522732775894703,
|
||||||
|
1.6920721090317592,
|
||||||
|
3.8742719210788685,
|
||||||
|
7.44407948309266,
|
||||||
|
13.413693596332184
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nq": {
|
||||||
|
"400": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
7.6803204433986965,
|
||||||
|
25.506609120436963,
|
||||||
|
35.4,
|
||||||
|
44.4,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
22.622804921188227,
|
||||||
|
35.4,
|
||||||
|
44.4,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"600": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
19.966301579194372,
|
||||||
|
35.4,
|
||||||
|
44.4,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"700": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
17.430763940163832,
|
||||||
|
33.79508340848005,
|
||||||
|
44.4,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"800": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
14.752921911234477,
|
||||||
|
31.71885034449889,
|
||||||
|
44.4,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"900": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
11.854693031181021,
|
||||||
|
29.923046639543475,
|
||||||
|
44.4,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1000": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.549433913822687,
|
||||||
|
26.734189128096668,
|
||||||
|
43.96760750800311,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1100": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
26.26933164936586,
|
||||||
|
42.23523193272671,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1200": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
24.443114637042832,
|
||||||
|
40.57167959798151,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1300": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
22.41596168949836,
|
||||||
|
39.04561852479495,
|
||||||
|
52.5
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1400": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
20.276864821170303,
|
||||||
|
37.557663261443224,
|
||||||
|
52.252852231224054
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1500": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
18.252772588147742,
|
||||||
|
35.9974418607538,
|
||||||
|
50.68604059588987
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1600": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
16.31441663648616,
|
||||||
|
34.51170378091407,
|
||||||
|
49.20153034100798
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1700": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
14.255458319309813,
|
||||||
|
33.043410795291045,
|
||||||
|
47.820213744181245
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1800": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
31.54620347513727,
|
||||||
|
46.51705619739449
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1900": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
29.986013742375484,
|
||||||
|
45.29506741639918
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2000": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
28.432646044605782,
|
||||||
|
44.107822395271945
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2100": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
26.892634464336055,
|
||||||
|
42.758175515158776
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2200": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
25.270679127870263,
|
||||||
|
41.467063889795895
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2300": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
23.531132157718837,
|
||||||
|
40.293041104955826
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2400": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
21.815645106750623,
|
||||||
|
39.03109248860755
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2500": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
20.34997949463564,
|
||||||
|
37.71320701654063
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2600": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
18.81710568651804,
|
||||||
|
36.35563657017404
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2700": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
17.259072160217805,
|
||||||
|
35.02979557646653
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2800": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
16,
|
||||||
|
33.74372254979665
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"2900": {
|
||||||
|
"x": [
|
||||||
|
0,
|
||||||
|
25.510204081632654,
|
||||||
|
51.020408163265309,
|
||||||
|
76.530612244897952,
|
||||||
|
100
|
||||||
|
],
|
||||||
|
"y": [
|
||||||
|
6.4,
|
||||||
|
9.500000000000002,
|
||||||
|
12.7,
|
||||||
|
16,
|
||||||
|
32.54934541379723
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1062
datasets/assetData/modelData/hidrostal-H05K-S03R.json
Normal file
1062
datasets/assetData/modelData/hidrostal-H05K-S03R.json
Normal file
File diff suppressed because it is too large
Load Diff
124
datasets/assetData/modelData/index.js
Normal file
124
datasets/assetData/modelData/index.js
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
class AssetLoader {
|
||||||
|
constructor() {
|
||||||
|
this.relPath = './'
|
||||||
|
this.baseDir = path.resolve(__dirname, this.relPath);
|
||||||
|
this.cache = new Map(); // Cache loaded JSON files for better performance
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a specific curve by type
|
||||||
|
* @param {string} curveType - The curve identifier (e.g., 'hidrostal-H05K-S03R')
|
||||||
|
* @returns {Object|null} The curve data object or null if not found
|
||||||
|
*/
|
||||||
|
loadModel(modelType) {
|
||||||
|
return this.loadAsset('models', modelType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load any asset from a specific dataset folder
|
||||||
|
* @param {string} datasetType - The dataset folder name (e.g., 'curves', 'assetData')
|
||||||
|
* @param {string} assetId - The specific asset identifier
|
||||||
|
* @returns {Object|null} The asset data object or null if not found
|
||||||
|
*/
|
||||||
|
loadAsset(datasetType, assetId) {
|
||||||
|
//const cacheKey = `${datasetType}/${assetId}`;
|
||||||
|
const cacheKey = `${assetId}`;
|
||||||
|
|
||||||
|
|
||||||
|
// Check cache first
|
||||||
|
if (this.cache.has(cacheKey)) {
|
||||||
|
return this.cache.get(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const filePath = path.join(this.baseDir, `${assetId}.json`);
|
||||||
|
|
||||||
|
// Check if file exists
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
console.warn(`Asset not found: ${filePath}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load and parse JSON
|
||||||
|
const rawData = fs.readFileSync(filePath, 'utf8');
|
||||||
|
const assetData = JSON.parse(rawData);
|
||||||
|
|
||||||
|
// Cache the result
|
||||||
|
this.cache.set(cacheKey, assetData);
|
||||||
|
|
||||||
|
return assetData;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error loading asset ${cacheKey}:`, error.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all available assets in a dataset
|
||||||
|
* @param {string} datasetType - The dataset folder name
|
||||||
|
* @returns {string[]} Array of available asset IDs
|
||||||
|
*/
|
||||||
|
getAvailableAssets(datasetType) {
|
||||||
|
try {
|
||||||
|
const datasetPath = path.join(this.baseDir, datasetType);
|
||||||
|
|
||||||
|
if (!fs.existsSync(datasetPath)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.readdirSync(datasetPath)
|
||||||
|
.filter(file => file.endsWith('.json'))
|
||||||
|
.map(file => file.replace('.json', ''));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error reading dataset ${datasetType}:`, error.message);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the cache (useful for development/testing)
|
||||||
|
*/
|
||||||
|
clearCache() {
|
||||||
|
this.cache.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and export a singleton instance
|
||||||
|
const assetLoader = new AssetLoader();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
AssetLoader,
|
||||||
|
assetLoader,
|
||||||
|
// Convenience methods for backward compatibility
|
||||||
|
loadModel: (modelType) => assetLoader.loadModel(modelType),
|
||||||
|
loadAsset: (datasetType, assetId) => assetLoader.loadAsset(datasetType, assetId),
|
||||||
|
getAvailableAssets: (datasetType) => assetLoader.getAvailableAssets(datasetType)
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Example usage in your scripts
|
||||||
|
const loader = new AssetLoader();
|
||||||
|
|
||||||
|
// Load a specific curve
|
||||||
|
const curve = loader.loadModel('hidrostal-H05K-S03R');
|
||||||
|
if (curve) {
|
||||||
|
console.log('Model loaded:', curve);
|
||||||
|
} else {
|
||||||
|
console.log('Model not found');
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// Load any asset from any dataset
|
||||||
|
const someAsset = loadAsset('assetData', 'some-asset-id');
|
||||||
|
|
||||||
|
// Get list of available models
|
||||||
|
const availableCurves = getAvailableAssets('curves');
|
||||||
|
console.log('Available curves:', availableCurves);
|
||||||
|
|
||||||
|
// Using the class directly for more control
|
||||||
|
const { AssetLoader } = require('./index.js');
|
||||||
|
const customLoader = new AssetLoader();
|
||||||
|
const data = customLoader.loadCurve('hidrostal-H05K-S03R');
|
||||||
|
*/
|
||||||
27
datasets/assetData/valve.json
Normal file
27
datasets/assetData/valve.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"id": "valve",
|
||||||
|
"label": "valve",
|
||||||
|
"softwareType": "valve",
|
||||||
|
"suppliers": [
|
||||||
|
{
|
||||||
|
"id": "binder",
|
||||||
|
"name": "Binder Engineering",
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"id": "valve-gate",
|
||||||
|
"name": "Gate",
|
||||||
|
"models": [
|
||||||
|
{ "id": "binder-valve-001", "name": "ECDV", "units": ["m3/h", "gpm", "l/min"] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valve-jet",
|
||||||
|
"name": "Jet",
|
||||||
|
"models": [
|
||||||
|
{ "id": "binder-valve-002", "name": "JCV", "units": ["m3/h", "gpm", "l/min"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
6
index.js
6
index.js
@@ -26,7 +26,8 @@ const MenuManager = require('./src/menu/index.js');
|
|||||||
const predict = require('./src/predict/predict_class.js');
|
const predict = require('./src/predict/predict_class.js');
|
||||||
const interpolation = require('./src/predict/interpolation.js');
|
const interpolation = require('./src/predict/interpolation.js');
|
||||||
const childRegistrationUtils = require('./src/helper/childRegistrationUtils.js');
|
const childRegistrationUtils = require('./src/helper/childRegistrationUtils.js');
|
||||||
const { loadCurve } = require('./datasets/assetData/curves/index.js');
|
const { loadCurve } = require('./datasets/assetData/curves/index.js'); //deprecated replace with load model data
|
||||||
|
const { loadModel } = require('./datasets/assetData/modelData/index.js');
|
||||||
|
|
||||||
// Export everything
|
// Export everything
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -45,6 +46,7 @@ module.exports = {
|
|||||||
convert,
|
convert,
|
||||||
MenuManager,
|
MenuManager,
|
||||||
childRegistrationUtils,
|
childRegistrationUtils,
|
||||||
loadCurve,
|
loadCurve, //deprecated replace with loadModel
|
||||||
|
loadModel,
|
||||||
gravity
|
gravity
|
||||||
};
|
};
|
||||||
|
|||||||
256
src/configs/monster.json
Normal file
256
src/configs/monster.json
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
{
|
||||||
|
"general": {
|
||||||
|
"name": {
|
||||||
|
"default": "Monster Configuration",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A human-readable name or label for this configuration."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"default": null,
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true,
|
||||||
|
"description": "A unique identifier for this configuration. If not provided, defaults to null."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"unit": {
|
||||||
|
"default": "unitless",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The unit for this configuration (e.g., 'meters', 'seconds', 'unitless')."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"logging": {
|
||||||
|
"logLevel": {
|
||||||
|
"default": "info",
|
||||||
|
"rules": {
|
||||||
|
"type": "enum",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": "debug",
|
||||||
|
"description": "Log messages are printed for debugging purposes."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "info",
|
||||||
|
"description": "Informational messages are printed."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "warn",
|
||||||
|
"description": "Warning messages are printed."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "error",
|
||||||
|
"description": "Error messages are printed."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enabled": {
|
||||||
|
"default": true,
|
||||||
|
"rules": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Indicates whether logging is active. If true, log messages will be generated."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"functionality": {
|
||||||
|
"softwareType": {
|
||||||
|
"default": "monster",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specified software type for this configuration."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
"default": "samplingCabinet",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Indicates the role this configuration plays (e.g., sensor, controller, etc.)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"asset": {
|
||||||
|
"uuid": {
|
||||||
|
"default": null,
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true,
|
||||||
|
"description": "Asset tag number which is a universally unique identifier for this asset. May be null if not assigned."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"geoLocation": {
|
||||||
|
"default": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "An object representing the asset's physical coordinates or location.",
|
||||||
|
"schema": {
|
||||||
|
"x": {
|
||||||
|
"default": 0,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "X coordinate of the asset's location."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"default": 0,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Y coordinate of the asset's location."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"default": 0,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Z coordinate of the asset's location."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"supplier": {
|
||||||
|
"default": "Unknown",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The supplier or manufacturer of the asset."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"default": "sensor",
|
||||||
|
"rules": {
|
||||||
|
"type": "enum",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": "sensor",
|
||||||
|
"description": "A device that detects or measures a physical property and responds to it (e.g. temperature sensor)."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"subType": {
|
||||||
|
"default": "pressure",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A more specific classification within 'type'. For example, 'pressure' for a pressure sensor."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"default": "Unknown",
|
||||||
|
"rules": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A user-defined or manufacturer-defined model identifier for the asset."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"emptyWeightBucket": {
|
||||||
|
"default": 3,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "The weight of the empty bucket in kilograms."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"constraints": {
|
||||||
|
"samplingtime": {
|
||||||
|
"default": 0,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "The time interval between sampling events (in seconds) if not using a flow meter."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"samplingperiod": {
|
||||||
|
"default": 24,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "The fixed period in hours in which a composite sample is collected."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minVolume": {
|
||||||
|
"default": 5,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 5,
|
||||||
|
"description": "The minimum volume in liters."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"maxWeight": {
|
||||||
|
"default": 23,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"max": 23,
|
||||||
|
"description": "The maximum weight in kilograms."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"subSampleVolume": {
|
||||||
|
"default": 50,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 50,
|
||||||
|
"max": 50,
|
||||||
|
"description": "The volume of each sub-sample in milliliters."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"storageTemperature": {
|
||||||
|
"default": {
|
||||||
|
"min": 1,
|
||||||
|
"max": 5
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Acceptable storage temperature range for samples in degrees Celsius.",
|
||||||
|
"schema": {
|
||||||
|
"min": {
|
||||||
|
"default": 1,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 1,
|
||||||
|
"description": "Minimum acceptable storage temperature in degrees Celsius."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"default": 5,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"max": 5,
|
||||||
|
"description": "Maximum acceptable storage temperature in degrees Celsius."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flowmeter": {
|
||||||
|
"default": true,
|
||||||
|
"rules": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Indicates whether a flow meter is used for proportional sampling."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"closedSystem": {
|
||||||
|
"default": false,
|
||||||
|
"rules": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Indicates if the sampling system is closed (true) or open (false)."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"intakeSpeed": {
|
||||||
|
"default": 0.3,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Minimum intake speed in meters per second."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"intakeDiameter": {
|
||||||
|
"default": 12,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Minimum inner diameter of the intake tubing in millimeters."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -299,6 +299,23 @@
|
|||||||
"description": "Reference height to use to identify the height vs other basins with. This will say something more about the expected pressure loss in m head"
|
"description": "Reference height to use to identify the height vs other basins with. This will say something more about the expected pressure loss in m head"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"minHeightBasedOn": {
|
||||||
|
"default": "outlet",
|
||||||
|
"rules": {
|
||||||
|
"type": "enum",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": "inlet",
|
||||||
|
"description": "Minimum height is based on inlet elevation."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "outlet",
|
||||||
|
"description": "Minimum height is based on outlet elevation."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Basis for minimum height check: inlet or outlet."
|
||||||
|
}
|
||||||
|
},
|
||||||
"staticHead": {
|
"staticHead": {
|
||||||
"default": 12,
|
"default": 12,
|
||||||
"rules": {
|
"rules": {
|
||||||
@@ -401,19 +418,36 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"levelbased": {
|
"levelbased": {
|
||||||
"thresholds": {
|
"startLevel": {
|
||||||
"default": [30,40,50,60,70,80,90],
|
"default": 1,
|
||||||
"rules": {
|
|
||||||
"type": "array",
|
|
||||||
"description": "Each time a threshold is overwritten a new pump can start or kick into higher gear. Volume thresholds (%) in ascending order used for level-based control."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"timeThresholdSeconds": {
|
|
||||||
"default": 5,
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"description": "Duration the volume condition must persist before triggering pump actions (seconds)."
|
"description": "start of pump / group when level reaches this in meters starting from bottom."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"stopLevel": {
|
||||||
|
"default": 1,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 0,
|
||||||
|
"description": "stop of pump / group when level reaches this in meters starting from bottom"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minFlowLevel": {
|
||||||
|
"default": 1,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 0,
|
||||||
|
"description": "min level to scale the flow lineair"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"maxFlowLevel": {
|
||||||
|
"default": 4,
|
||||||
|
"rules": {
|
||||||
|
"type": "number",
|
||||||
|
"min": 0,
|
||||||
|
"description": "max level to scale the flow lineair"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -552,7 +586,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"timeleftToFullOrEmptyThresholdSeconds": {
|
"timeleftToFullOrEmptyThresholdSeconds": {
|
||||||
"default": 120,
|
"default": 0,
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"unit": {
|
"unit": {
|
||||||
"default": "m3/h",
|
"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')."
|
||||||
@@ -260,6 +260,7 @@
|
|||||||
"statuscheck",
|
"statuscheck",
|
||||||
"execmovement",
|
"execmovement",
|
||||||
"execsequence",
|
"execsequence",
|
||||||
|
"flowmovement",
|
||||||
"emergencystop",
|
"emergencystop",
|
||||||
"entermaintenance"
|
"entermaintenance"
|
||||||
],
|
],
|
||||||
@@ -273,6 +274,7 @@
|
|||||||
"default": [
|
"default": [
|
||||||
"statuscheck",
|
"statuscheck",
|
||||||
"execmovement",
|
"execmovement",
|
||||||
|
"flowmovement",
|
||||||
"execsequence",
|
"execsequence",
|
||||||
"emergencystop",
|
"emergencystop",
|
||||||
"exitmaintenance"
|
"exitmaintenance"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class MeasurementContainer {
|
|||||||
this.windowSize = options.windowSize || 10; // Default window size
|
this.windowSize = options.windowSize || 10; // Default window size
|
||||||
|
|
||||||
// For chaining context
|
// For chaining context
|
||||||
|
this._currentChildId = null;
|
||||||
this._currentType = null;
|
this._currentType = null;
|
||||||
this._currentVariant = null;
|
this._currentVariant = null;
|
||||||
this._currentPosition = null;
|
this._currentPosition = null;
|
||||||
@@ -49,6 +50,11 @@ class MeasurementContainer {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
child(childId) {
|
||||||
|
this._currentChildId = childId || 'default';
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
setChildName(childName) {
|
setChildName(childName) {
|
||||||
this.childName = childName;
|
this.childName = childName;
|
||||||
return this;
|
return this;
|
||||||
@@ -72,11 +78,19 @@ class MeasurementContainer {
|
|||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUnit(type) {
|
||||||
|
if (!type) return null;
|
||||||
|
if (this.preferredUnits && this.preferredUnits[type]) return this.preferredUnits[type];
|
||||||
|
if (this.defaultUnits && this.defaultUnits[type]) return this.defaultUnits[type];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Chainable methods
|
// Chainable methods
|
||||||
type(typeName) {
|
type(typeName) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +100,7 @@ class MeasurementContainer {
|
|||||||
}
|
}
|
||||||
this._currentVariant = variantName;
|
this._currentVariant = variantName;
|
||||||
this._currentPosition = null;
|
this._currentPosition = null;
|
||||||
|
this._currentChildId = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,8 +227,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;
|
||||||
|
|
||||||
@@ -226,35 +239,46 @@ class MeasurementContainer {
|
|||||||
// Terminal operations - get data out
|
// Terminal operations - get data out
|
||||||
get() {
|
get() {
|
||||||
if (!this._ensureChainIsValid()) return null;
|
if (!this._ensureChainIsValid()) return null;
|
||||||
return this._getOrCreateMeasurement();
|
const variantBucket = this.measurements[this._currentType]?.[this._currentVariant];
|
||||||
|
if (!variantBucket) return null;
|
||||||
|
const posBucket = variantBucket[this._currentPosition];
|
||||||
|
if (!posBucket) return null;
|
||||||
|
|
||||||
|
// Legacy single measurement
|
||||||
|
if (posBucket?.getCurrentValue) return posBucket;
|
||||||
|
|
||||||
|
// Child-aware: pick requested child, otherwise fall back to default, otherwise first available
|
||||||
|
if (posBucket && typeof posBucket === 'object') {
|
||||||
|
const requestedKey = this._currentChildId || this.childId;
|
||||||
|
const keys = Object.keys(posBucket);
|
||||||
|
if (!keys.length) return null;
|
||||||
|
const measurement =
|
||||||
|
(requestedKey && posBucket[requestedKey]) ||
|
||||||
|
posBucket.default ||
|
||||||
|
posBucket[keys[0]];
|
||||||
|
return measurement || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getCurrentValue(requestedUnit = null) {
|
getCurrentValue(requestedUnit = null) {
|
||||||
const measurement = this.get();
|
const measurement = this.get();
|
||||||
if (!measurement) return null;
|
if (!measurement) return null;
|
||||||
|
|
||||||
const value = measurement.getCurrentValue();
|
const value = measurement.getCurrentValue();
|
||||||
if (value === null) return null;
|
if (value === null) return null;
|
||||||
|
if (!requestedUnit || !measurement.unit || requestedUnit === measurement.unit) {
|
||||||
// Return as-is if no unit conversion requested
|
|
||||||
if (!requestedUnit) {
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert if needed
|
|
||||||
if (measurement.unit && requestedUnit !== measurement.unit) {
|
|
||||||
try {
|
try {
|
||||||
return convertModule(value).from(measurement.unit).to(requestedUnit);
|
return convertModule(value).from(measurement.unit).to(requestedUnit);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.logger) {
|
if (this.logger) this.logger.error(`Unit conversion failed: ${error.message}`);
|
||||||
this.logger.error(`Unit conversion failed: ${error.message}`);
|
|
||||||
}
|
|
||||||
return value; // Return original value if conversion fails
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getAverage(requestedUnit = null) {
|
getAverage(requestedUnit = null) {
|
||||||
const measurement = this.get();
|
const measurement = this.get();
|
||||||
@@ -357,6 +381,50 @@ class MeasurementContainer {
|
|||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sum(type, variant, positions = [], targetUnit = null) {
|
||||||
|
const bucket = this.measurements?.[type]?.[variant];
|
||||||
|
if (!bucket) return 0;
|
||||||
|
return positions
|
||||||
|
.map((pos) => {
|
||||||
|
const posBucket = bucket[pos];
|
||||||
|
if (!posBucket) return 0;
|
||||||
|
return Object.values(posBucket)
|
||||||
|
.map((m) => {
|
||||||
|
if (!m?.getCurrentValue) return 0;
|
||||||
|
const val = m.getCurrentValue();
|
||||||
|
if (val == null) return 0;
|
||||||
|
const fromUnit = m.unit || targetUnit;
|
||||||
|
if (!targetUnit || !fromUnit || fromUnit === targetUnit) return val;
|
||||||
|
try { return convertModule(val).from(fromUnit).to(targetUnit); } catch { return val; }
|
||||||
|
})
|
||||||
|
.reduce((acc, v) => acc + (Number.isFinite(v) ? v : 0), 0);
|
||||||
|
})
|
||||||
|
.reduce((acc, v) => acc + v, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFlattenedOutput() {
|
||||||
|
const out = {};
|
||||||
|
Object.entries(this.measurements).forEach(([type, variants]) => {
|
||||||
|
Object.entries(variants).forEach(([variant, positions]) => {
|
||||||
|
Object.entries(positions).forEach(([position, entry]) => {
|
||||||
|
// Legacy single series
|
||||||
|
if (entry?.getCurrentValue) {
|
||||||
|
out[`${type}.${variant}.${position}`] = entry.getCurrentValue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Child-bucketed series
|
||||||
|
if (entry && typeof entry === 'object') {
|
||||||
|
Object.entries(entry).forEach(([childId, m]) => {
|
||||||
|
if (m?.getCurrentValue) {
|
||||||
|
out[`${type}.${variant}.${position}.${childId}`] = m.getCurrentValue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
// Difference calculations between positions
|
// Difference calculations between positions
|
||||||
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
||||||
@@ -364,12 +432,21 @@ difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
|||||||
throw new Error("Type and variant must be specified for difference calculation");
|
throw new Error("Type and variant must be specified for difference calculation");
|
||||||
}
|
}
|
||||||
|
|
||||||
const get = pos =>
|
const get = pos => {
|
||||||
this.measurements?.[this._currentType]?.[this._currentVariant]?.[pos] || null;
|
const bucket = this.measurements?.[this._currentType]?.[this._currentVariant]?.[pos];
|
||||||
|
if (!bucket) return null;
|
||||||
|
// child-aware bucket: pick current childId/default or first available
|
||||||
|
if (bucket && typeof bucket === 'object' && !bucket.getCurrentValue) {
|
||||||
|
const childKey = this._currentChildId || this.childId || Object.keys(bucket)[0];
|
||||||
|
return bucket?.[childKey] || null;
|
||||||
|
}
|
||||||
|
// legacy single measurement
|
||||||
|
return bucket;
|
||||||
|
};
|
||||||
|
|
||||||
const a = get(from);
|
const a = get(from);
|
||||||
const b = get(to);
|
const b = get(to);
|
||||||
if (!a || !b || a.values.length === 0 || b.values.length === 0) {
|
if (!a || !b || !a.values || !b.values || a.values.length === 0 || b.values.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,13 +457,7 @@ difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
|||||||
const aAvg = this._convertValueToUnit(a.getAverage(), a.unit, targetUnit);
|
const aAvg = this._convertValueToUnit(a.getAverage(), a.unit, targetUnit);
|
||||||
const bAvg = this._convertValueToUnit(b.getAverage(), b.unit, targetUnit);
|
const bAvg = this._convertValueToUnit(b.getAverage(), b.unit, targetUnit);
|
||||||
|
|
||||||
return {
|
return { value: aVal - bVal, avgDiff: aAvg - bAvg, unit: targetUnit, from, to };
|
||||||
value: aVal - bVal,
|
|
||||||
avgDiff: aAvg - bAvg,
|
|
||||||
unit: targetUnit,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
@@ -410,18 +481,26 @@ difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
|
|||||||
this.measurements[this._currentType][this._currentVariant] = {};
|
this.measurements[this._currentType][this._currentVariant] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.measurements[this._currentType][this._currentVariant][this._currentPosition]) {
|
const positionKey = this._currentPosition;
|
||||||
this.measurements[this._currentType][this._currentVariant][this._currentPosition] =
|
const childKey = this._currentChildId || this.childId || 'default';
|
||||||
new MeasurementBuilder()
|
|
||||||
|
if (!this.measurements[this._currentType][this._currentVariant][positionKey]) {
|
||||||
|
this.measurements[this._currentType][this._currentVariant][positionKey] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const bucket = this.measurements[this._currentType][this._currentVariant][positionKey];
|
||||||
|
|
||||||
|
if (!bucket[childKey]) {
|
||||||
|
bucket[childKey] = new MeasurementBuilder()
|
||||||
.setType(this._currentType)
|
.setType(this._currentType)
|
||||||
.setVariant(this._currentVariant)
|
.setVariant(this._currentVariant)
|
||||||
.setPosition(this._currentPosition)
|
.setPosition(positionKey)
|
||||||
.setWindowSize(this.windowSize)
|
.setWindowSize(this.windowSize)
|
||||||
.setDistance(this._currentDistance)
|
.setDistance(this._currentDistance)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.measurements[this._currentType][this._currentVariant][this._currentPosition];
|
return bucket[childKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional utility methods
|
// Additional utility methods
|
||||||
|
|||||||
@@ -177,18 +177,18 @@ const downstreamData = basicContainer
|
|||||||
.get();
|
.get();
|
||||||
|
|
||||||
//check wether a serie exists
|
//check wether a serie exists
|
||||||
const hasSeries = measurements
|
const hasSeries = basicContainer
|
||||||
.type("flow")
|
.type("flow")
|
||||||
.variant("measured")
|
.variant("measured")
|
||||||
.exists(); // true if any position exists
|
.exists(); // true if any position exists
|
||||||
|
|
||||||
const hasUpstreamValues = measurements
|
const hasUpstreamValues = basicContainer
|
||||||
.type("flow")
|
.type("flow")
|
||||||
.variant("measured")
|
.variant("measured")
|
||||||
.exists({ position: "upstream", requireValues: true });
|
.exists({ position: "upstream", requireValues: true });
|
||||||
|
|
||||||
// Passing everything explicitly
|
// Passing everything explicitly
|
||||||
const hasPercent = measurements.exists({
|
const hasPercent = basicContainer.exists({
|
||||||
type: "volume",
|
type: "volume",
|
||||||
variant: "percent",
|
variant: "percent",
|
||||||
position: "atEquipment",
|
position: "atEquipment",
|
||||||
@@ -274,14 +274,14 @@ console.log(` History: [${allValues.values.join(', ')}]\n`);
|
|||||||
|
|
||||||
console.log('--- Lagged sample comparison ---');
|
console.log('--- Lagged sample comparison ---');
|
||||||
|
|
||||||
const latest = stats.getCurrentValue(); // existing helper
|
const latestSample = stats.getLaggedSample(0); // newest sample object
|
||||||
const prevSample = stats.getLaggedValue(1); // new helper
|
const prevSample = stats.getLaggedSample(1);
|
||||||
const prevPrevSample = stats.getLaggedValue(2); // optional
|
const prevPrevSample = stats.getLaggedSample(2);
|
||||||
|
|
||||||
if (prevSample) {
|
if (prevSample) {
|
||||||
const delta = latest - prevSample.value;
|
const delta = (latestSample?.value ?? 0) - (prevSample.value ?? 0);
|
||||||
console.log(
|
console.log(
|
||||||
`Current vs previous: ${latest} ${statsData.unit} (t=${stats.get().getLatestTimestamp()}) vs ` +
|
`Current vs previous: ${latestSample?.value} ${statsData.unit} (t=${latestSample?.timestamp}) vs ` +
|
||||||
`${prevSample.value} ${prevSample.unit} (t=${prevSample.timestamp})`
|
`${prevSample.value} ${prevSample.unit} (t=${prevSample.timestamp})`
|
||||||
);
|
);
|
||||||
console.log(`Δ = ${delta.toFixed(2)} ${statsData.unit}`);
|
console.log(`Δ = ${delta.toFixed(2)} ${statsData.unit}`);
|
||||||
@@ -345,6 +345,68 @@ basicContainer.getTypes().forEach(type => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// --- Child Aggregation -----------------------------------------------------
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// ====================================
|
||||||
|
// AGGREGATION WITH CHILD SERIES (sum)
|
||||||
|
// ====================================
|
||||||
|
console.log();
|
||||||
|
console.log('--- Example X: Aggregation with sum() and child series ---');
|
||||||
|
|
||||||
|
// Container where flow is stored internally in m3/h
|
||||||
|
const aggContainer = new MeasurementContainer({
|
||||||
|
windowSize: 10,
|
||||||
|
defaultUnits: {
|
||||||
|
flow: 'm3/h',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Two pumps both feeding the same inlet position
|
||||||
|
aggContainer
|
||||||
|
.child('pumpA')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('inlet')
|
||||||
|
.value(10, Date.now(), 'm3/h'); // 10 m3/h
|
||||||
|
|
||||||
|
aggContainer
|
||||||
|
.child('pumpB')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('inlet')
|
||||||
|
.value(15, Date.now(), 'm3/h'); // 15 m3/h
|
||||||
|
|
||||||
|
// Another position, e.g. outlet, also with two pumps
|
||||||
|
aggContainer
|
||||||
|
.child('pumpA')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('outlet')
|
||||||
|
.value(8, Date.now(), 'm3/h'); // 8 m3/h
|
||||||
|
|
||||||
|
aggContainer
|
||||||
|
.child('pumpB')
|
||||||
|
.type('flow')
|
||||||
|
.variant('measured')
|
||||||
|
.position('outlet')
|
||||||
|
.value(11, Date.now(), 'm3/h'); // 11 m3/h
|
||||||
|
|
||||||
|
|
||||||
|
// 1) Sum only inlet position (children pumpA + pumpB)
|
||||||
|
const inletTotal = aggContainer.sum('flow', 'measured', ['inlet']);
|
||||||
|
console.log(`Total inlet flow: ${inletTotal} m3/h (expected 25 m3/h)`);
|
||||||
|
|
||||||
|
// 2) Sum inlet + outlet positions together
|
||||||
|
const totalAll = aggContainer.sum('flow', 'measured', ['inlet', 'outlet']);
|
||||||
|
console.log(`Total inlet+outlet flow: ${totalAll} m3/h (expected 44 m3/h)`);
|
||||||
|
|
||||||
|
// 3) Same sum but explicitly ask for a target unit (e.g. l/s)
|
||||||
|
// This will use convertModule(...) internally.
|
||||||
|
// If conversion is not supported, it will fall back to the raw value.
|
||||||
|
const totalAllLps = aggContainer.sum('flow', 'measured', ['inlet', 'outlet'], 'l/s');
|
||||||
|
console.log(`Total inlet+outlet flow in l/s: ${totalAllLps} l/s (converted from m3/h)\n`);
|
||||||
|
|
||||||
|
|
||||||
console.log('\n✅ All examples complete!\n');
|
console.log('\n✅ All examples complete!\n');
|
||||||
|
|||||||
@@ -1,61 +1,82 @@
|
|||||||
// asset.js
|
const { assetCategoryManager } = require('../../datasets/assetData');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
class AssetMenu {
|
class AssetMenu {
|
||||||
/** Define path where to find data of assets in constructor for now */
|
constructor({ manager = assetCategoryManager, softwareType = null } = {}) {
|
||||||
constructor(relPath = '../../datasets/assetData') {
|
this.manager = manager;
|
||||||
this.baseDir = path.resolve(__dirname, relPath);
|
this.softwareType = softwareType;
|
||||||
this.assetData = this._loadJSON('assetData');
|
this.categories = this.manager
|
||||||
|
.listCategories({ withMeta: true })
|
||||||
|
.reduce((map, meta) => {
|
||||||
|
map[meta.softwareType] = this.manager.getCategory(meta.softwareType);
|
||||||
|
return map;
|
||||||
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadJSON(...segments) {
|
normalizeCategory(key) {
|
||||||
const filePath = path.resolve(this.baseDir, ...segments) + '.json';
|
const category = this.categories[key];
|
||||||
try {
|
if (!category) {
|
||||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
return null;
|
||||||
} catch (err) {
|
}
|
||||||
throw new Error(`Failed to load ${filePath}: ${err.message}`);
|
|
||||||
|
return {
|
||||||
|
...category,
|
||||||
|
label: category.label || category.softwareType || key,
|
||||||
|
suppliers: (category.suppliers || []).map((supplier) => ({
|
||||||
|
...supplier,
|
||||||
|
id: supplier.id || supplier.name,
|
||||||
|
types: (supplier.types || []).map((type) => ({
|
||||||
|
...type,
|
||||||
|
id: type.id || type.name,
|
||||||
|
models: (type.models || []).map((model) => ({
|
||||||
|
...model,
|
||||||
|
id: model.id || model.name,
|
||||||
|
units: model.units || []
|
||||||
|
}))
|
||||||
|
}))
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveCategoryForNode(nodeName) {
|
||||||
|
const keys = Object.keys(this.categories);
|
||||||
|
if (keys.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.softwareType && this.categories[this.softwareType]) {
|
||||||
|
return this.softwareType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nodeName) {
|
||||||
|
const normalized = typeof nodeName === 'string' ? nodeName.toLowerCase() : nodeName;
|
||||||
|
if (normalized && this.categories[normalized]) {
|
||||||
|
return normalized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return keys[0];
|
||||||
* ADD THIS METHOD
|
}
|
||||||
* Compiles all menu data from the file system into a single nested object.
|
|
||||||
* This is run once on the server to pre-load everything.
|
getAllMenuData(nodeName) {
|
||||||
* @returns {object} A comprehensive object with all menu options.
|
const categoryKey = this.resolveCategoryForNode(nodeName);
|
||||||
*/
|
const selectedCategories = {};
|
||||||
getAllMenuData() {
|
|
||||||
// load the raw JSON once
|
if (categoryKey && this.categories[categoryKey]) {
|
||||||
const data = this._loadJSON('assetData');
|
selectedCategories[categoryKey] = this.normalizeCategory(categoryKey);
|
||||||
const allData = {};
|
}
|
||||||
|
|
||||||
data.suppliers.forEach(sup => {
|
return {
|
||||||
allData[sup.name] = {};
|
categories: selectedCategories,
|
||||||
sup.categories.forEach(cat => {
|
defaultCategory: categoryKey
|
||||||
allData[sup.name][cat.name] = {};
|
};
|
||||||
cat.types.forEach(type => {
|
|
||||||
// here: store the full array of model objects, not just names
|
|
||||||
allData[sup.name][cat.name][type.name] = type.models;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return allData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the static initEditor function to a string that can be served to the client
|
|
||||||
* @param {string} nodeName - The name of the node type
|
|
||||||
* @returns {string} JavaScript code as a string
|
|
||||||
*/
|
|
||||||
getClientInitCode(nodeName) {
|
getClientInitCode(nodeName) {
|
||||||
// step 1: get the two helper strings
|
|
||||||
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 saveCode = this.getSaveInjectionCode(nodeName);
|
const saveCode = this.getSaveInjectionCode(nodeName);
|
||||||
|
|
||||||
|
|
||||||
return `
|
return `
|
||||||
// --- AssetMenu for ${nodeName} ---
|
// --- AssetMenu for ${nodeName} ---
|
||||||
window.EVOLV.nodes.${nodeName}.assetMenu =
|
window.EVOLV.nodes.${nodeName}.assetMenu =
|
||||||
@@ -66,103 +87,276 @@ getClientInitCode(nodeName) {
|
|||||||
${eventsCode}
|
${eventsCode}
|
||||||
${saveCode}
|
${saveCode}
|
||||||
|
|
||||||
// wire it all up when the editor loads
|
|
||||||
window.EVOLV.nodes.${nodeName}.assetMenu.initEditor = function(node) {
|
window.EVOLV.nodes.${nodeName}.assetMenu.initEditor = function(node) {
|
||||||
// ------------------ BELOW sequence is important! -------------------------------
|
console.log('Initializing asset properties for ${nodeName}');
|
||||||
console.log('Initializing asset properties for ${nodeName}…');
|
|
||||||
this.injectHtml();
|
this.injectHtml();
|
||||||
// load the data and wire up events
|
|
||||||
// this will populate the fields and set up the event listeners
|
|
||||||
this.wireEvents(node);
|
this.wireEvents(node);
|
||||||
// this will load the initial data into the fields
|
|
||||||
// this is important to ensure the fields are populated correctly
|
|
||||||
this.loadData(node);
|
this.loadData(node);
|
||||||
};
|
};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = function(node) {
|
||||||
const data = window.EVOLV.nodes.${nodeName}.menuData.asset;
|
const menuAsset = window.EVOLV.nodes.${nodeName}.menuData.asset || {};
|
||||||
|
const categories = menuAsset.categories || {};
|
||||||
|
const defaultCategory = menuAsset.defaultCategory || Object.keys(categories)[0] || null;
|
||||||
const elems = {
|
const elems = {
|
||||||
supplier: document.getElementById('node-input-supplier'),
|
supplier: document.getElementById('node-input-supplier'),
|
||||||
category: document.getElementById('node-input-category'),
|
|
||||||
type: document.getElementById('node-input-assetType'),
|
type: document.getElementById('node-input-assetType'),
|
||||||
model: document.getElementById('node-input-model'),
|
model: document.getElementById('node-input-model'),
|
||||||
unit: document.getElementById('node-input-unit')
|
unit: document.getElementById('node-input-unit')
|
||||||
};
|
};
|
||||||
function populate(el, opts, sel) {
|
|
||||||
const old = el.value;
|
function populate(selectEl, items = [], selectedValue, mapFn, placeholderText = 'Select...') {
|
||||||
el.innerHTML = '<option value="">Select…</option>';
|
const previous = selectEl.value;
|
||||||
(opts||[]).forEach(o=>{
|
const mapper = typeof mapFn === 'function'
|
||||||
const opt = document.createElement('option');
|
? mapFn
|
||||||
opt.value = o; opt.textContent = o;
|
: (value) => ({ value, label: value });
|
||||||
el.appendChild(opt);
|
|
||||||
});
|
selectEl.innerHTML = '';
|
||||||
el.value = sel||"";
|
|
||||||
if(el.value!==old) el.dispatchEvent(new Event('change'));
|
const placeholder = document.createElement('option');
|
||||||
|
placeholder.value = '';
|
||||||
|
placeholder.textContent = placeholderText;
|
||||||
|
placeholder.disabled = true;
|
||||||
|
placeholder.selected = true;
|
||||||
|
selectEl.appendChild(placeholder);
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
const option = mapper(item);
|
||||||
|
if (!option || typeof option.value === 'undefined') {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// initial population
|
const opt = document.createElement('option');
|
||||||
populate(elems.supplier, Object.keys(data), node.supplier);
|
opt.value = option.value;
|
||||||
|
opt.textContent = option.label;
|
||||||
|
selectEl.appendChild(opt);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selectedValue) {
|
||||||
|
selectEl.value = selectedValue;
|
||||||
|
if (!selectEl.value) {
|
||||||
|
selectEl.value = '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectEl.value = '';
|
||||||
|
}
|
||||||
|
if (selectEl.value !== previous) {
|
||||||
|
selectEl.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
node.category = categoryKey;
|
||||||
|
const activeCategory = categoryKey ? categories[categoryKey] : null;
|
||||||
|
|
||||||
|
const suppliers = activeCategory ? activeCategory.suppliers : [];
|
||||||
|
populate(
|
||||||
|
elems.supplier,
|
||||||
|
suppliers,
|
||||||
|
node.supplier,
|
||||||
|
(supplier) => ({ value: supplier.id || supplier.name, label: supplier.name }),
|
||||||
|
suppliers.length ? 'Select...' : 'No suppliers available'
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeSupplier = suppliers.find(
|
||||||
|
(supplier) => (supplier.id || supplier.name) === node.supplier
|
||||||
|
);
|
||||||
|
const types = activeSupplier ? activeSupplier.types : [];
|
||||||
|
populate(
|
||||||
|
elems.type,
|
||||||
|
types,
|
||||||
|
node.assetType,
|
||||||
|
(type) => ({ value: type.id || type.name, label: type.name }),
|
||||||
|
activeSupplier ? 'Select...' : 'Awaiting Supplier Selection'
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeType = types.find(
|
||||||
|
(type) => (type.id || type.name) === node.assetType
|
||||||
|
);
|
||||||
|
const models = activeType ? activeType.models : [];
|
||||||
|
populate(
|
||||||
|
elems.model,
|
||||||
|
models,
|
||||||
|
node.model,
|
||||||
|
(model) => ({ value: model.id || model.name, label: model.name }),
|
||||||
|
activeType ? 'Select...' : 'Awaiting Type Selection'
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeModel = models.find(
|
||||||
|
(model) => (model.id || model.name) === node.model
|
||||||
|
);
|
||||||
|
populate(
|
||||||
|
elems.unit,
|
||||||
|
activeModel ? activeModel.units || [] : [],
|
||||||
|
node.unit,
|
||||||
|
(unit) => ({ value: unit, label: unit }),
|
||||||
|
activeModel ? 'Select...' : activeType ? 'Awaiting Model Selection' : 'Awaiting Type Selection'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
getEventInjectionCode(nodeName) {
|
getEventInjectionCode(nodeName) {
|
||||||
return `
|
return `
|
||||||
// Asset Event wiring for ${nodeName}
|
// Asset event wiring for ${nodeName}
|
||||||
window.EVOLV.nodes.${nodeName}.assetMenu.wireEvents = function(node) {
|
window.EVOLV.nodes.${nodeName}.assetMenu.wireEvents = function(node) {
|
||||||
const data = window.EVOLV.nodes.${nodeName}.menuData.asset;
|
const menuAsset = window.EVOLV.nodes.${nodeName}.menuData.asset || {};
|
||||||
|
const categories = menuAsset.categories || {};
|
||||||
|
const defaultCategory = menuAsset.defaultCategory || Object.keys(categories)[0] || null;
|
||||||
const elems = {
|
const elems = {
|
||||||
supplier: document.getElementById('node-input-supplier'),
|
supplier: document.getElementById('node-input-supplier'),
|
||||||
category: document.getElementById('node-input-category'),
|
|
||||||
type: document.getElementById('node-input-assetType'),
|
type: document.getElementById('node-input-assetType'),
|
||||||
model: document.getElementById('node-input-model'),
|
model: document.getElementById('node-input-model'),
|
||||||
unit: document.getElementById('node-input-unit')
|
unit: document.getElementById('node-input-unit')
|
||||||
};
|
};
|
||||||
function populate(el, opts, sel) {
|
|
||||||
const old = el.value;
|
function populate(selectEl, items = [], selectedValue, mapFn, placeholderText = 'Select...') {
|
||||||
el.innerHTML = '<option value="">Select…</option>';
|
const previous = selectEl.value;
|
||||||
(opts||[]).forEach(o=>{
|
const mapper = typeof mapFn === 'function'
|
||||||
const opt = document.createElement('option');
|
? mapFn
|
||||||
opt.value = o; opt.textContent = o;
|
: (value) => ({ value, label: value });
|
||||||
el.appendChild(opt);
|
|
||||||
});
|
selectEl.innerHTML = '';
|
||||||
el.value = sel||"";
|
|
||||||
if(el.value!==old) el.dispatchEvent(new Event('change'));
|
const placeholder = document.createElement('option');
|
||||||
|
placeholder.value = '';
|
||||||
|
placeholder.textContent = placeholderText;
|
||||||
|
placeholder.disabled = true;
|
||||||
|
placeholder.selected = true;
|
||||||
|
selectEl.appendChild(placeholder);
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
const option = mapper(item);
|
||||||
|
if (!option || typeof option.value === 'undefined') {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
elems.supplier.addEventListener('change', ()=>{
|
const opt = document.createElement('option');
|
||||||
populate(elems.category,
|
opt.value = option.value;
|
||||||
elems.supplier.value? Object.keys(data[elems.supplier.value]||{}) : [],
|
opt.textContent = option.label;
|
||||||
node.category);
|
selectEl.appendChild(opt);
|
||||||
});
|
});
|
||||||
elems.category.addEventListener('change', ()=>{
|
|
||||||
const s=elems.supplier.value, c=elems.category.value;
|
if (selectedValue) {
|
||||||
populate(elems.type,
|
selectEl.value = selectedValue;
|
||||||
(s&&c)? Object.keys(data[s][c]||{}) : [],
|
if (!selectEl.value) {
|
||||||
node.assetType);
|
selectEl.value = '';
|
||||||
});
|
}
|
||||||
elems.type.addEventListener('change', ()=>{
|
} else {
|
||||||
const s=elems.supplier.value, c=elems.category.value, t=elems.type.value;
|
selectEl.value = '';
|
||||||
const md = (s&&c&&t)? data[s][c][t]||[] : [];
|
}
|
||||||
populate(elems.model, md.map(m=>m.name), node.model);
|
if (selectEl.value !== previous) {
|
||||||
});
|
selectEl.dispatchEvent(new Event('change'));
|
||||||
elems.model.addEventListener('change', ()=>{
|
}
|
||||||
const s=elems.supplier.value, c=elems.category.value, t=elems.type.value, m=elems.model.value;
|
}
|
||||||
const md = (s&&c&&t)? data[s][c][t]||[] : [];
|
|
||||||
const entry = md.find(x=>x.name===m);
|
const resolveCategoryKey = () => {
|
||||||
populate(elems.unit, entry? entry.units : [], node.unit);
|
if (node.softwareType && categories[node.softwareType]) {
|
||||||
});
|
return node.softwareType;
|
||||||
};
|
}
|
||||||
`
|
if (node.category && categories[node.category]) {
|
||||||
|
return node.category;
|
||||||
|
}
|
||||||
|
return defaultCategory;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getActiveCategory = () => {
|
||||||
|
const key = resolveCategoryKey();
|
||||||
|
return key ? categories[key] : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
node.category = resolveCategoryKey();
|
||||||
|
|
||||||
|
elems.supplier.addEventListener('change', () => {
|
||||||
|
const category = getActiveCategory();
|
||||||
|
const supplier = category
|
||||||
|
? category.suppliers.find(
|
||||||
|
(item) => (item.id || item.name) === elems.supplier.value
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
const types = supplier ? supplier.types : [];
|
||||||
|
populate(
|
||||||
|
elems.type,
|
||||||
|
types,
|
||||||
|
node.assetType,
|
||||||
|
(type) => ({ value: type.id || type.name, label: type.name }),
|
||||||
|
supplier ? 'Select...' : 'Awaiting Supplier Selection'
|
||||||
|
);
|
||||||
|
populate(elems.model, [], '', undefined, 'Awaiting Type Selection');
|
||||||
|
populate(elems.unit, [], '', undefined, 'Awaiting Type Selection');
|
||||||
|
});
|
||||||
|
|
||||||
|
elems.type.addEventListener('change', () => {
|
||||||
|
const category = getActiveCategory();
|
||||||
|
const supplier = category
|
||||||
|
? category.suppliers.find(
|
||||||
|
(item) => (item.id || item.name) === elems.supplier.value
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
const type = supplier
|
||||||
|
? supplier.types.find(
|
||||||
|
(item) => (item.id || item.name) === elems.type.value
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
const models = type ? type.models : [];
|
||||||
|
populate(
|
||||||
|
elems.model,
|
||||||
|
models,
|
||||||
|
node.model,
|
||||||
|
(model) => ({ value: model.id || model.name, label: model.name }),
|
||||||
|
type ? 'Select...' : 'Awaiting Type Selection'
|
||||||
|
);
|
||||||
|
populate(
|
||||||
|
elems.unit,
|
||||||
|
[],
|
||||||
|
'',
|
||||||
|
undefined,
|
||||||
|
type ? 'Awaiting Model Selection' : 'Awaiting Type Selection'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
elems.model.addEventListener('change', () => {
|
||||||
|
const category = getActiveCategory();
|
||||||
|
const supplier = category
|
||||||
|
? category.suppliers.find(
|
||||||
|
(item) => (item.id || item.name) === elems.supplier.value
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
const type = supplier
|
||||||
|
? supplier.types.find(
|
||||||
|
(item) => (item.id || item.name) === elems.type.value
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
const model = type
|
||||||
|
? type.models.find(
|
||||||
|
(item) => (item.id || item.name) === elems.model.value
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
populate(
|
||||||
|
elems.unit,
|
||||||
|
model ? model.units || [] : [],
|
||||||
|
node.unit,
|
||||||
|
(unit) => ({ value: unit, label: unit }),
|
||||||
|
model ? 'Select...' : type ? 'Awaiting Model Selection' : 'Awaiting Type Selection'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate HTML template for asset fields
|
|
||||||
*/
|
|
||||||
getHtmlTemplate() {
|
getHtmlTemplate() {
|
||||||
return `
|
return `
|
||||||
<!-- Asset Properties -->
|
<!-- Asset Properties -->
|
||||||
@@ -172,10 +366,6 @@ getEventInjectionCode(nodeName) {
|
|||||||
<label for="node-input-supplier"><i class="fa fa-industry"></i> Supplier</label>
|
<label for="node-input-supplier"><i class="fa fa-industry"></i> Supplier</label>
|
||||||
<select id="node-input-supplier" style="width:70%;"></select>
|
<select id="node-input-supplier" style="width:70%;"></select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
|
||||||
<label for="node-input-category"><i class="fa fa-sitemap"></i> Category</label>
|
|
||||||
<select id="node-input-category" style="width:70%;"></select>
|
|
||||||
</div>
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-assetType"><i class="fa fa-puzzle-piece"></i> Type</label>
|
<label for="node-input-assetType"><i class="fa fa-puzzle-piece"></i> Type</label>
|
||||||
<select id="node-input-assetType" style="width:70%;"></select>
|
<select id="node-input-assetType" style="width:70%;"></select>
|
||||||
@@ -192,11 +382,10 @@ getEventInjectionCode(nodeName) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get client-side HTML injection code
|
|
||||||
*/
|
|
||||||
getHtmlInjectionCode(nodeName) {
|
getHtmlInjectionCode(nodeName) {
|
||||||
const htmlTemplate = this.getHtmlTemplate().replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
const htmlTemplate = this.getHtmlTemplate()
|
||||||
|
.replace(/`/g, '\\`')
|
||||||
|
.replace(/\$/g, '\\$');
|
||||||
|
|
||||||
return `
|
return `
|
||||||
// Asset HTML injection for ${nodeName}
|
// Asset HTML injection for ${nodeName}
|
||||||
@@ -210,33 +399,53 @@ getEventInjectionCode(nodeName) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the JS that injects the saveEditor function
|
|
||||||
*/
|
|
||||||
getSaveInjectionCode(nodeName) {
|
getSaveInjectionCode(nodeName) {
|
||||||
return `
|
return `
|
||||||
// Asset Save injection for ${nodeName}
|
// Asset save handler for ${nodeName}
|
||||||
window.EVOLV.nodes.${nodeName}.assetMenu.saveEditor = function(node) {
|
window.EVOLV.nodes.${nodeName}.assetMenu.saveEditor = function(node) {
|
||||||
console.log('Saving asset properties for ${nodeName}…');
|
console.log('Saving asset properties for ${nodeName}');
|
||||||
const fields = ['supplier','category','assetType','model','unit'];
|
const menuAsset = window.EVOLV.nodes.${nodeName}.menuData.asset || {};
|
||||||
const errors = [];
|
const categories = menuAsset.categories || {};
|
||||||
fields.forEach(f => {
|
const defaultCategory = menuAsset.defaultCategory || Object.keys(categories)[0] || null;
|
||||||
const el = document.getElementById(\`node-input-\${f}\`);
|
const resolveCategoryKey = () => {
|
||||||
node[f] = el ? el.value : '';
|
if (node.softwareType && categories[node.softwareType]) {
|
||||||
});
|
return node.softwareType;
|
||||||
if (node.assetType && !node.unit) errors.push('Unit must be set when type is specified.');
|
}
|
||||||
if (!node.unit) errors.push('Unit is required.');
|
if (node.category && categories[node.category]) {
|
||||||
errors.forEach(e=>RED.notify(e,'error'));
|
return node.category;
|
||||||
|
}
|
||||||
|
return defaultCategory || '';
|
||||||
|
};
|
||||||
|
|
||||||
// --- DEBUG: show exactly what was saved ---
|
node.category = resolveCategoryKey();
|
||||||
const saved = fields.reduce((o,f) => { o[f] = node[f]; return o; }, {});
|
|
||||||
console.log('→ assetMenu.saveEditor result:', saved);
|
const fields = ['supplier', 'assetType', 'model', 'unit'];
|
||||||
|
const errors = [];
|
||||||
|
|
||||||
|
fields.forEach((field) => {
|
||||||
|
const el = document.getElementById(\`node-input-\${field}\`);
|
||||||
|
node[field] = el ? el.value : '';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (node.assetType && !node.unit) {
|
||||||
|
errors.push('Unit must be set when a type is specified.');
|
||||||
|
}
|
||||||
|
if (!node.unit) {
|
||||||
|
errors.push('Unit is required.');
|
||||||
|
}
|
||||||
|
|
||||||
|
errors.forEach((msg) => RED.notify(msg, 'error'));
|
||||||
|
|
||||||
|
const saved = fields.reduce((acc, field) => {
|
||||||
|
acc[field] = node[field];
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
console.log('[AssetMenu] save result:', saved);
|
||||||
|
|
||||||
return errors.length === 0;
|
return errors.length === 0;
|
||||||
};
|
};
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = AssetMenu;
|
module.exports = AssetMenu;
|
||||||
|
|||||||
243
src/menu/asset_DEPRECATED.js
Normal file
243
src/menu/asset_DEPRECATED.js
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
// asset.js
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
|
||||||
|
class AssetMenu {
|
||||||
|
/** Define path where to find data of assets in constructor for now */
|
||||||
|
constructor(relPath = '../../datasets/assetData') {
|
||||||
|
this.baseDir = path.resolve(__dirname, relPath);
|
||||||
|
this.assetData = this._loadJSON('assetData');
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadJSON(...segments) {
|
||||||
|
const filePath = path.resolve(this.baseDir, ...segments) + '.json';
|
||||||
|
try {
|
||||||
|
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to load ${filePath}: ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ADD THIS METHOD
|
||||||
|
* Compiles all menu data from the file system into a single nested object.
|
||||||
|
* This is run once on the server to pre-load everything.
|
||||||
|
* @returns {object} A comprehensive object with all menu options.
|
||||||
|
*/
|
||||||
|
getAllMenuData() {
|
||||||
|
// load the raw JSON once
|
||||||
|
const data = this._loadJSON('assetData');
|
||||||
|
const allData = {};
|
||||||
|
|
||||||
|
data.suppliers.forEach(sup => {
|
||||||
|
allData[sup.name] = {};
|
||||||
|
sup.categories.forEach(cat => {
|
||||||
|
allData[sup.name][cat.name] = {};
|
||||||
|
cat.types.forEach(type => {
|
||||||
|
// here: store the full array of model objects, not just names
|
||||||
|
allData[sup.name][cat.name][type.name] = type.models;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return allData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the static initEditor function to a string that can be served to the client
|
||||||
|
* @param {string} nodeName - The name of the node type
|
||||||
|
* @returns {string} JavaScript code as a string
|
||||||
|
*/
|
||||||
|
getClientInitCode(nodeName) {
|
||||||
|
// step 1: get the two helper strings
|
||||||
|
const htmlCode = this.getHtmlInjectionCode(nodeName);
|
||||||
|
const dataCode = this.getDataInjectionCode(nodeName);
|
||||||
|
const eventsCode = this.getEventInjectionCode(nodeName);
|
||||||
|
const saveCode = this.getSaveInjectionCode(nodeName);
|
||||||
|
|
||||||
|
|
||||||
|
return `
|
||||||
|
// --- AssetMenu for ${nodeName} ---
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu =
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu || {};
|
||||||
|
|
||||||
|
${htmlCode}
|
||||||
|
${dataCode}
|
||||||
|
${eventsCode}
|
||||||
|
${saveCode}
|
||||||
|
|
||||||
|
// wire it all up when the editor loads
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu.initEditor = function(node) {
|
||||||
|
// ------------------ BELOW sequence is important! -------------------------------
|
||||||
|
console.log('Initializing asset properties for ${nodeName}…');
|
||||||
|
this.injectHtml();
|
||||||
|
// load the data and wire up events
|
||||||
|
// this will populate the fields and set up the event listeners
|
||||||
|
this.wireEvents(node);
|
||||||
|
// this will load the initial data into the fields
|
||||||
|
// this is important to ensure the fields are populated correctly
|
||||||
|
this.loadData(node);
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
getDataInjectionCode(nodeName) {
|
||||||
|
return `
|
||||||
|
// Asset Data loader for ${nodeName}
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu.loadData = function(node) {
|
||||||
|
const data = window.EVOLV.nodes.${nodeName}.menuData.asset;
|
||||||
|
const elems = {
|
||||||
|
supplier: document.getElementById('node-input-supplier'),
|
||||||
|
category: document.getElementById('node-input-category'),
|
||||||
|
type: document.getElementById('node-input-assetType'),
|
||||||
|
model: document.getElementById('node-input-model'),
|
||||||
|
unit: document.getElementById('node-input-unit')
|
||||||
|
};
|
||||||
|
function populate(el, opts, sel) {
|
||||||
|
const old = el.value;
|
||||||
|
el.innerHTML = '<option value="">Select…</option>';
|
||||||
|
(opts||[]).forEach(o=>{
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = o; opt.textContent = o;
|
||||||
|
el.appendChild(opt);
|
||||||
|
});
|
||||||
|
el.value = sel||"";
|
||||||
|
if(el.value!==old) el.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
// initial population
|
||||||
|
populate(elems.supplier, Object.keys(data), node.supplier);
|
||||||
|
};
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
getEventInjectionCode(nodeName) {
|
||||||
|
return `
|
||||||
|
// Asset Event wiring for ${nodeName}
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu.wireEvents = function(node) {
|
||||||
|
const data = window.EVOLV.nodes.${nodeName}.menuData.asset;
|
||||||
|
const elems = {
|
||||||
|
supplier: document.getElementById('node-input-supplier'),
|
||||||
|
category: document.getElementById('node-input-category'),
|
||||||
|
type: document.getElementById('node-input-assetType'),
|
||||||
|
model: document.getElementById('node-input-model'),
|
||||||
|
unit: document.getElementById('node-input-unit')
|
||||||
|
};
|
||||||
|
function populate(el, opts, sel) {
|
||||||
|
const old = el.value;
|
||||||
|
el.innerHTML = '<option value="">Select…</option>';
|
||||||
|
(opts||[]).forEach(o=>{
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = o; opt.textContent = o;
|
||||||
|
el.appendChild(opt);
|
||||||
|
});
|
||||||
|
el.value = sel||"";
|
||||||
|
if(el.value!==old) el.dispatchEvent(new Event('change'));
|
||||||
|
}
|
||||||
|
elems.supplier.addEventListener('change', ()=>{
|
||||||
|
populate(elems.category,
|
||||||
|
elems.supplier.value? Object.keys(data[elems.supplier.value]||{}) : [],
|
||||||
|
node.category);
|
||||||
|
});
|
||||||
|
elems.category.addEventListener('change', ()=>{
|
||||||
|
const s=elems.supplier.value, c=elems.category.value;
|
||||||
|
populate(elems.type,
|
||||||
|
(s&&c)? Object.keys(data[s][c]||{}) : [],
|
||||||
|
node.assetType);
|
||||||
|
});
|
||||||
|
elems.type.addEventListener('change', ()=>{
|
||||||
|
const s=elems.supplier.value, c=elems.category.value, t=elems.type.value;
|
||||||
|
const md = (s&&c&&t)? data[s][c][t]||[] : [];
|
||||||
|
populate(elems.model, md.map(m=>m.name), node.model);
|
||||||
|
});
|
||||||
|
elems.model.addEventListener('change', ()=>{
|
||||||
|
const s=elems.supplier.value, c=elems.category.value, t=elems.type.value, m=elems.model.value;
|
||||||
|
const md = (s&&c&&t)? data[s][c][t]||[] : [];
|
||||||
|
const entry = md.find(x=>x.name===m);
|
||||||
|
populate(elems.unit, entry? entry.units : [], node.unit);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate HTML template for asset fields
|
||||||
|
*/
|
||||||
|
getHtmlTemplate() {
|
||||||
|
return `
|
||||||
|
<!-- Asset Properties -->
|
||||||
|
<hr />
|
||||||
|
<h3>Asset selection</h3>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-supplier"><i class="fa fa-industry"></i> Supplier</label>
|
||||||
|
<select id="node-input-supplier" style="width:70%;"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-category"><i class="fa fa-sitemap"></i> Category</label>
|
||||||
|
<select id="node-input-category" style="width:70%;"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-assetType"><i class="fa fa-puzzle-piece"></i> Type</label>
|
||||||
|
<select id="node-input-assetType" style="width:70%;"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-model"><i class="fa fa-wrench"></i> Model</label>
|
||||||
|
<select id="node-input-model" style="width:70%;"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-unit"><i class="fa fa-balance-scale"></i> Unit</label>
|
||||||
|
<select id="node-input-unit" style="width:70%;"></select>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get client-side HTML injection code
|
||||||
|
*/
|
||||||
|
getHtmlInjectionCode(nodeName) {
|
||||||
|
const htmlTemplate = this.getHtmlTemplate().replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
||||||
|
|
||||||
|
return `
|
||||||
|
// Asset HTML injection for ${nodeName}
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu.injectHtml = function() {
|
||||||
|
const placeholder = document.getElementById('asset-fields-placeholder');
|
||||||
|
if (placeholder && !placeholder.hasChildNodes()) {
|
||||||
|
placeholder.innerHTML = \`${htmlTemplate}\`;
|
||||||
|
console.log('Asset HTML injected successfully');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the JS that injects the saveEditor function
|
||||||
|
*/
|
||||||
|
getSaveInjectionCode(nodeName) {
|
||||||
|
return `
|
||||||
|
// Asset Save injection for ${nodeName}
|
||||||
|
window.EVOLV.nodes.${nodeName}.assetMenu.saveEditor = function(node) {
|
||||||
|
console.log('Saving asset properties for ${nodeName}…');
|
||||||
|
const fields = ['supplier','category','assetType','model','unit'];
|
||||||
|
const errors = [];
|
||||||
|
fields.forEach(f => {
|
||||||
|
const el = document.getElementById(\`node-input-\${f}\`);
|
||||||
|
node[f] = el ? el.value : '';
|
||||||
|
});
|
||||||
|
if (node.assetType && !node.unit) errors.push('Unit must be set when type is specified.');
|
||||||
|
if (!node.unit) errors.push('Unit is required.');
|
||||||
|
errors.forEach(e=>RED.notify(e,'error'));
|
||||||
|
|
||||||
|
// --- DEBUG: show exactly what was saved ---
|
||||||
|
const saved = fields.reduce((o,f) => { o[f] = node[f]; return o; }, {});
|
||||||
|
console.log('→ assetMenu.saveEditor result:', saved);
|
||||||
|
|
||||||
|
return errors.length===0;
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AssetMenu;
|
||||||
@@ -2,13 +2,17 @@ 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 ConfigManager = require('../configs');
|
||||||
|
|
||||||
class MenuManager {
|
class MenuManager {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.registeredMenus = new Map();
|
this.registeredMenus = new Map();
|
||||||
|
this.configManager = new ConfigManager('../configs');
|
||||||
// Register factory functions
|
// Register factory functions
|
||||||
this.registerMenu('asset', () => new AssetMenu()); // static menu to be replaced by dynamic one but later
|
this.registerMenu('asset', (nodeName) => new AssetMenu({
|
||||||
|
softwareType: this._getSoftwareType(nodeName)
|
||||||
|
})); // static menu to be replaced by dynamic one but later
|
||||||
//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());
|
||||||
@@ -23,6 +27,20 @@ class MenuManager {
|
|||||||
this.registeredMenus.set(menuType, menuFactory);
|
this.registeredMenus.set(menuType, menuFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getSoftwareType(nodeName) {
|
||||||
|
if (!nodeName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const config = this.configManager.getConfig(nodeName);
|
||||||
|
return config?.functionality?.softwareType || nodeName;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Unable to determine softwareType for ${nodeName}: ${error.message}`);
|
||||||
|
return nodeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a complete endpoint script with data and initialization functions
|
* Create a complete endpoint script with data and initialization functions
|
||||||
* @param {string} nodeName - The name of the node type
|
* @param {string} nodeName - The name of the node type
|
||||||
@@ -54,7 +72,7 @@ class MenuManager {
|
|||||||
try {
|
try {
|
||||||
const handler = instantiatedMenus.get(menuType);
|
const handler = instantiatedMenus.get(menuType);
|
||||||
if (handler && typeof handler.getAllMenuData === 'function') {
|
if (handler && typeof handler.getAllMenuData === 'function') {
|
||||||
menuData[menuType] = handler.getAllMenuData();
|
menuData[menuType] = handler.getAllMenuData(nodeName);
|
||||||
} else {
|
} else {
|
||||||
// Provide default empty data if method doesn't exist
|
// Provide default empty data if method doesn't exist
|
||||||
menuData[menuType] = {};
|
menuData[menuType] = {};
|
||||||
|
|||||||
@@ -81,11 +81,8 @@ class movementManager {
|
|||||||
const direction = targetPosition > this.currentPosition ? 1 : -1;
|
const direction = targetPosition > this.currentPosition ? 1 : -1;
|
||||||
const distance = Math.abs(targetPosition - this.currentPosition);
|
const distance = Math.abs(targetPosition - this.currentPosition);
|
||||||
|
|
||||||
// Speed is a fraction [0,1] of full-range per second
|
const velocity = this.getVelocity(); // units per second
|
||||||
this.speed = Math.min(Math.max(this.speed, 0), 1);
|
if (velocity <= 0) {
|
||||||
const fullRange = this.maxPosition - this.minPosition;
|
|
||||||
const velocity = this.speed * fullRange; // units per second
|
|
||||||
if (velocity === 0) {
|
|
||||||
return reject(new Error("Movement aborted: zero speed"));
|
return reject(new Error("Movement aborted: zero speed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,11 +151,11 @@ class movementManager {
|
|||||||
const direction = targetPosition > this.currentPosition ? 1 : -1;
|
const direction = targetPosition > this.currentPosition ? 1 : -1;
|
||||||
const distance = Math.abs(targetPosition - this.currentPosition);
|
const distance = Math.abs(targetPosition - this.currentPosition);
|
||||||
|
|
||||||
// Ensure speed is a percentage [0, 1]
|
const velocity = this.getVelocity();
|
||||||
this.speed = Math.min(Math.max(this.speed, 0), 1);
|
if (velocity <= 0) {
|
||||||
|
return reject(new Error("Movement aborted: zero speed"));
|
||||||
// Calculate duration based on percentage of distance per second
|
}
|
||||||
const duration = 1 / this.speed; // 1 second for 100% of the distance
|
const duration = distance / velocity;
|
||||||
|
|
||||||
this.timeleft = duration; //set this so other classes can use it
|
this.timeleft = duration; //set this so other classes can use it
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
@@ -217,13 +214,16 @@ class movementManager {
|
|||||||
const direction = targetPosition > this.currentPosition ? 1 : -1;
|
const direction = targetPosition > this.currentPosition ? 1 : -1;
|
||||||
const totalDistance = Math.abs(targetPosition - this.currentPosition);
|
const totalDistance = Math.abs(targetPosition - this.currentPosition);
|
||||||
const startPosition = this.currentPosition;
|
const startPosition = this.currentPosition;
|
||||||
this.speed = Math.min(Math.max(this.speed, 0), 1);
|
const velocity = this.getVelocity();
|
||||||
|
if (velocity <= 0) {
|
||||||
|
return reject(new Error("Movement aborted: zero speed"));
|
||||||
|
}
|
||||||
|
|
||||||
const easeFunction = (t) =>
|
const easeFunction = (t) =>
|
||||||
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
||||||
|
|
||||||
let elapsedTime = 0;
|
let elapsedTime = 0;
|
||||||
const duration = totalDistance / this.speed;
|
const duration = totalDistance / velocity;
|
||||||
this.timeleft = duration;
|
this.timeleft = duration;
|
||||||
const interval = this.interval;
|
const interval = this.interval;
|
||||||
|
|
||||||
@@ -273,6 +273,20 @@ class movementManager {
|
|||||||
constrain(value) {
|
constrain(value) {
|
||||||
return Math.min(Math.max(value, this.minPosition), this.maxPosition);
|
return Math.min(Math.max(value, this.minPosition), this.maxPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNormalizedSpeed() {
|
||||||
|
const rawSpeed = Number.isFinite(this.speed) ? this.speed : 0;
|
||||||
|
const clampedSpeed = Math.max(0, rawSpeed);
|
||||||
|
const hasMax = Number.isFinite(this.maxSpeed) && this.maxSpeed > 0;
|
||||||
|
const effectiveSpeed = hasMax ? Math.min(clampedSpeed, this.maxSpeed) : clampedSpeed;
|
||||||
|
return effectiveSpeed / 100; // convert %/s -> fraction of range per second
|
||||||
|
}
|
||||||
|
|
||||||
|
getVelocity() {
|
||||||
|
const normalizedSpeed = this.getNormalizedSpeed();
|
||||||
|
const fullRange = this.maxPosition - this.minPosition;
|
||||||
|
return normalizedSpeed * fullRange;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = movementManager;
|
module.exports = movementManager;
|
||||||
|
|||||||
@@ -127,7 +127,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"maxSpeed": {
|
"maxSpeed": {
|
||||||
"default": 10,
|
"default": 1000,
|
||||||
"rules": {
|
"rules": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"description": "Maximum speed setting."
|
"description": "Maximum speed setting."
|
||||||
|
|||||||
Reference in New Issue
Block a user