@yarkivaev/scada 2.5.0 → 2.5.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/README.md CHANGED
@@ -579,3 +579,7 @@ servers:
579
579
  ```
580
580
 
581
581
  This changes the selected server only; it does not mutate the shared profile.
582
+
583
+ ### Central backup freshness
584
+
585
+ Silent Modbus backup sources use `MX210/<device>` freshness identities. AMQP telemetry tracks `<source-family>/<device>`, so cooling for a device cannot hide missing MX210 electrical samples. Measurement topic paths are unchanged. Custom freshness callbacks must pass the source’s full identity to `seen()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -59,12 +59,12 @@ export function mx210Metrics(device, collector) {
59
59
  * @param {string} name - Stream id (device name in MX210 topics)
60
60
  * @param {string} host - Modbus TCP host
61
61
  * @param {number} port - Modbus TCP port
62
- * @returns {object} Stream with name() and open(collector, clock, interval)
62
+ * @returns {object} Stream with family/device name() and open(collector, clock, interval)
63
63
  */
64
64
  export default function mx210Tcp(name, host, port) {
65
65
  return Object.freeze({
66
66
  name() {
67
- return name;
67
+ return `MX210/${name}`;
68
68
  },
69
69
  open(collector, clk, interval) {
70
70
  return modbusSource(
@@ -2,10 +2,10 @@
2
2
  * Extracts the stream id from a metrics MQTT/AMQP topic path.
3
3
  *
4
4
  * @example
5
- * streamNameFromTopic('MX210/m-1/GET/AI1/VALUE') === 'm-1'
5
+ * streamNameFromTopic('MX210/m-1/GET/AI1/VALUE') === 'MX210/m-1'
6
6
  *
7
7
  * @param {string} topic - Slash-separated topic
8
- * @returns {string|undefined} Device/stream id
8
+ * @returns {string|undefined} Source-family/device id
9
9
  */
10
10
  export default function streamNameFromTopic(topic) {
11
11
  if (typeof topic !== 'string' || topic.length === 0) {
@@ -17,5 +17,5 @@ export default function streamNameFromTopic(topic) {
17
17
  if (parts.length < 2) {
18
18
  return undefined;
19
19
  }
20
- return parts[1];
20
+ return `${parts[0]}/${parts[1]}`;
21
21
  }
@@ -1,5 +1,9 @@
1
1
  import cycleLookback from '../../../domain/timeline/cycleLookback.js';
2
2
 
3
+ function phases(store) {
4
+ return store.segments.filter((row) => { return (row.kind || 'phase') === 'phase'; });
5
+ }
6
+
3
7
  function parseJsonField(raw) {
4
8
  if (!raw) {
5
9
  return null;
@@ -25,19 +29,19 @@ function segmentItem(row) {
25
29
 
26
30
  function segmentAt(store, machineId, startEpoch) {
27
31
  const startMs = startEpoch * 1000;
28
- const row = store.segments.find((item) => {
32
+ const row = phases(store).find((item) => {
29
33
  return item.machine === machineId && new Date(item.start_time).getTime() === startMs;
30
34
  });
31
35
  return segmentItem(row);
32
36
  }
33
37
 
34
38
  function replayCursorFor(store, machineId) {
35
- const closed = store.segments.filter((row) => {
39
+ const closed = phases(store).filter((row) => {
36
40
  return row.machine === machineId && Number(row.duration) > 0;
37
41
  }).map((row) => {
38
42
  return new Date(row.end_time).getTime() / 1000;
39
43
  });
40
- const pending = store.segments.filter((row) => {
44
+ const pending = phases(store).filter((row) => {
41
45
  return row.machine === machineId && Number(row.duration) === 0;
42
46
  }).map((row) => {
43
47
  return new Date(row.start_time).getTime() / 1000;
@@ -67,7 +71,7 @@ export default function checkpointStateMemory(store) {
67
71
  return replayCursorFor(store, machineId);
68
72
  },
69
73
  pendingSegments() {
70
- return store.segments.filter((row) => {
74
+ return phases(store).filter((row) => {
71
75
  return Number(row.duration) === 0;
72
76
  }).map((row) => {
73
77
  return {
@@ -98,7 +102,7 @@ export default function checkpointStateMemory(store) {
98
102
  },
99
103
  cyclePrior(machineId, beforeEpoch, resetTags) {
100
104
  const beforeMs = Number(beforeEpoch) * 1000;
101
- const rows = store.segments.filter((row) => {
105
+ const rows = phases(store).filter((row) => {
102
106
  return row.machine === machineId && new Date(row.start_time).getTime() < beforeMs;
103
107
  }).sort((a, b) => {
104
108
  return new Date(b.start_time) - new Date(a.start_time);
@@ -37,12 +37,12 @@ function replayCursor(pool, machineId) {
37
37
  `WITH closed AS (
38
38
  SELECT MAX(EXTRACT(EPOCH FROM end_time)) AS ts
39
39
  FROM segments
40
- WHERE machine = $1 AND duration > 0
40
+ WHERE machine = $1 AND kind = 'phase' AND duration > 0
41
41
  ),
42
42
  pending AS (
43
43
  SELECT MAX(EXTRACT(EPOCH FROM start_time)) AS ts
44
44
  FROM segments
45
- WHERE machine = $1 AND duration = 0
45
+ WHERE machine = $1 AND kind = 'phase' AND duration = 0
46
46
  )
47
47
  SELECT COALESCE(LEAST(closed.ts, pending.ts), pending.ts, closed.ts, 0.0) AS cursor
48
48
  FROM closed, pending`,
@@ -58,7 +58,7 @@ function pendingSegments(pool) {
58
58
  EXTRACT(EPOCH FROM start_time) AS start,
59
59
  EXTRACT(EPOCH FROM end_time) AS end
60
60
  FROM segments
61
- WHERE duration = 0`
61
+ WHERE kind = 'phase' AND duration = 0`
62
62
  ).then((result) => {
63
63
  return result.rows.map((row) => {
64
64
  return {
@@ -116,7 +116,7 @@ export default function checkpointStatePg(pool, metricsEnabled = true) {
116
116
  return pool.query(
117
117
  `SELECT name, start_time, end_time, duration, tags, options, properties
118
118
  FROM segments
119
- WHERE machine = $1 AND start_time < $2
119
+ WHERE machine = $1 AND kind = 'phase' AND start_time < $2
120
120
  ORDER BY start_time DESC`,
121
121
  [machineId, new Date(beforeEpoch * 1000)]
122
122
  ).then((result) => {