node-opcua-aggregates 2.97.0 → 2.98.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/dist/interval.js CHANGED
@@ -1,200 +1,200 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInterval = exports.Interval = exports.adjustProcessingOptions = exports._findGoodDataValueAfter = exports._findGoodDataValueBefore = exports.isUncertain = exports.isGoodish2 = void 0;
4
- /**
5
- * @module node-opca-aggregates
6
- */
7
- const node_opcua_data_value_1 = require("node-opcua-data-value");
8
- const node_opcua_status_code_1 = require("node-opcua-status-code");
9
- function isGoodish2(statusCode, { treatUncertainAsBad }) {
10
- if (statusCode.isGoodish())
11
- return true;
12
- if (isUncertain(statusCode))
13
- return !treatUncertainAsBad;
14
- return false;
15
- }
16
- exports.isGoodish2 = isGoodish2;
17
- function isUncertain(statusCode) {
18
- return (statusCode.value & 0x40000000) === 0x40000000 && statusCode.value !== node_opcua_status_code_1.StatusCodes.BadNoData.value;
19
- }
20
- exports.isUncertain = isUncertain;
21
- function _findGoodDataValueBefore(dataValues, index, bTreatUncertainAsBad) {
22
- index--;
23
- while (index >= 0) {
24
- const dataValue1 = dataValues[index];
25
- if (!bTreatUncertainAsBad && !dataValue1.statusCode.isBad()) {
26
- return { index, dataValue: dataValue1 };
27
- }
28
- if (bTreatUncertainAsBad && dataValue1.statusCode.isGood()) {
29
- return { index, dataValue: dataValue1 };
30
- }
31
- index -= 1;
32
- }
33
- // not found
34
- return {
35
- dataValue: new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoData }),
36
- index: -1
37
- };
38
- }
39
- exports._findGoodDataValueBefore = _findGoodDataValueBefore;
40
- function _findGoodDataValueAfter(dataValues, index, bTreatUncertainAsBad) {
41
- while (index < dataValues.length) {
42
- const dataValue1 = dataValues[index];
43
- if (!bTreatUncertainAsBad && !dataValue1.statusCode.isBad()) {
44
- return {
45
- dataValue: dataValue1,
46
- index
47
- };
48
- }
49
- if (bTreatUncertainAsBad && dataValue1.statusCode.isGood()) {
50
- return {
51
- dataValue: dataValue1,
52
- index
53
- };
54
- }
55
- index += 1;
56
- }
57
- // not found
58
- return {
59
- dataValue: new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoData }),
60
- index: -1
61
- };
62
- }
63
- exports._findGoodDataValueAfter = _findGoodDataValueAfter;
64
- function adjustProcessingOptions(options) {
65
- options = options || {};
66
- options.treatUncertainAsBad = options.treatUncertainAsBad || false;
67
- options.useSlopedExtrapolation = options.useSlopedExtrapolation || false;
68
- options.stepped = options.stepped || false;
69
- options.percentDataBad = parseInt(options.percentDataBad, 10);
70
- options.percentDataGood = parseInt(options.percentDataGood, 10);
71
- return options;
72
- }
73
- exports.adjustProcessingOptions = adjustProcessingOptions;
74
- class Interval {
75
- // startTime
76
- // dataValues
77
- // index: index of first dataValue inside the interval
78
- // count: number of dataValue inside the interval
79
- constructor(options) {
80
- this.startTime = options.startTime;
81
- this.dataValues = options.dataValues;
82
- this.index = options.index;
83
- this.count = options.count;
84
- this.isPartial = options.isPartial;
85
- this.processingInterval = options.processingInterval;
86
- }
87
- getPercentBad() {
88
- return 100;
89
- }
90
- /**
91
- * returns true if a raw data exists at start
92
- */
93
- hasRawDataAsStart() {
94
- const index = this.index;
95
- if (index < 0) {
96
- return false;
97
- }
98
- const dataValue1 = this.dataValues[index];
99
- return this.startTime.getTime() === dataValue1.sourceTimestamp.getTime();
100
- }
101
- /**
102
- * Find the first good or uncertain dataValue
103
- * just preceding this interval
104
- * @returns {*}
105
- */
106
- beforeStartDataValue(bTreatUncertainAsBad) {
107
- return _findGoodDataValueBefore(this.dataValues, this.index, bTreatUncertainAsBad);
108
- }
109
- nextStartDataValue(bTreatUncertainAsBad) {
110
- return _findGoodDataValueAfter(this.dataValues, this.index, bTreatUncertainAsBad);
111
- }
112
- toString() {
113
- let str = "";
114
- str += "startTime " + this.startTime.toUTCString() + "\n";
115
- str += "start " + this.index + " ";
116
- str += "count " + this.count + " ";
117
- str += "isPartial " + this.isPartial + "\n";
118
- if (this.index >= 0) {
119
- for (let i = this.index; i < this.index + this.count; i++) {
120
- const dataValue = this.dataValues[i];
121
- str += " " + dataValue.sourceTimestamp.toUTCString() + dataValue.statusCode.toString();
122
- str += dataValue.value ? dataValue.value.toString() : "";
123
- str += "\n";
124
- }
125
- }
126
- return str;
127
- }
128
- getEffectiveEndTime() {
129
- const e = this.startTime.getTime() + this.processingInterval;
130
- if (!this.dataValues || this.dataValues.length === 0) {
131
- return e;
132
- }
133
- let i = this.dataValues.length - 1;
134
- while (i >= 0 && this.dataValues[i].statusCode.equals(node_opcua_status_code_1.StatusCodes.BadNoData)) {
135
- i--;
136
- }
137
- if (i < 0) {
138
- return e;
139
- }
140
- const lastTimestamp = this.dataValues[i].sourceTimestamp;
141
- return Math.min(e, lastTimestamp.getTime() + 1);
142
- }
143
- /**
144
- *
145
- * @returns the interval duration
146
- */
147
- duration() {
148
- const t1 = this.dataValues[this.index].sourceTimestamp.getTime();
149
- const e = this.getEffectiveEndTime();
150
- return e - t1;
151
- }
152
- /**
153
- * returns the region duration starting at index and finishing at index+1 or end limit of the interval
154
- */
155
- regionDuration(index) {
156
- const t1 = this.dataValues[index].sourceTimestamp.getTime();
157
- const e = this.getEffectiveEndTime();
158
- const t2 = index < this.dataValues.length - 1 ? Math.min(this.dataValues[index + 1].sourceTimestamp.getTime(), e) : e;
159
- return t2 - t1;
160
- }
161
- }
162
- exports.Interval = Interval;
163
- function getInterval(startTime, processingInterval, indexHint, dataValues) {
164
- let count = 0;
165
- let index = -1;
166
- for (let i = indexHint; i < dataValues.length; i++) {
167
- if (dataValues[i].sourceTimestamp.getTime() < startTime.getTime()) {
168
- continue;
169
- }
170
- index = i;
171
- break;
172
- }
173
- if (index >= 0) {
174
- for (let i = index; i < dataValues.length; i++) {
175
- if (dataValues[i].sourceTimestamp.getTime() >= startTime.getTime() + processingInterval) {
176
- break;
177
- }
178
- count++;
179
- }
180
- }
181
- // check if interval is complete or partial (end or start)
182
- let isPartial = false;
183
- if (index + count >= dataValues.length &&
184
- dataValues[dataValues.length - 1].sourceTimestamp.getTime() < startTime.getTime() + processingInterval) {
185
- isPartial = true;
186
- }
187
- if (index <= 0 && dataValues[0].sourceTimestamp.getTime() > startTime.getTime()) {
188
- isPartial = true;
189
- }
190
- return new Interval({
191
- count,
192
- dataValues,
193
- index,
194
- isPartial,
195
- startTime,
196
- processingInterval
197
- });
198
- }
199
- exports.getInterval = getInterval;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInterval = exports.Interval = exports.adjustProcessingOptions = exports._findGoodDataValueAfter = exports._findGoodDataValueBefore = exports.isUncertain = exports.isGoodish2 = void 0;
4
+ /**
5
+ * @module node-opca-aggregates
6
+ */
7
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
8
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
9
+ function isGoodish2(statusCode, { treatUncertainAsBad }) {
10
+ if (statusCode.isGoodish())
11
+ return true;
12
+ if (isUncertain(statusCode))
13
+ return !treatUncertainAsBad;
14
+ return false;
15
+ }
16
+ exports.isGoodish2 = isGoodish2;
17
+ function isUncertain(statusCode) {
18
+ return (statusCode.value & 0x40000000) === 0x40000000 && statusCode.value !== node_opcua_status_code_1.StatusCodes.BadNoData.value;
19
+ }
20
+ exports.isUncertain = isUncertain;
21
+ function _findGoodDataValueBefore(dataValues, index, bTreatUncertainAsBad) {
22
+ index--;
23
+ while (index >= 0) {
24
+ const dataValue1 = dataValues[index];
25
+ if (!bTreatUncertainAsBad && !dataValue1.statusCode.isBad()) {
26
+ return { index, dataValue: dataValue1 };
27
+ }
28
+ if (bTreatUncertainAsBad && dataValue1.statusCode.isGood()) {
29
+ return { index, dataValue: dataValue1 };
30
+ }
31
+ index -= 1;
32
+ }
33
+ // not found
34
+ return {
35
+ dataValue: new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoData }),
36
+ index: -1
37
+ };
38
+ }
39
+ exports._findGoodDataValueBefore = _findGoodDataValueBefore;
40
+ function _findGoodDataValueAfter(dataValues, index, bTreatUncertainAsBad) {
41
+ while (index < dataValues.length) {
42
+ const dataValue1 = dataValues[index];
43
+ if (!bTreatUncertainAsBad && !dataValue1.statusCode.isBad()) {
44
+ return {
45
+ dataValue: dataValue1,
46
+ index
47
+ };
48
+ }
49
+ if (bTreatUncertainAsBad && dataValue1.statusCode.isGood()) {
50
+ return {
51
+ dataValue: dataValue1,
52
+ index
53
+ };
54
+ }
55
+ index += 1;
56
+ }
57
+ // not found
58
+ return {
59
+ dataValue: new node_opcua_data_value_1.DataValue({ statusCode: node_opcua_status_code_1.StatusCodes.BadNoData }),
60
+ index: -1
61
+ };
62
+ }
63
+ exports._findGoodDataValueAfter = _findGoodDataValueAfter;
64
+ function adjustProcessingOptions(options) {
65
+ options = options || {};
66
+ options.treatUncertainAsBad = options.treatUncertainAsBad || false;
67
+ options.useSlopedExtrapolation = options.useSlopedExtrapolation || false;
68
+ options.stepped = options.stepped || false;
69
+ options.percentDataBad = parseInt(options.percentDataBad, 10);
70
+ options.percentDataGood = parseInt(options.percentDataGood, 10);
71
+ return options;
72
+ }
73
+ exports.adjustProcessingOptions = adjustProcessingOptions;
74
+ class Interval {
75
+ // startTime
76
+ // dataValues
77
+ // index: index of first dataValue inside the interval
78
+ // count: number of dataValue inside the interval
79
+ constructor(options) {
80
+ this.startTime = options.startTime;
81
+ this.dataValues = options.dataValues;
82
+ this.index = options.index;
83
+ this.count = options.count;
84
+ this.isPartial = options.isPartial;
85
+ this.processingInterval = options.processingInterval;
86
+ }
87
+ getPercentBad() {
88
+ return 100;
89
+ }
90
+ /**
91
+ * returns true if a raw data exists at start
92
+ */
93
+ hasRawDataAsStart() {
94
+ const index = this.index;
95
+ if (index < 0) {
96
+ return false;
97
+ }
98
+ const dataValue1 = this.dataValues[index];
99
+ return this.startTime.getTime() === dataValue1.sourceTimestamp.getTime();
100
+ }
101
+ /**
102
+ * Find the first good or uncertain dataValue
103
+ * just preceding this interval
104
+ * @returns {*}
105
+ */
106
+ beforeStartDataValue(bTreatUncertainAsBad) {
107
+ return _findGoodDataValueBefore(this.dataValues, this.index, bTreatUncertainAsBad);
108
+ }
109
+ nextStartDataValue(bTreatUncertainAsBad) {
110
+ return _findGoodDataValueAfter(this.dataValues, this.index, bTreatUncertainAsBad);
111
+ }
112
+ toString() {
113
+ let str = "";
114
+ str += "startTime " + this.startTime.toUTCString() + "\n";
115
+ str += "start " + this.index + " ";
116
+ str += "count " + this.count + " ";
117
+ str += "isPartial " + this.isPartial + "\n";
118
+ if (this.index >= 0) {
119
+ for (let i = this.index; i < this.index + this.count; i++) {
120
+ const dataValue = this.dataValues[i];
121
+ str += " " + dataValue.sourceTimestamp.toUTCString() + dataValue.statusCode.toString();
122
+ str += dataValue.value ? dataValue.value.toString() : "";
123
+ str += "\n";
124
+ }
125
+ }
126
+ return str;
127
+ }
128
+ getEffectiveEndTime() {
129
+ const e = this.startTime.getTime() + this.processingInterval;
130
+ if (!this.dataValues || this.dataValues.length === 0) {
131
+ return e;
132
+ }
133
+ let i = this.dataValues.length - 1;
134
+ while (i >= 0 && this.dataValues[i].statusCode.equals(node_opcua_status_code_1.StatusCodes.BadNoData)) {
135
+ i--;
136
+ }
137
+ if (i < 0) {
138
+ return e;
139
+ }
140
+ const lastTimestamp = this.dataValues[i].sourceTimestamp;
141
+ return Math.min(e, lastTimestamp.getTime() + 1);
142
+ }
143
+ /**
144
+ *
145
+ * @returns the interval duration
146
+ */
147
+ duration() {
148
+ const t1 = this.dataValues[this.index].sourceTimestamp.getTime();
149
+ const e = this.getEffectiveEndTime();
150
+ return e - t1;
151
+ }
152
+ /**
153
+ * returns the region duration starting at index and finishing at index+1 or end limit of the interval
154
+ */
155
+ regionDuration(index) {
156
+ const t1 = this.dataValues[index].sourceTimestamp.getTime();
157
+ const e = this.getEffectiveEndTime();
158
+ const t2 = index < this.dataValues.length - 1 ? Math.min(this.dataValues[index + 1].sourceTimestamp.getTime(), e) : e;
159
+ return t2 - t1;
160
+ }
161
+ }
162
+ exports.Interval = Interval;
163
+ function getInterval(startTime, processingInterval, indexHint, dataValues) {
164
+ let count = 0;
165
+ let index = -1;
166
+ for (let i = indexHint; i < dataValues.length; i++) {
167
+ if (dataValues[i].sourceTimestamp.getTime() < startTime.getTime()) {
168
+ continue;
169
+ }
170
+ index = i;
171
+ break;
172
+ }
173
+ if (index >= 0) {
174
+ for (let i = index; i < dataValues.length; i++) {
175
+ if (dataValues[i].sourceTimestamp.getTime() >= startTime.getTime() + processingInterval) {
176
+ break;
177
+ }
178
+ count++;
179
+ }
180
+ }
181
+ // check if interval is complete or partial (end or start)
182
+ let isPartial = false;
183
+ if (index + count >= dataValues.length &&
184
+ dataValues[dataValues.length - 1].sourceTimestamp.getTime() < startTime.getTime() + processingInterval) {
185
+ isPartial = true;
186
+ }
187
+ if (index <= 0 && dataValues[0].sourceTimestamp.getTime() > startTime.getTime()) {
188
+ isPartial = true;
189
+ }
190
+ return new Interval({
191
+ count,
192
+ dataValues,
193
+ index,
194
+ isPartial,
195
+ startTime,
196
+ processingInterval
197
+ });
198
+ }
199
+ exports.getInterval = getInterval;
200
200
  //# sourceMappingURL=interval.js.map
package/dist/minmax.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- /**
2
- * @module node-opca-aggregates
3
- */
4
- import { UAVariable } from "node-opcua-address-space";
5
- import { DataValue } from "node-opcua-data-value";
6
- import { AggregateConfigurationOptions, Interval } from "./interval";
7
- export declare function calculateIntervalMinValue(interval: Interval, options: AggregateConfigurationOptions): DataValue;
8
- export declare function calculateIntervalMaxValue(interval: Interval, options: AggregateConfigurationOptions): DataValue;
9
- /**
10
- *
11
- * @param node
12
- * @param processingInterval
13
- * @param startDate
14
- * @param endDate
15
- * @param callback
16
- */
17
- export declare function getMinData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
18
- export declare function getMaxData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
1
+ /**
2
+ * @module node-opca-aggregates
3
+ */
4
+ import { UAVariable } from "node-opcua-address-space";
5
+ import { DataValue } from "node-opcua-data-value";
6
+ import { AggregateConfigurationOptions, Interval } from "./interval";
7
+ export declare function calculateIntervalMinValue(interval: Interval, options: AggregateConfigurationOptions): DataValue;
8
+ export declare function calculateIntervalMaxValue(interval: Interval, options: AggregateConfigurationOptions): DataValue;
9
+ /**
10
+ *
11
+ * @param node
12
+ * @param processingInterval
13
+ * @param startDate
14
+ * @param endDate
15
+ * @param callback
16
+ */
17
+ export declare function getMinData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
18
+ export declare function getMaxData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;