node-opcua-aggregates 2.71.0 → 2.72.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/dist/aggregates.d.ts +7 -7
- package/dist/aggregates.js +200 -200
- package/dist/average.d.ts +3 -3
- package/dist/average.js +61 -61
- package/dist/common.d.ts +8 -8
- package/dist/common.js +99 -99
- package/dist/index.d.ts +11 -11
- package/dist/index.js +32 -32
- package/dist/interpolate.d.ts +16 -16
- package/dist/interpolate.js +130 -130
- package/dist/interval.d.ts +49 -49
- package/dist/interval.js +164 -164
- package/dist/minmax.d.ts +18 -18
- package/dist/minmax.js +149 -149
- package/dist/read_processed_details.d.ts +6 -6
- package/dist/read_processed_details.js +118 -118
- package/package.json +9 -9
- package/LICENSE +0 -20
package/dist/minmax.js
CHANGED
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMaxData = exports.getMinData = exports.calculateIntervalMaxValue = exports.calculateIntervalMinValue = void 0;
|
|
4
|
-
const node_opcua_data_value_1 = require("node-opcua-data-value");
|
|
5
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
6
|
-
const common_1 = require("./common");
|
|
7
|
-
const interval_1 = require("./interval");
|
|
8
|
-
// eslint-disable-next-line max-statements
|
|
9
|
-
function calculateIntervalMinOrMaxValue(interval, options, predicate) {
|
|
10
|
-
// console.log(interval.toString());
|
|
11
|
-
const indexStart = interval.index;
|
|
12
|
-
let selectedValue = null;
|
|
13
|
-
let counter = 0;
|
|
14
|
-
let statusCode;
|
|
15
|
-
let isPartial = interval.isPartial;
|
|
16
|
-
let isRaw = false;
|
|
17
|
-
let hasBad = false;
|
|
18
|
-
for (let i = indexStart; i < indexStart + interval.count; i++) {
|
|
19
|
-
const dataValue = interval.dataValues[i];
|
|
20
|
-
if (dataValue.statusCode === node_opcua_status_code_1.StatusCodes.BadNoData) {
|
|
21
|
-
isPartial = true;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (!(0, interval_1.isGood)(dataValue.statusCode)) {
|
|
25
|
-
hasBad = true;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (!selectedValue) {
|
|
29
|
-
selectedValue = dataValue.value;
|
|
30
|
-
counter = 1;
|
|
31
|
-
if (i === indexStart && dataValue.sourceTimestamp.getTime() === interval.startTime.getTime()) {
|
|
32
|
-
isRaw = true;
|
|
33
|
-
}
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const compare = predicate(selectedValue, dataValue.value);
|
|
37
|
-
if (compare === "equal") {
|
|
38
|
-
counter = 1;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (compare === "select") {
|
|
42
|
-
selectedValue = dataValue.value;
|
|
43
|
-
counter = 1;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (!selectedValue) {
|
|
47
|
-
return new node_opcua_data_value_1.DataValue({
|
|
48
|
-
sourceTimestamp: interval.startTime,
|
|
49
|
-
statusCode: node_opcua_status_code_1.StatusCodes.BadNoData
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (isRaw) {
|
|
53
|
-
if (hasBad) {
|
|
54
|
-
statusCode = node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
statusCode = node_opcua_status_code_1.StatusCodes.Good;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if (hasBad) {
|
|
61
|
-
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, "HistorianCalculated");
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.Good, "HistorianCalculated");
|
|
65
|
-
}
|
|
66
|
-
if (counter > 1) {
|
|
67
|
-
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(statusCode, "HistorianMultiValue");
|
|
68
|
-
}
|
|
69
|
-
if (isPartial || interval.isPartial) {
|
|
70
|
-
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(statusCode, "HistorianPartial");
|
|
71
|
-
}
|
|
72
|
-
return new node_opcua_data_value_1.DataValue({
|
|
73
|
-
sourceTimestamp: interval.startTime,
|
|
74
|
-
statusCode: statusCode,
|
|
75
|
-
value: selectedValue
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function calculateIntervalMinValue(interval, options) {
|
|
79
|
-
return calculateIntervalMinOrMaxValue(interval, options, (a, b) => a.value > b.value ? "select" : a.value === b.value ? "equal" : "reject");
|
|
80
|
-
}
|
|
81
|
-
exports.calculateIntervalMinValue = calculateIntervalMinValue;
|
|
82
|
-
function calculateIntervalMaxValue(interval, options) {
|
|
83
|
-
return calculateIntervalMinOrMaxValue(interval, options, (a, b) => a.value < b.value ? "select" : a.value === b.value ? "equal" : "reject");
|
|
84
|
-
}
|
|
85
|
-
exports.calculateIntervalMaxValue = calculateIntervalMaxValue;
|
|
86
|
-
// From OPC Unified Architecture, Part 13 26 Release 1.04
|
|
87
|
-
// 5.4.3.11 Maximum
|
|
88
|
-
// The Maximum Aggregate defined in Table 22 retrieves the maximum Good raw value within
|
|
89
|
-
// the interval, and returns that value with the timestamp at the start of the interval. Note that if
|
|
90
|
-
// the same maximum exists at more than one timestamp the MultipleValues bit is set.
|
|
91
|
-
// Unless otherwise indicated, StatusCodes are Good, Calculated. If the minimum value is on
|
|
92
|
-
// the interval start time the status code will be Good, Raw. If only Bad quality values are
|
|
93
|
-
// available then the status is returned as Bad_NoData.
|
|
94
|
-
// The timestamp of the Aggregate will always be the start of the interval for every
|
|
95
|
-
//
|
|
96
|
-
// ProcessingInterval.
|
|
97
|
-
//
|
|
98
|
-
// Table 22 – Maximum Aggregate summary
|
|
99
|
-
// Maximum Aggregate Characteristics
|
|
100
|
-
//
|
|
101
|
-
// Type Calculated
|
|
102
|
-
// Data Type Same as Source
|
|
103
|
-
// Use Bounds None
|
|
104
|
-
// Timestamp StartTime
|
|
105
|
-
//
|
|
106
|
-
// Status Code Calculations
|
|
107
|
-
// Calculation Method Custom
|
|
108
|
-
// If no Bad values then the Status is Good. If Bad values exist then
|
|
109
|
-
// the Status is Uncertain_SubNormal. If an Uncertain value is greater
|
|
110
|
-
// than the maximum Good value the Status is Uncertain_SubNormal
|
|
111
|
-
//
|
|
112
|
-
// Partial Set Sometimes
|
|
113
|
-
// If an interval is not a complete interval
|
|
114
|
-
//
|
|
115
|
-
// Calculated Set Sometimes
|
|
116
|
-
// If the Maximum value is not on the startTime of the interval or if the
|
|
117
|
-
// Status was set to Uncertain_SubNormal because of non-Good
|
|
118
|
-
// values in the interval
|
|
119
|
-
//
|
|
120
|
-
// Interpolated Not Set
|
|
121
|
-
//
|
|
122
|
-
// Raw Set Sometimes
|
|
123
|
-
// If Maximum value is on the startTime of the interval
|
|
124
|
-
// Multi Value Set Sometimes
|
|
125
|
-
// If multiple Good values exist with the Maximum value
|
|
126
|
-
//
|
|
127
|
-
// Status Code Common Special Cases
|
|
128
|
-
// Before Start of Data Bad_NoData
|
|
129
|
-
// After End of Data Bad_NoData
|
|
130
|
-
// No Start Bound Not Applicable
|
|
131
|
-
// No End Bound Not Applicable
|
|
132
|
-
// Bound Bad Not Applicable
|
|
133
|
-
// Bound Uncertain Not Applicable
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
* @param node
|
|
137
|
-
* @param processingInterval
|
|
138
|
-
* @param startDate
|
|
139
|
-
* @param endDate
|
|
140
|
-
* @param callback
|
|
141
|
-
*/
|
|
142
|
-
function getMinData(node, processingInterval, startDate, endDate, callback) {
|
|
143
|
-
return (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalMinValue, callback);
|
|
144
|
-
}
|
|
145
|
-
exports.getMinData = getMinData;
|
|
146
|
-
function getMaxData(node, processingInterval, startDate, endDate, callback) {
|
|
147
|
-
return (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalMaxValue, callback);
|
|
148
|
-
}
|
|
149
|
-
exports.getMaxData = getMaxData;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaxData = exports.getMinData = exports.calculateIntervalMaxValue = exports.calculateIntervalMinValue = void 0;
|
|
4
|
+
const node_opcua_data_value_1 = require("node-opcua-data-value");
|
|
5
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
const interval_1 = require("./interval");
|
|
8
|
+
// eslint-disable-next-line max-statements
|
|
9
|
+
function calculateIntervalMinOrMaxValue(interval, options, predicate) {
|
|
10
|
+
// console.log(interval.toString());
|
|
11
|
+
const indexStart = interval.index;
|
|
12
|
+
let selectedValue = null;
|
|
13
|
+
let counter = 0;
|
|
14
|
+
let statusCode;
|
|
15
|
+
let isPartial = interval.isPartial;
|
|
16
|
+
let isRaw = false;
|
|
17
|
+
let hasBad = false;
|
|
18
|
+
for (let i = indexStart; i < indexStart + interval.count; i++) {
|
|
19
|
+
const dataValue = interval.dataValues[i];
|
|
20
|
+
if (dataValue.statusCode === node_opcua_status_code_1.StatusCodes.BadNoData) {
|
|
21
|
+
isPartial = true;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (!(0, interval_1.isGood)(dataValue.statusCode)) {
|
|
25
|
+
hasBad = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!selectedValue) {
|
|
29
|
+
selectedValue = dataValue.value;
|
|
30
|
+
counter = 1;
|
|
31
|
+
if (i === indexStart && dataValue.sourceTimestamp.getTime() === interval.startTime.getTime()) {
|
|
32
|
+
isRaw = true;
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const compare = predicate(selectedValue, dataValue.value);
|
|
37
|
+
if (compare === "equal") {
|
|
38
|
+
counter = 1;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (compare === "select") {
|
|
42
|
+
selectedValue = dataValue.value;
|
|
43
|
+
counter = 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!selectedValue) {
|
|
47
|
+
return new node_opcua_data_value_1.DataValue({
|
|
48
|
+
sourceTimestamp: interval.startTime,
|
|
49
|
+
statusCode: node_opcua_status_code_1.StatusCodes.BadNoData
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (isRaw) {
|
|
53
|
+
if (hasBad) {
|
|
54
|
+
statusCode = node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
statusCode = node_opcua_status_code_1.StatusCodes.Good;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (hasBad) {
|
|
61
|
+
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, "HistorianCalculated");
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.Good, "HistorianCalculated");
|
|
65
|
+
}
|
|
66
|
+
if (counter > 1) {
|
|
67
|
+
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(statusCode, "HistorianMultiValue");
|
|
68
|
+
}
|
|
69
|
+
if (isPartial || interval.isPartial) {
|
|
70
|
+
statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(statusCode, "HistorianPartial");
|
|
71
|
+
}
|
|
72
|
+
return new node_opcua_data_value_1.DataValue({
|
|
73
|
+
sourceTimestamp: interval.startTime,
|
|
74
|
+
statusCode: statusCode,
|
|
75
|
+
value: selectedValue
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function calculateIntervalMinValue(interval, options) {
|
|
79
|
+
return calculateIntervalMinOrMaxValue(interval, options, (a, b) => a.value > b.value ? "select" : a.value === b.value ? "equal" : "reject");
|
|
80
|
+
}
|
|
81
|
+
exports.calculateIntervalMinValue = calculateIntervalMinValue;
|
|
82
|
+
function calculateIntervalMaxValue(interval, options) {
|
|
83
|
+
return calculateIntervalMinOrMaxValue(interval, options, (a, b) => a.value < b.value ? "select" : a.value === b.value ? "equal" : "reject");
|
|
84
|
+
}
|
|
85
|
+
exports.calculateIntervalMaxValue = calculateIntervalMaxValue;
|
|
86
|
+
// From OPC Unified Architecture, Part 13 26 Release 1.04
|
|
87
|
+
// 5.4.3.11 Maximum
|
|
88
|
+
// The Maximum Aggregate defined in Table 22 retrieves the maximum Good raw value within
|
|
89
|
+
// the interval, and returns that value with the timestamp at the start of the interval. Note that if
|
|
90
|
+
// the same maximum exists at more than one timestamp the MultipleValues bit is set.
|
|
91
|
+
// Unless otherwise indicated, StatusCodes are Good, Calculated. If the minimum value is on
|
|
92
|
+
// the interval start time the status code will be Good, Raw. If only Bad quality values are
|
|
93
|
+
// available then the status is returned as Bad_NoData.
|
|
94
|
+
// The timestamp of the Aggregate will always be the start of the interval for every
|
|
95
|
+
//
|
|
96
|
+
// ProcessingInterval.
|
|
97
|
+
//
|
|
98
|
+
// Table 22 – Maximum Aggregate summary
|
|
99
|
+
// Maximum Aggregate Characteristics
|
|
100
|
+
//
|
|
101
|
+
// Type Calculated
|
|
102
|
+
// Data Type Same as Source
|
|
103
|
+
// Use Bounds None
|
|
104
|
+
// Timestamp StartTime
|
|
105
|
+
//
|
|
106
|
+
// Status Code Calculations
|
|
107
|
+
// Calculation Method Custom
|
|
108
|
+
// If no Bad values then the Status is Good. If Bad values exist then
|
|
109
|
+
// the Status is Uncertain_SubNormal. If an Uncertain value is greater
|
|
110
|
+
// than the maximum Good value the Status is Uncertain_SubNormal
|
|
111
|
+
//
|
|
112
|
+
// Partial Set Sometimes
|
|
113
|
+
// If an interval is not a complete interval
|
|
114
|
+
//
|
|
115
|
+
// Calculated Set Sometimes
|
|
116
|
+
// If the Maximum value is not on the startTime of the interval or if the
|
|
117
|
+
// Status was set to Uncertain_SubNormal because of non-Good
|
|
118
|
+
// values in the interval
|
|
119
|
+
//
|
|
120
|
+
// Interpolated Not Set
|
|
121
|
+
//
|
|
122
|
+
// Raw Set Sometimes
|
|
123
|
+
// If Maximum value is on the startTime of the interval
|
|
124
|
+
// Multi Value Set Sometimes
|
|
125
|
+
// If multiple Good values exist with the Maximum value
|
|
126
|
+
//
|
|
127
|
+
// Status Code Common Special Cases
|
|
128
|
+
// Before Start of Data Bad_NoData
|
|
129
|
+
// After End of Data Bad_NoData
|
|
130
|
+
// No Start Bound Not Applicable
|
|
131
|
+
// No End Bound Not Applicable
|
|
132
|
+
// Bound Bad Not Applicable
|
|
133
|
+
// Bound Uncertain Not Applicable
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* @param node
|
|
137
|
+
* @param processingInterval
|
|
138
|
+
* @param startDate
|
|
139
|
+
* @param endDate
|
|
140
|
+
* @param callback
|
|
141
|
+
*/
|
|
142
|
+
function getMinData(node, processingInterval, startDate, endDate, callback) {
|
|
143
|
+
return (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalMinValue, callback);
|
|
144
|
+
}
|
|
145
|
+
exports.getMinData = getMinData;
|
|
146
|
+
function getMaxData(node, processingInterval, startDate, endDate, callback) {
|
|
147
|
+
return (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalMaxValue, callback);
|
|
148
|
+
}
|
|
149
|
+
exports.getMaxData = getMaxData;
|
|
150
150
|
//# sourceMappingURL=minmax.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ISessionContext, UAVariable, ContinuationData } from "node-opcua-address-space";
|
|
2
|
-
import { NumericRange } from "node-opcua-numeric-range";
|
|
3
|
-
import { QualifiedNameLike } from "node-opcua-data-model";
|
|
4
|
-
import { CallbackT } from "node-opcua-status-code";
|
|
5
|
-
import { HistoryReadResult, ReadProcessedDetails } from "node-opcua-service-history";
|
|
6
|
-
export declare function readProcessedDetails(variable: UAVariable, context: ISessionContext, historyReadDetails: ReadProcessedDetails, indexRange: NumericRange | null, dataEncoding: QualifiedNameLike | null, continuationData: ContinuationData, callback: CallbackT<HistoryReadResult>): void;
|
|
1
|
+
import { ISessionContext, UAVariable, ContinuationData } from "node-opcua-address-space";
|
|
2
|
+
import { NumericRange } from "node-opcua-numeric-range";
|
|
3
|
+
import { QualifiedNameLike } from "node-opcua-data-model";
|
|
4
|
+
import { CallbackT } from "node-opcua-status-code";
|
|
5
|
+
import { HistoryReadResult, ReadProcessedDetails } from "node-opcua-service-history";
|
|
6
|
+
export declare function readProcessedDetails(variable: UAVariable, context: ISessionContext, historyReadDetails: ReadProcessedDetails, indexRange: NumericRange | null, dataEncoding: QualifiedNameLike | null, continuationData: ContinuationData, callback: CallbackT<HistoryReadResult>): void;
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readProcessedDetails = void 0;
|
|
4
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
5
|
-
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
6
|
-
const node_opcua_service_history_1 = require("node-opcua-service-history");
|
|
7
|
-
const minmax_1 = require("./minmax");
|
|
8
|
-
const interpolate_1 = require("./interpolate");
|
|
9
|
-
const average_1 = require("./average");
|
|
10
|
-
function _buildResult(err, dataValues, callback2) {
|
|
11
|
-
if (err) {
|
|
12
|
-
return callback2(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError }));
|
|
13
|
-
}
|
|
14
|
-
const result = new node_opcua_service_history_1.HistoryReadResult({
|
|
15
|
-
historyData: new node_opcua_service_history_1.HistoryData({
|
|
16
|
-
dataValues
|
|
17
|
-
}),
|
|
18
|
-
statusCode: node_opcua_status_code_1.StatusCodes.Good
|
|
19
|
-
});
|
|
20
|
-
return callback2(null, result);
|
|
21
|
-
}
|
|
22
|
-
function applyAggregate(variable, processingInterval, startTime, endTime, aggregateType, callback2) {
|
|
23
|
-
if (!startTime || !endTime) {
|
|
24
|
-
return _buildResult(new Error("Invalid date time"), undefined, callback2);
|
|
25
|
-
}
|
|
26
|
-
const buildResult = (err, dataValues) => {
|
|
27
|
-
_buildResult(err, dataValues, callback2);
|
|
28
|
-
};
|
|
29
|
-
switch (aggregateType.value) {
|
|
30
|
-
case node_opcua_constants_1.AggregateFunction.Minimum:
|
|
31
|
-
(0, minmax_1.getMinData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
32
|
-
break;
|
|
33
|
-
case node_opcua_constants_1.AggregateFunction.Maximum:
|
|
34
|
-
(0, minmax_1.getMaxData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
35
|
-
break;
|
|
36
|
-
case node_opcua_constants_1.AggregateFunction.Interpolative:
|
|
37
|
-
(0, interpolate_1.getInterpolatedData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
38
|
-
break;
|
|
39
|
-
case node_opcua_constants_1.AggregateFunction.Average:
|
|
40
|
-
(0, average_1.getAverageData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
41
|
-
break;
|
|
42
|
-
case node_opcua_constants_1.AggregateFunction.Count:
|
|
43
|
-
default:
|
|
44
|
-
// todo provide correct implementation
|
|
45
|
-
return callback2(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadAggregateNotSupported }));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function readProcessedDetails(variable, context, historyReadDetails, indexRange, dataEncoding, continuationData, callback) {
|
|
49
|
-
var _a;
|
|
50
|
-
// OPC Unified Architecture, Part 11 27 Release 1.03
|
|
51
|
-
//
|
|
52
|
-
// This structure is used to compute Aggregate values, qualities, and timestamps from data in
|
|
53
|
-
// the history database for the specified time domain for one or more HistoricalDataNodes. The
|
|
54
|
-
// time domain is divided into intervals of duration ProcessingInterval. The specified Aggregate
|
|
55
|
-
// Type is calculated for each interval beginning with startTime by using the data within the next
|
|
56
|
-
// ProcessingInterval.
|
|
57
|
-
// For example, this function can provide hourly statistics such as Maximum, Minimum , and
|
|
58
|
-
// Average for each item during the specified time domain when ProcessingInterval is 1 hour.
|
|
59
|
-
// The domain of the request is defined by startTime, endTime, and ProcessingInterval. All three
|
|
60
|
-
// shall be specified. If endTime is less than startTime then the data shall be returned in reverse
|
|
61
|
-
// order with the later data coming first. If startTime and endTime are the same then the Server
|
|
62
|
-
// shall return Bad_InvalidArgument as there is no meaningful way to interpret such a case. If
|
|
63
|
-
// the ProcessingInterval is specified as 0 then Aggregates shall be calculated using one interval
|
|
64
|
-
// starting at startTime and ending at endTime.
|
|
65
|
-
// The aggregateType[] parameter allows a Client to request multiple Aggregate calculations per
|
|
66
|
-
// requested NodeId. If multiple Aggregates are requested then a corresponding number of
|
|
67
|
-
// entries are required in the NodesToRead array.
|
|
68
|
-
// For example, to request Min Aggregate for NodeId FIC101, FIC102, and both Min and Max
|
|
69
|
-
// Aggregates for NodeId FIC103 would require NodeId FIC103 to appear twice in the
|
|
70
|
-
// NodesToRead array request parameter.
|
|
71
|
-
// aggregateType[] NodesToRead[]
|
|
72
|
-
// Min FIC101
|
|
73
|
-
// Min FIC102
|
|
74
|
-
// Min FIC103
|
|
75
|
-
// Max FIC103
|
|
76
|
-
// If the array of Aggregates does not match the array of NodesToRead then the Server shall
|
|
77
|
-
// return a StatusCode of Bad_AggregateListMismatch.
|
|
78
|
-
// The aggregateConfiguration parameter allows a Client to override the Aggregate configuration
|
|
79
|
-
// settings supplied by the AggregateConfiguration Object on a per call basis. See Part 13 for
|
|
80
|
-
// more information on Aggregate configurations. If the Server does not support the ability to
|
|
81
|
-
// override the Aggregate configuration settings then it shall return a StatusCode of Bad_
|
|
82
|
-
// AggregateConfigurationRejected. If the Aggregate is not valid for the Node then the
|
|
83
|
-
// StatusCode shall be Bad_AggregateNotSupported.
|
|
84
|
-
// The values used in computing the Aggregate for each interval shall include any value that
|
|
85
|
-
// falls exactly on the timestamp at the beginning of the interval, but shall not include any value
|
|
86
|
-
// that falls directly on the timestamp ending the interval. Thus, each value shall be included
|
|
87
|
-
// only once in the calculation. If the time domain is in reverse order then we consider the later
|
|
88
|
-
// timestamp to be the one beginning the sub interval, and the earlier timestamp to be the one
|
|
89
|
-
// ending it. Note that this means that simply swapping the start and end times will not result in
|
|
90
|
-
// getting the same values back in reverse order as the intervals being requested in the two
|
|
91
|
-
// cases are not the same.
|
|
92
|
-
// If an Aggregate is taking a long time to calculate then the Server can return partial results
|
|
93
|
-
// with a continuation point. This might be done if the calculation is going to take more time th an
|
|
94
|
-
// the Client timeout hint. In some cases it may take longer than the Client timeout hint to
|
|
95
|
-
// calculate even one Aggregate result. Then the Server may return zero results with a
|
|
96
|
-
// continuation point that allows the Server to resume the calculation on the next Client read
|
|
97
|
-
// call.
|
|
98
|
-
const startTime = historyReadDetails.startTime;
|
|
99
|
-
const endTime = historyReadDetails.endTime;
|
|
100
|
-
if (!startTime || !endTime) {
|
|
101
|
-
return callback(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument }));
|
|
102
|
-
}
|
|
103
|
-
if (startTime.getTime() === endTime.getTime()) {
|
|
104
|
-
// Start = End Int = Anything No intervals. Returns a Bad_InvalidArgument StatusCode,
|
|
105
|
-
// regardless of whether there is data at the specified time or not
|
|
106
|
-
return callback(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument }));
|
|
107
|
-
}
|
|
108
|
-
const aggregateTypes = historyReadDetails.aggregateType || [];
|
|
109
|
-
// If the ProcessingInterval is specified as 0 then Aggregates shall be calculated using one interval
|
|
110
|
-
// starting at startTime and ending at endTime.
|
|
111
|
-
const processingInterval = historyReadDetails.processingInterval || endTime.getTime() - startTime.getTime();
|
|
112
|
-
// tslint:disable-next-line: prefer-for-of
|
|
113
|
-
if (((_a = historyReadDetails.aggregateType) === null || _a === void 0 ? void 0 : _a.length) !== 1) {
|
|
114
|
-
return callback(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError }));
|
|
115
|
-
}
|
|
116
|
-
return applyAggregate(variable, processingInterval, startTime, endTime, aggregateTypes[0], callback);
|
|
117
|
-
}
|
|
118
|
-
exports.readProcessedDetails = readProcessedDetails;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readProcessedDetails = void 0;
|
|
4
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
5
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
6
|
+
const node_opcua_service_history_1 = require("node-opcua-service-history");
|
|
7
|
+
const minmax_1 = require("./minmax");
|
|
8
|
+
const interpolate_1 = require("./interpolate");
|
|
9
|
+
const average_1 = require("./average");
|
|
10
|
+
function _buildResult(err, dataValues, callback2) {
|
|
11
|
+
if (err) {
|
|
12
|
+
return callback2(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError }));
|
|
13
|
+
}
|
|
14
|
+
const result = new node_opcua_service_history_1.HistoryReadResult({
|
|
15
|
+
historyData: new node_opcua_service_history_1.HistoryData({
|
|
16
|
+
dataValues
|
|
17
|
+
}),
|
|
18
|
+
statusCode: node_opcua_status_code_1.StatusCodes.Good
|
|
19
|
+
});
|
|
20
|
+
return callback2(null, result);
|
|
21
|
+
}
|
|
22
|
+
function applyAggregate(variable, processingInterval, startTime, endTime, aggregateType, callback2) {
|
|
23
|
+
if (!startTime || !endTime) {
|
|
24
|
+
return _buildResult(new Error("Invalid date time"), undefined, callback2);
|
|
25
|
+
}
|
|
26
|
+
const buildResult = (err, dataValues) => {
|
|
27
|
+
_buildResult(err, dataValues, callback2);
|
|
28
|
+
};
|
|
29
|
+
switch (aggregateType.value) {
|
|
30
|
+
case node_opcua_constants_1.AggregateFunction.Minimum:
|
|
31
|
+
(0, minmax_1.getMinData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
32
|
+
break;
|
|
33
|
+
case node_opcua_constants_1.AggregateFunction.Maximum:
|
|
34
|
+
(0, minmax_1.getMaxData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
35
|
+
break;
|
|
36
|
+
case node_opcua_constants_1.AggregateFunction.Interpolative:
|
|
37
|
+
(0, interpolate_1.getInterpolatedData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
38
|
+
break;
|
|
39
|
+
case node_opcua_constants_1.AggregateFunction.Average:
|
|
40
|
+
(0, average_1.getAverageData)(variable, processingInterval, startTime, endTime, buildResult);
|
|
41
|
+
break;
|
|
42
|
+
case node_opcua_constants_1.AggregateFunction.Count:
|
|
43
|
+
default:
|
|
44
|
+
// todo provide correct implementation
|
|
45
|
+
return callback2(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadAggregateNotSupported }));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function readProcessedDetails(variable, context, historyReadDetails, indexRange, dataEncoding, continuationData, callback) {
|
|
49
|
+
var _a;
|
|
50
|
+
// OPC Unified Architecture, Part 11 27 Release 1.03
|
|
51
|
+
//
|
|
52
|
+
// This structure is used to compute Aggregate values, qualities, and timestamps from data in
|
|
53
|
+
// the history database for the specified time domain for one or more HistoricalDataNodes. The
|
|
54
|
+
// time domain is divided into intervals of duration ProcessingInterval. The specified Aggregate
|
|
55
|
+
// Type is calculated for each interval beginning with startTime by using the data within the next
|
|
56
|
+
// ProcessingInterval.
|
|
57
|
+
// For example, this function can provide hourly statistics such as Maximum, Minimum , and
|
|
58
|
+
// Average for each item during the specified time domain when ProcessingInterval is 1 hour.
|
|
59
|
+
// The domain of the request is defined by startTime, endTime, and ProcessingInterval. All three
|
|
60
|
+
// shall be specified. If endTime is less than startTime then the data shall be returned in reverse
|
|
61
|
+
// order with the later data coming first. If startTime and endTime are the same then the Server
|
|
62
|
+
// shall return Bad_InvalidArgument as there is no meaningful way to interpret such a case. If
|
|
63
|
+
// the ProcessingInterval is specified as 0 then Aggregates shall be calculated using one interval
|
|
64
|
+
// starting at startTime and ending at endTime.
|
|
65
|
+
// The aggregateType[] parameter allows a Client to request multiple Aggregate calculations per
|
|
66
|
+
// requested NodeId. If multiple Aggregates are requested then a corresponding number of
|
|
67
|
+
// entries are required in the NodesToRead array.
|
|
68
|
+
// For example, to request Min Aggregate for NodeId FIC101, FIC102, and both Min and Max
|
|
69
|
+
// Aggregates for NodeId FIC103 would require NodeId FIC103 to appear twice in the
|
|
70
|
+
// NodesToRead array request parameter.
|
|
71
|
+
// aggregateType[] NodesToRead[]
|
|
72
|
+
// Min FIC101
|
|
73
|
+
// Min FIC102
|
|
74
|
+
// Min FIC103
|
|
75
|
+
// Max FIC103
|
|
76
|
+
// If the array of Aggregates does not match the array of NodesToRead then the Server shall
|
|
77
|
+
// return a StatusCode of Bad_AggregateListMismatch.
|
|
78
|
+
// The aggregateConfiguration parameter allows a Client to override the Aggregate configuration
|
|
79
|
+
// settings supplied by the AggregateConfiguration Object on a per call basis. See Part 13 for
|
|
80
|
+
// more information on Aggregate configurations. If the Server does not support the ability to
|
|
81
|
+
// override the Aggregate configuration settings then it shall return a StatusCode of Bad_
|
|
82
|
+
// AggregateConfigurationRejected. If the Aggregate is not valid for the Node then the
|
|
83
|
+
// StatusCode shall be Bad_AggregateNotSupported.
|
|
84
|
+
// The values used in computing the Aggregate for each interval shall include any value that
|
|
85
|
+
// falls exactly on the timestamp at the beginning of the interval, but shall not include any value
|
|
86
|
+
// that falls directly on the timestamp ending the interval. Thus, each value shall be included
|
|
87
|
+
// only once in the calculation. If the time domain is in reverse order then we consider the later
|
|
88
|
+
// timestamp to be the one beginning the sub interval, and the earlier timestamp to be the one
|
|
89
|
+
// ending it. Note that this means that simply swapping the start and end times will not result in
|
|
90
|
+
// getting the same values back in reverse order as the intervals being requested in the two
|
|
91
|
+
// cases are not the same.
|
|
92
|
+
// If an Aggregate is taking a long time to calculate then the Server can return partial results
|
|
93
|
+
// with a continuation point. This might be done if the calculation is going to take more time th an
|
|
94
|
+
// the Client timeout hint. In some cases it may take longer than the Client timeout hint to
|
|
95
|
+
// calculate even one Aggregate result. Then the Server may return zero results with a
|
|
96
|
+
// continuation point that allows the Server to resume the calculation on the next Client read
|
|
97
|
+
// call.
|
|
98
|
+
const startTime = historyReadDetails.startTime;
|
|
99
|
+
const endTime = historyReadDetails.endTime;
|
|
100
|
+
if (!startTime || !endTime) {
|
|
101
|
+
return callback(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument }));
|
|
102
|
+
}
|
|
103
|
+
if (startTime.getTime() === endTime.getTime()) {
|
|
104
|
+
// Start = End Int = Anything No intervals. Returns a Bad_InvalidArgument StatusCode,
|
|
105
|
+
// regardless of whether there is data at the specified time or not
|
|
106
|
+
return callback(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInvalidArgument }));
|
|
107
|
+
}
|
|
108
|
+
const aggregateTypes = historyReadDetails.aggregateType || [];
|
|
109
|
+
// If the ProcessingInterval is specified as 0 then Aggregates shall be calculated using one interval
|
|
110
|
+
// starting at startTime and ending at endTime.
|
|
111
|
+
const processingInterval = historyReadDetails.processingInterval || endTime.getTime() - startTime.getTime();
|
|
112
|
+
// tslint:disable-next-line: prefer-for-of
|
|
113
|
+
if (((_a = historyReadDetails.aggregateType) === null || _a === void 0 ? void 0 : _a.length) !== 1) {
|
|
114
|
+
return callback(null, new node_opcua_service_history_1.HistoryReadResult({ statusCode: node_opcua_status_code_1.StatusCodes.BadInternalError }));
|
|
115
|
+
}
|
|
116
|
+
return applyAggregate(variable, processingInterval, startTime, endTime, aggregateTypes[0], callback);
|
|
117
|
+
}
|
|
118
|
+
exports.readProcessedDetails = readProcessedDetails;
|
|
119
119
|
//# sourceMappingURL=read_processed_details.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-aggregates",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.72.2",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -end2end-test",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -13,18 +13,18 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@types/async": "^3.2.13",
|
|
16
|
-
"node-opcua-address-space": "2.
|
|
16
|
+
"node-opcua-address-space": "2.72.2",
|
|
17
17
|
"node-opcua-constants": "2.70.0",
|
|
18
|
-
"node-opcua-data-model": "2.
|
|
19
|
-
"node-opcua-data-value": "2.
|
|
18
|
+
"node-opcua-data-model": "2.72.1",
|
|
19
|
+
"node-opcua-data-value": "2.72.2",
|
|
20
20
|
"node-opcua-nodeid": "2.71.0",
|
|
21
21
|
"node-opcua-nodesets": "2.71.0",
|
|
22
|
-
"node-opcua-numeric-range": "2.
|
|
23
|
-
"node-opcua-service-history": "2.
|
|
22
|
+
"node-opcua-numeric-range": "2.72.2",
|
|
23
|
+
"node-opcua-service-history": "2.72.2",
|
|
24
24
|
"node-opcua-status-code": "2.71.0",
|
|
25
|
-
"node-opcua-types": "2.
|
|
25
|
+
"node-opcua-types": "2.72.2",
|
|
26
26
|
"node-opcua-utils": "2.71.0",
|
|
27
|
-
"node-opcua-variant": "2.
|
|
27
|
+
"node-opcua-variant": "2.72.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"delayed": "^2.0.0",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"internet of things"
|
|
50
50
|
],
|
|
51
51
|
"homepage": "http://node-opcua.github.io/",
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "07dcdd8e8c7f2b55544c6e23023093e35674829c"
|
|
53
53
|
}
|
package/LICENSE
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014-2021 Etienne Rossignon
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|