node-opcua-aggregates 2.54.0 → 2.57.0

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.
Files changed (53) hide show
  1. package/.mocharc.yml +7 -7
  2. package/LICENSE +20 -20
  3. package/bin/sample_aggregate_server.js +14 -14
  4. package/dist/aggregates.js +2 -2
  5. package/dist/aggregates.js.map +1 -1
  6. package/dist/average.js +6 -5
  7. package/dist/average.js.map +1 -1
  8. package/dist/common.js +12 -2
  9. package/dist/common.js.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/interpolate.d.ts +1 -1
  13. package/dist/interpolate.js +8 -12
  14. package/dist/interpolate.js.map +1 -1
  15. package/dist/minmax.js +3 -2
  16. package/dist/minmax.js.map +1 -1
  17. package/dist/read_processed_details.d.ts +2 -2
  18. package/dist/read_processed_details.js +41 -38
  19. package/dist/read_processed_details.js.map +1 -1
  20. package/nyc.config.js +16 -16
  21. package/package.json +17 -15
  22. package/source/aggregates.ts +284 -277
  23. package/source/average.ts +71 -74
  24. package/source/common.ts +23 -10
  25. package/source/index.ts +11 -17
  26. package/source/interpolate.ts +14 -20
  27. package/source/interval.ts +3 -3
  28. package/source/minmax.ts +231 -231
  29. package/source/read_processed_details.ts +149 -139
  30. package/dist2/aggregates.d.ts +0 -7
  31. package/dist2/aggregates.js +0 -201
  32. package/dist2/aggregates.js.map +0 -1
  33. package/dist2/average.d.ts +0 -3
  34. package/dist2/average.js +0 -61
  35. package/dist2/average.js.map +0 -1
  36. package/dist2/common.d.ts +0 -8
  37. package/dist2/common.js +0 -89
  38. package/dist2/common.js.map +0 -1
  39. package/dist2/index.d.ts +0 -11
  40. package/dist2/index.js +0 -29
  41. package/dist2/index.js.map +0 -1
  42. package/dist2/interpolate.d.ts +0 -16
  43. package/dist2/interpolate.js +0 -135
  44. package/dist2/interpolate.js.map +0 -1
  45. package/dist2/interval.d.ts +0 -49
  46. package/dist2/interval.js +0 -165
  47. package/dist2/interval.js.map +0 -1
  48. package/dist2/minmax.d.ts +0 -18
  49. package/dist2/minmax.js +0 -149
  50. package/dist2/minmax.js.map +0 -1
  51. package/dist2/read_processed_details.d.ts +0 -6
  52. package/dist2/read_processed_details.js +0 -116
  53. package/dist2/read_processed_details.js.map +0 -1
package/source/minmax.ts CHANGED
@@ -1,231 +1,231 @@
1
- /**
2
- * @module node-opca-aggregates
3
- */
4
- // excert from OPC Unified Architecture, Part 13 21 Release 1.04
5
- // 5.4.3.10 Minimum
6
- // The Minimum Aggregate defined in Table 21 retrieves the minimum Good raw value within the
7
- // interval, and returns that value with the timestamp at the start of the interval. Note that if the
8
- // same minimum exists at more than one timestamp the MultipleValues bit is set.
9
- //
10
- // Unless otherwise indicated, StatusCodes are Good, Calculated. If the minimum value is on
11
- // the start time the status code will be Good, Raw. If only Bad quality values are available then
12
- // the status is returned as Bad_NoData.
13
- //
14
- // The timestamp of the Aggregate will always be the start of the interval for every
15
- // ProcessingInterval.
16
- //
17
- // Table 21 – Minimum Aggregate summary
18
- //
19
- // Minimum Aggregate Characteristics
20
- //
21
- // Type Calculated
22
- // Data Type Same as Source
23
- // Use Bounds None
24
- // Timestamp StartTime
25
- //
26
- // Status Code Calculations
27
- //
28
- // Calculation Method Custom
29
- // If no Bad values then the Status is Good. If Bad values exist then
30
- // the Status is Uncertain_SubNormal. If an Uncertain value is less
31
- // than the minimum Good value the Status is Uncertain_SubNormal.
32
- //
33
- // Partial Set Sometimes
34
- // If an interval is not a complete interval
35
- //
36
- // Calculated Set Sometimes
37
- // If the Minimum value is not on the StartTime of the interval or if the
38
- // Status was set to Uncertain_SubNormal because of non-Good
39
- // values in the interval
40
- //
41
- // Interpolated Not Set
42
- // Raw Set Sometimes
43
- // If Minimum value is on the StartTime of the interval
44
- //
45
- // Multi Value Set Sometimes
46
- // If multiple Good values exist with the Minimum value
47
- //
48
- // Status Code Common Special Cases
49
- // Before Start of Data Bad_NoData
50
- // After End of Data Bad_NoData
51
- // No Start Bound Not Applicable
52
- // No End Bound Not Applicable
53
- // Bound Bad Not Applicable
54
- // Bound Uncertain Not Applicable
55
- import { UAVariable } from "node-opcua-address-space";
56
- import { DataValue } from "node-opcua-data-value";
57
- import { StatusCode, StatusCodes } from "node-opcua-status-code";
58
- import { Variant } from "node-opcua-variant";
59
-
60
- import { getAggregateData } from "./common";
61
- import { AggregateConfigurationOptions, Interval, isGood } from "./interval";
62
-
63
- function calculateIntervalMinOrMaxValue(
64
- interval: Interval,
65
- options: AggregateConfigurationOptions,
66
- predicate: (a: Variant, b: Variant) => "equal" | "select" | "reject"
67
- ): DataValue {
68
-
69
- // console.log(interval.toString());
70
-
71
- const indexStart = interval.index;
72
- let selectedValue: Variant | null = null;
73
-
74
- let counter = 0;
75
- let statusCode: StatusCode;
76
- let isPartial = interval.isPartial;
77
-
78
- let isRaw = false;
79
- let hasBad = false;
80
-
81
- for (let i = indexStart; i < indexStart + interval.count; i++) {
82
- const dataValue = interval.dataValues[i];
83
-
84
- if (dataValue.statusCode === StatusCodes.BadNoData) {
85
- isPartial = true;
86
- continue;
87
- }
88
-
89
- if (!isGood(dataValue.statusCode)) {
90
- hasBad = true;
91
- continue;
92
- }
93
-
94
- if (!selectedValue) {
95
- selectedValue = dataValue.value;
96
- counter = 1;
97
- if (i === indexStart && dataValue.sourceTimestamp!.getTime() === interval.startTime.getTime()) {
98
- isRaw = true;
99
- }
100
- continue;
101
- }
102
- const compare = predicate(selectedValue, dataValue.value);
103
- if (compare === "equal") {
104
- counter = 1;
105
- continue;
106
- }
107
- if (compare === "select") {
108
- selectedValue = dataValue.value;
109
- counter = 1;
110
- }
111
- }
112
-
113
- if (!selectedValue) {
114
- return new DataValue({
115
- sourceTimestamp: interval.startTime,
116
- statusCode: StatusCodes.BadNoData
117
- });
118
- }
119
- if (isRaw) {
120
- if (hasBad) {
121
- statusCode = StatusCodes.UncertainDataSubNormal;
122
- } else {
123
- statusCode = StatusCodes.Good;
124
- }
125
- } else if (hasBad) {
126
- statusCode = StatusCode.makeStatusCode(StatusCodes.UncertainDataSubNormal, "HistorianCalculated");
127
- } else {
128
- statusCode = StatusCode.makeStatusCode(StatusCodes.Good, "HistorianCalculated");
129
- }
130
-
131
- if (counter > 1) {
132
- statusCode = StatusCode.makeStatusCode(statusCode, "HistorianMultiValue");
133
- }
134
- if (isPartial || interval.isPartial) {
135
- statusCode = StatusCode.makeStatusCode(statusCode, "HistorianPartial");
136
- }
137
-
138
- return new DataValue({
139
- sourceTimestamp: interval.startTime,
140
- statusCode: statusCode as StatusCode,
141
- value: selectedValue!
142
- });
143
- }
144
-
145
- export function calculateIntervalMinValue(interval: Interval, options: AggregateConfigurationOptions): DataValue {
146
- return calculateIntervalMinOrMaxValue(interval, options,
147
- (a: Variant, b: Variant) =>
148
- a.value > b.value ? "select" : (a.value === b.value ? "equal" : "reject"));
149
- }
150
-
151
- export function calculateIntervalMaxValue(interval: Interval, options: AggregateConfigurationOptions): DataValue {
152
- return calculateIntervalMinOrMaxValue(interval, options,
153
- (a: Variant, b: Variant) =>
154
- a.value < b.value ? "select" : (a.value === b.value ? "equal" : "reject"));
155
- }
156
-
157
- // From OPC Unified Architecture, Part 13 26 Release 1.04
158
- // 5.4.3.11 Maximum
159
- // The Maximum Aggregate defined in Table 22 retrieves the maximum Good raw value within
160
- // the interval, and returns that value with the timestamp at the start of the interval. Note that if
161
- // the same maximum exists at more than one timestamp the MultipleValues bit is set.
162
- // Unless otherwise indicated, StatusCodes are Good, Calculated. If the minimum value is on
163
- // the interval start time the status code will be Good, Raw. If only Bad quality values are
164
- // available then the status is returned as Bad_NoData.
165
- // The timestamp of the Aggregate will always be the start of the interval for every
166
- //
167
- // ProcessingInterval.
168
- //
169
- // Table 22 – Maximum Aggregate summary
170
- // Maximum Aggregate Characteristics
171
- //
172
- // Type Calculated
173
- // Data Type Same as Source
174
- // Use Bounds None
175
- // Timestamp StartTime
176
- //
177
- // Status Code Calculations
178
- // Calculation Method Custom
179
- // If no Bad values then the Status is Good. If Bad values exist then
180
- // the Status is Uncertain_SubNormal. If an Uncertain value is greater
181
- // than the maximum Good value the Status is Uncertain_SubNormal
182
- //
183
- // Partial Set Sometimes
184
- // If an interval is not a complete interval
185
- //
186
- // Calculated Set Sometimes
187
- // If the Maximum value is not on the startTime of the interval or if the
188
- // Status was set to Uncertain_SubNormal because of non-Good
189
- // values in the interval
190
- //
191
- // Interpolated Not Set
192
- //
193
- // Raw Set Sometimes
194
- // If Maximum value is on the startTime of the interval
195
- // Multi Value Set Sometimes
196
- // If multiple Good values exist with the Maximum value
197
- //
198
- // Status Code Common Special Cases
199
- // Before Start of Data Bad_NoData
200
- // After End of Data Bad_NoData
201
- // No Start Bound Not Applicable
202
- // No End Bound Not Applicable
203
- // Bound Bad Not Applicable
204
- // Bound Uncertain Not Applicable
205
- /**
206
- *
207
- * @param node
208
- * @param processingInterval
209
- * @param startDate
210
- * @param endDate
211
- * @param callback
212
- */
213
- export function getMinData(
214
- node: UAVariable,
215
- processingInterval: number,
216
- startDate: Date,
217
- endDate: Date,
218
- callback: (err: Error | null, dataValues?: DataValue[]) => void
219
- ) {
220
- return getAggregateData(node, processingInterval, startDate, endDate, calculateIntervalMinValue, callback);
221
- }
222
-
223
- export function getMaxData(
224
- node: UAVariable,
225
- processingInterval: number,
226
- startDate: Date,
227
- endDate: Date,
228
- callback: (err: Error | null, dataValues?: DataValue[]) => void
229
- ) {
230
- return getAggregateData(node, processingInterval, startDate, endDate, calculateIntervalMaxValue, callback);
231
- }
1
+ /**
2
+ * @module node-opca-aggregates
3
+ */
4
+ // excerpt from OPC Unified Architecture, Part 13 21 Release 1.04
5
+ // 5.4.3.10 Minimum
6
+ // The Minimum Aggregate defined in Table 21 retrieves the minimum Good raw value within the
7
+ // interval, and returns that value with the timestamp at the start of the interval. Note that if the
8
+ // same minimum exists at more than one timestamp the MultipleValues bit is set.
9
+ //
10
+ // Unless otherwise indicated, StatusCodes are Good, Calculated. If the minimum value is on
11
+ // the start time the status code will be Good, Raw. If only Bad quality values are available then
12
+ // the status is returned as Bad_NoData.
13
+ //
14
+ // The timestamp of the Aggregate will always be the start of the interval for every
15
+ // ProcessingInterval.
16
+ //
17
+ // Table 21 – Minimum Aggregate summary
18
+ //
19
+ // Minimum Aggregate Characteristics
20
+ //
21
+ // Type Calculated
22
+ // Data Type Same as Source
23
+ // Use Bounds None
24
+ // Timestamp StartTime
25
+ //
26
+ // Status Code Calculations
27
+ //
28
+ // Calculation Method Custom
29
+ // If no Bad values then the Status is Good. If Bad values exist then
30
+ // the Status is Uncertain_SubNormal. If an Uncertain value is less
31
+ // than the minimum Good value the Status is Uncertain_SubNormal.
32
+ //
33
+ // Partial Set Sometimes
34
+ // If an interval is not a complete interval
35
+ //
36
+ // Calculated Set Sometimes
37
+ // If the Minimum value is not on the StartTime of the interval or if the
38
+ // Status was set to Uncertain_SubNormal because of non-Good
39
+ // values in the interval
40
+ //
41
+ // Interpolated Not Set
42
+ // Raw Set Sometimes
43
+ // If Minimum value is on the StartTime of the interval
44
+ //
45
+ // Multi Value Set Sometimes
46
+ // If multiple Good values exist with the Minimum value
47
+ //
48
+ // Status Code Common Special Cases
49
+ // Before Start of Data Bad_NoData
50
+ // After End of Data Bad_NoData
51
+ // No Start Bound Not Applicable
52
+ // No End Bound Not Applicable
53
+ // Bound Bad Not Applicable
54
+ // Bound Uncertain Not Applicable
55
+ import { UAVariable } from "node-opcua-address-space";
56
+ import { DataValue } from "node-opcua-data-value";
57
+ import { StatusCode, StatusCodes } from "node-opcua-status-code";
58
+ import { Variant } from "node-opcua-variant";
59
+
60
+ import { getAggregateData } from "./common";
61
+ import { AggregateConfigurationOptions, Interval, isGood } from "./interval";
62
+
63
+ // eslint-disable-next-line max-statements
64
+ function calculateIntervalMinOrMaxValue(
65
+ interval: Interval,
66
+ options: AggregateConfigurationOptions,
67
+ predicate: (a: Variant, b: Variant) => "equal" | "select" | "reject"
68
+ ): DataValue {
69
+ // console.log(interval.toString());
70
+
71
+ const indexStart = interval.index;
72
+ let selectedValue: Variant | null = null;
73
+
74
+ let counter = 0;
75
+ let statusCode: StatusCode;
76
+ let isPartial = interval.isPartial;
77
+
78
+ let isRaw = false;
79
+ let hasBad = false;
80
+
81
+ for (let i = indexStart; i < indexStart + interval.count; i++) {
82
+ const dataValue = interval.dataValues[i];
83
+
84
+ if (dataValue.statusCode === StatusCodes.BadNoData) {
85
+ isPartial = true;
86
+ continue;
87
+ }
88
+
89
+ if (!isGood(dataValue.statusCode)) {
90
+ hasBad = true;
91
+ continue;
92
+ }
93
+
94
+ if (!selectedValue) {
95
+ selectedValue = dataValue.value;
96
+ counter = 1;
97
+ if (i === indexStart && dataValue.sourceTimestamp!.getTime() === interval.startTime.getTime()) {
98
+ isRaw = true;
99
+ }
100
+ continue;
101
+ }
102
+ const compare = predicate(selectedValue, dataValue.value);
103
+ if (compare === "equal") {
104
+ counter = 1;
105
+ continue;
106
+ }
107
+ if (compare === "select") {
108
+ selectedValue = dataValue.value;
109
+ counter = 1;
110
+ }
111
+ }
112
+
113
+ if (!selectedValue) {
114
+ return new DataValue({
115
+ sourceTimestamp: interval.startTime,
116
+ statusCode: StatusCodes.BadNoData
117
+ });
118
+ }
119
+ if (isRaw) {
120
+ if (hasBad) {
121
+ statusCode = StatusCodes.UncertainDataSubNormal;
122
+ } else {
123
+ statusCode = StatusCodes.Good;
124
+ }
125
+ } else if (hasBad) {
126
+ statusCode = StatusCode.makeStatusCode(StatusCodes.UncertainDataSubNormal, "HistorianCalculated");
127
+ } else {
128
+ statusCode = StatusCode.makeStatusCode(StatusCodes.Good, "HistorianCalculated");
129
+ }
130
+
131
+ if (counter > 1) {
132
+ statusCode = StatusCode.makeStatusCode(statusCode, "HistorianMultiValue");
133
+ }
134
+ if (isPartial || interval.isPartial) {
135
+ statusCode = StatusCode.makeStatusCode(statusCode, "HistorianPartial");
136
+ }
137
+
138
+ return new DataValue({
139
+ sourceTimestamp: interval.startTime,
140
+ statusCode: statusCode as StatusCode,
141
+ value: selectedValue!
142
+ });
143
+ }
144
+
145
+ export function calculateIntervalMinValue(interval: Interval, options: AggregateConfigurationOptions): DataValue {
146
+ return calculateIntervalMinOrMaxValue(interval, options, (a: Variant, b: Variant) =>
147
+ a.value > b.value ? "select" : a.value === b.value ? "equal" : "reject"
148
+ );
149
+ }
150
+
151
+ export function calculateIntervalMaxValue(interval: Interval, options: AggregateConfigurationOptions): DataValue {
152
+ return calculateIntervalMinOrMaxValue(interval, options, (a: Variant, b: Variant) =>
153
+ a.value < b.value ? "select" : a.value === b.value ? "equal" : "reject"
154
+ );
155
+ }
156
+
157
+ // From OPC Unified Architecture, Part 13 26 Release 1.04
158
+ // 5.4.3.11 Maximum
159
+ // The Maximum Aggregate defined in Table 22 retrieves the maximum Good raw value within
160
+ // the interval, and returns that value with the timestamp at the start of the interval. Note that if
161
+ // the same maximum exists at more than one timestamp the MultipleValues bit is set.
162
+ // Unless otherwise indicated, StatusCodes are Good, Calculated. If the minimum value is on
163
+ // the interval start time the status code will be Good, Raw. If only Bad quality values are
164
+ // available then the status is returned as Bad_NoData.
165
+ // The timestamp of the Aggregate will always be the start of the interval for every
166
+ //
167
+ // ProcessingInterval.
168
+ //
169
+ // Table 22 – Maximum Aggregate summary
170
+ // Maximum Aggregate Characteristics
171
+ //
172
+ // Type Calculated
173
+ // Data Type Same as Source
174
+ // Use Bounds None
175
+ // Timestamp StartTime
176
+ //
177
+ // Status Code Calculations
178
+ // Calculation Method Custom
179
+ // If no Bad values then the Status is Good. If Bad values exist then
180
+ // the Status is Uncertain_SubNormal. If an Uncertain value is greater
181
+ // than the maximum Good value the Status is Uncertain_SubNormal
182
+ //
183
+ // Partial Set Sometimes
184
+ // If an interval is not a complete interval
185
+ //
186
+ // Calculated Set Sometimes
187
+ // If the Maximum value is not on the startTime of the interval or if the
188
+ // Status was set to Uncertain_SubNormal because of non-Good
189
+ // values in the interval
190
+ //
191
+ // Interpolated Not Set
192
+ //
193
+ // Raw Set Sometimes
194
+ // If Maximum value is on the startTime of the interval
195
+ // Multi Value Set Sometimes
196
+ // If multiple Good values exist with the Maximum value
197
+ //
198
+ // Status Code Common Special Cases
199
+ // Before Start of Data Bad_NoData
200
+ // After End of Data Bad_NoData
201
+ // No Start Bound Not Applicable
202
+ // No End Bound Not Applicable
203
+ // Bound Bad Not Applicable
204
+ // Bound Uncertain Not Applicable
205
+ /**
206
+ *
207
+ * @param node
208
+ * @param processingInterval
209
+ * @param startDate
210
+ * @param endDate
211
+ * @param callback
212
+ */
213
+ export function getMinData(
214
+ node: UAVariable,
215
+ processingInterval: number,
216
+ startDate: Date,
217
+ endDate: Date,
218
+ callback: (err: Error | null, dataValues?: DataValue[]) => void
219
+ ): void {
220
+ return getAggregateData(node, processingInterval, startDate, endDate, calculateIntervalMinValue, callback);
221
+ }
222
+
223
+ export function getMaxData(
224
+ node: UAVariable,
225
+ processingInterval: number,
226
+ startDate: Date,
227
+ endDate: Date,
228
+ callback: (err: Error | null, dataValues?: DataValue[]) => void
229
+ ): void {
230
+ return getAggregateData(node, processingInterval, startDate, endDate, calculateIntervalMaxValue, callback);
231
+ }