@yarkivaev/scada 2.5.0 → 2.5.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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) => {