@yarkivaev/scada 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/clickhouseSensor.js +4 -4
- package/src/machineChronology.js +3 -1
- package/src/segments.js +15 -3
package/package.json
CHANGED
package/src/clickhouseSensor.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @example
|
|
16
16
|
* const sensor = clickhouseSensor(conn, 'icht1/voltage', 'Voltage', 'V');
|
|
17
17
|
* sensor.name(); // 'Voltage'
|
|
18
|
-
* await sensor.current(); // { timestamp, value, unit }
|
|
18
|
+
* await sensor.current(); // { found: true, timestamp, value, unit } or { found: false }
|
|
19
19
|
* await sensor.measurements({ start, end }, 60000); // downsampled to 1-minute intervals
|
|
20
20
|
* sensor.stream(since, 1000, callback); // live stream
|
|
21
21
|
*/
|
|
@@ -37,16 +37,16 @@ export default function clickhouseSensor(connection, topic, displayName, unit) {
|
|
|
37
37
|
{ topic }
|
|
38
38
|
);
|
|
39
39
|
if (rows.length === 0) {
|
|
40
|
-
return {
|
|
40
|
+
return { found: false };
|
|
41
41
|
}
|
|
42
|
-
return { timestamp: new Date(`${rows[0].ts}Z`), value: rows[0].value, unit };
|
|
42
|
+
return { found: true, timestamp: new Date(`${rows[0].ts}Z`), value: rows[0].value, unit };
|
|
43
43
|
},
|
|
44
44
|
async measurements(range, step) {
|
|
45
45
|
const seconds = Math.max(1, Math.floor(step / 1000));
|
|
46
46
|
const rows = await connection.query(
|
|
47
47
|
`SELECT
|
|
48
48
|
toStartOfInterval(ts, INTERVAL ${seconds} SECOND) as ts,
|
|
49
|
-
|
|
49
|
+
anyLast(value) as value
|
|
50
50
|
FROM scada.metrics
|
|
51
51
|
WHERE topic = {topic:String}
|
|
52
52
|
AND ts >= toStartOfInterval({start:DateTime64(3)}, INTERVAL ${seconds} SECOND)
|
package/src/machineChronology.js
CHANGED
|
@@ -25,7 +25,9 @@ export default function machineChronology(initial, history, sensors) {
|
|
|
25
25
|
const values = await Promise.all(keys.map((key) => {
|
|
26
26
|
return sensors[key].current();
|
|
27
27
|
}));
|
|
28
|
-
keys.forEach((key, i) => {
|
|
28
|
+
keys.forEach((key, i) => {
|
|
29
|
+
result[key] = values[i].found ? values[i] : { value: 0, unit: '' };
|
|
30
|
+
});
|
|
29
31
|
}
|
|
30
32
|
return result;
|
|
31
33
|
}
|
package/src/segments.js
CHANGED
|
@@ -10,7 +10,7 @@ import pubsub from './pubsub.js';
|
|
|
10
10
|
* @example
|
|
11
11
|
* const segs = segments();
|
|
12
12
|
* segs.add({ name: 'on', startTime: new Date(), endTime: new Date(), duration: 60 });
|
|
13
|
-
* segs.relabel(startTime, 'heating');
|
|
13
|
+
* segs.relabel(startTime, ['heating'], {});
|
|
14
14
|
* segs.query(); // all segments
|
|
15
15
|
* segs.query({ from: '2024-01-01', to: '2024-01-02' }); // filtered
|
|
16
16
|
* const sub = segs.stream((e) => console.log(e));
|
|
@@ -24,12 +24,24 @@ export default function segments() {
|
|
|
24
24
|
items.push(segment);
|
|
25
25
|
bus.emit({ type: 'created', segment });
|
|
26
26
|
},
|
|
27
|
-
relabel(start,
|
|
27
|
+
relabel(start, tags, properties) {
|
|
28
28
|
const found = items.find((item) => {
|
|
29
29
|
return item.startTime.getTime() === start.getTime();
|
|
30
30
|
});
|
|
31
31
|
if (found) {
|
|
32
|
-
found.
|
|
32
|
+
found.tags = tags;
|
|
33
|
+
found.properties = properties;
|
|
34
|
+
bus.emit({ type: 'relabeled', segment: found });
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
retag(start, tags, properties) {
|
|
38
|
+
const found = items.find((item) => {
|
|
39
|
+
return item.startTime.getTime() === start.getTime();
|
|
40
|
+
});
|
|
41
|
+
if (found) {
|
|
42
|
+
found.tags = tags;
|
|
43
|
+
found.properties = properties;
|
|
44
|
+
delete found.options;
|
|
33
45
|
bus.emit({ type: 'relabeled', segment: found });
|
|
34
46
|
}
|
|
35
47
|
},
|