node-opcua-aggregates 2.73.1 → 2.76.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.
package/LICENSE CHANGED
@@ -1,6 +1,8 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2021 Etienne Rossignon
3
+ Copyright (c) 2022 Sterfive SAS - 833264583 RCS ORLEANS - France (https://www.sterfive.com)
4
+
5
+ Copyright (c) 2014-2022 Etienne Rossignon
4
6
 
5
7
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
8
  this software and associated documentation files (the "Software"), to deal in
@@ -1,7 +1,7 @@
1
- import { AddressSpace, BaseNode, UAObject, UAServerCapabilities, UAVariable } from "node-opcua-address-space";
2
- import { AggregateConfigurationOptionsEx } from "./interval";
3
- export declare function createHistoryServerCapabilities(addressSpace: AddressSpace, serverCapabilities: UAServerCapabilities): UAObject;
4
- export declare type AggregateFunctionName = "AnnotationCount" | "Average" | "Count" | "Delta" | "DeltaBounds" | "DurationBad" | "DurationGood" | "DurationInStateNonZero" | "DurationInStateZero" | "EndBound" | "Interpolative" | "Maximum" | "Maximum2" | "MaximumActualTime" | "MaximumActualTime2" | "Minimum" | "Minimum2" | "MinimumActualTime" | "MinimumActualTime2" | "NumberOfTransitions" | "PercentBad" | "PercentGood" | "Range" | "Range2" | "StandardDeviationPopulation" | "StandardDeviationSample" | "Start" | "StartBound" | "TimeAverage" | "TimeAverage2" | "Total" | "Total2" | "VariancePopulation" | "VarianceSample" | "WorstQuality" | "WorstQuality2";
5
- export declare function addAggregateSupport(addressSpace: AddressSpace): void;
6
- export declare function installAggregateConfigurationOptions(node: UAVariable, options: AggregateConfigurationOptionsEx): void;
7
- export declare function getAggregateConfiguration(node: BaseNode): AggregateConfigurationOptionsEx;
1
+ import { AddressSpace, BaseNode, UAObject, UAServerCapabilities, UAVariable } from "node-opcua-address-space";
2
+ import { AggregateConfigurationOptionsEx } from "./interval";
3
+ export declare function createHistoryServerCapabilities(addressSpace: AddressSpace, serverCapabilities: UAServerCapabilities): UAObject;
4
+ export declare type AggregateFunctionName = "AnnotationCount" | "Average" | "Count" | "Delta" | "DeltaBounds" | "DurationBad" | "DurationGood" | "DurationInStateNonZero" | "DurationInStateZero" | "EndBound" | "Interpolative" | "Maximum" | "Maximum2" | "MaximumActualTime" | "MaximumActualTime2" | "Minimum" | "Minimum2" | "MinimumActualTime" | "MinimumActualTime2" | "NumberOfTransitions" | "PercentBad" | "PercentGood" | "Range" | "Range2" | "StandardDeviationPopulation" | "StandardDeviationSample" | "Start" | "StartBound" | "TimeAverage" | "TimeAverage2" | "Total" | "Total2" | "VariancePopulation" | "VarianceSample" | "WorstQuality" | "WorstQuality2";
5
+ export declare function addAggregateSupport(addressSpace: AddressSpace): void;
6
+ export declare function installAggregateConfigurationOptions(node: UAVariable, options: AggregateConfigurationOptionsEx): void;
7
+ export declare function getAggregateConfiguration(node: BaseNode): AggregateConfigurationOptionsEx;
@@ -1,201 +1,201 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAggregateConfiguration = exports.installAggregateConfigurationOptions = exports.addAggregateSupport = exports.createHistoryServerCapabilities = void 0;
4
- /**
5
- * @module node-opcua-aggregates
6
- */
7
- const node_opcua_constants_1 = require("node-opcua-constants");
8
- const node_opcua_nodeid_1 = require("node-opcua-nodeid");
9
- const utils = require("node-opcua-utils");
10
- const node_opcua_variant_1 = require("node-opcua-variant");
11
- const read_processed_details_1 = require("./read_processed_details");
12
- // import { HistoryServerCapabilities } from "node-opcua-server";
13
- /*
14
- HasProperty Variable AccessHistoryDataCapability Boolean PropertyType Mandatory
15
- HasProperty Variable AccessHistoryEventsCapability Boolean PropertyType Mandatory
16
- HasProperty Variable MaxReturnDataValues UInt32 PropertyType Mandatory
17
- HasProperty Variable MaxReturnEventValues UInt32 PropertyType Mandatory
18
- HasProperty Variable InsertDataCapability Boolean PropertyType Mandatory
19
- HasProperty Variable ReplaceDataCapability Boolean PropertyType Mandatory
20
- HasProperty Variable UpdateDataCapability Boolean PropertyType Mandatory
21
- HasProperty Variable DeleteRawCapability Boolean PropertyType Mandatory
22
- HasProperty Variable DeleteAtTimeCapability Boolean PropertyType Mandatory
23
- HasProperty Variable InsertEventCapability Boolean PropertyType Mandatory
24
- HasProperty Variable ReplaceEventCapability Boolean PropertyType Mandatory
25
- HasProperty Variable UpdateEventCapability Boolean PropertyType Mandatory
26
- HasProperty Variable DeleteEventCapability Boolean PropertyType Mandatory
27
- HasProperty Variable InsertAnnotationsCapability Boolean PropertyType Mandatory
28
- */
29
- const historicalCapabilitiesDefaultProperties /*: HistoryServerCapabilities */ = {
30
- accessHistoryDataCapability: true,
31
- accessHistoryEventsCapability: true,
32
- deleteAtTimeCapability: false,
33
- deleteEventCapability: false,
34
- deleteRawCapability: false,
35
- insertAnnotationCapability: false,
36
- insertDataCapability: false,
37
- insertEventCapability: false,
38
- maxReturnDataValues: 0,
39
- maxReturnEventValues: 0,
40
- replaceDataCapability: false,
41
- replaceEventCapability: false,
42
- updateDataCapability: false,
43
- updateEventCapability: false // Boolean PropertyType Mandatory
44
- };
45
- function createHistoryServerCapabilities(addressSpace, serverCapabilities) {
46
- /* istanbul ignore next */
47
- if (serverCapabilities.browseName.toString() !== "ServerCapabilities") {
48
- throw new Error("Expecting server Capabilities");
49
- }
50
- const historyServerCapabilitiesType = addressSpace.getNamespace(0).findObjectType("HistoryServerCapabilitiesType");
51
- /* istanbul ignore next */
52
- if (!historyServerCapabilitiesType) {
53
- throw new Error("Cannot find HistoryServerCapabilitiesType");
54
- }
55
- return historyServerCapabilitiesType.instantiate({
56
- browseName: "HistoryServerCapabilities",
57
- componentOf: serverCapabilities
58
- });
59
- }
60
- exports.createHistoryServerCapabilities = createHistoryServerCapabilities;
61
- function setHistoricalServerCapabilities(historyServerCapabilities, defaultProperties) {
62
- function setBoolean(propName) {
63
- const lowerCase = utils.lowerFirstLetter(propName);
64
- /* istanbul ignore next */
65
- if (!Object.prototype.hasOwnProperty.call(defaultProperties, lowerCase)) {
66
- throw new Error("cannot find " + lowerCase);
67
- }
68
- const value = defaultProperties[lowerCase];
69
- const prop = historyServerCapabilities.getChildByName(propName);
70
- /* istanbul ignore next */
71
- if (!prop) {
72
- throw new Error(" Cannot find property " + propName);
73
- }
74
- prop.setValueFromSource({ dataType: node_opcua_variant_1.DataType.Boolean, value });
75
- }
76
- function setUInt32(propName) {
77
- const lowerCase = utils.lowerFirstLetter(propName);
78
- /* istanbul ignore next */
79
- if (!Object.prototype.hasOwnProperty.call(historyServerCapabilities, lowerCase)) {
80
- throw new Error("cannot find " + lowerCase);
81
- }
82
- const value = defaultProperties[lowerCase];
83
- const prop = historyServerCapabilities.getChildByName(propName);
84
- prop.setValueFromSource({ dataType: node_opcua_variant_1.DataType.UInt32, value });
85
- }
86
- setBoolean("AccessHistoryDataCapability");
87
- setBoolean("AccessHistoryEventsCapability");
88
- setUInt32("MaxReturnDataValues");
89
- setUInt32("MaxReturnEventValues");
90
- setBoolean("InsertDataCapability");
91
- setBoolean("ReplaceDataCapability");
92
- setBoolean("UpdateDataCapability");
93
- setBoolean("DeleteRawCapability");
94
- setBoolean("DeleteAtTimeCapability");
95
- setBoolean("InsertEventCapability");
96
- setBoolean("ReplaceEventCapability");
97
- setBoolean("UpdateEventCapability");
98
- setBoolean("DeleteEventCapability");
99
- /// FOUND A BUG HERE spec says InsertAnnotationsCapability
100
- /// Standard nodeset2 says InsertAnnotationCapability ( without s )
101
- // xx setBoolean("InsertAnnotationsCapability");
102
- }
103
- function addAggregateFunctionSupport(addressSpace, functionName) {
104
- /* istanbul ignore next */
105
- if (!functionName) {
106
- throw new Error("Invalid function name");
107
- }
108
- const serverCapabilities = addressSpace.rootFolder.objects.server.serverCapabilities;
109
- /* istanbul ignore next */
110
- if (!serverCapabilities.historyServerCapabilities) {
111
- throw new Error("missing serverCapabilities.historyServerCapabilities");
112
- }
113
- const aggregateFunctions = serverCapabilities.aggregateFunctions;
114
- const aggregateFunctionsInHist = serverCapabilities.historyServerCapabilities.aggregateFunctions;
115
- const functionNodeId = (0, node_opcua_nodeid_1.makeNodeId)(functionName);
116
- const functionNode = addressSpace.getNamespace(0).findNode(functionNodeId);
117
- /* istanbul ignore next */
118
- if (!functionNode) {
119
- throw new Error("Cannot find node " + functionName + " in addressSpace");
120
- }
121
- aggregateFunctions.addReference({
122
- nodeId: functionNode.nodeId,
123
- referenceType: "Organizes"
124
- });
125
- aggregateFunctionsInHist.addReference({
126
- nodeId: functionNode.nodeId,
127
- referenceType: "Organizes"
128
- });
129
- }
130
- function addAggregateSupport(addressSpace) {
131
- const aggregateConfigurationType = addressSpace.getNamespace(0).findObjectType("AggregateConfigurationType");
132
- /* istanbul ignore next */
133
- if (!aggregateConfigurationType) {
134
- throw new Error("addressSpace do not expose AggregateConfigurationType");
135
- }
136
- const aggregateFunctionType = addressSpace.getNamespace(0).findObjectType("AggregateFunctionType");
137
- /* istanbul ignore next */
138
- if (!aggregateFunctionType) {
139
- throw new Error("addressSpace do not expose AggregateFunctionType");
140
- }
141
- const serverObject = addressSpace.rootFolder.objects.getFolderElementByName("Server");
142
- /* istanbul ignore next */
143
- if (!serverObject) {
144
- throw new Error("addressSpace do not expose a ServerObject");
145
- }
146
- // xx serverObject.
147
- const serverCapabilities = serverObject.getChildByName("ServerCapabilities");
148
- // Let see if HistoryServer Capabilities object exists
149
- let historyServerCapabilities = serverCapabilities.getChildByName("HistoryServerCapabilities");
150
- /* istanbul ignore next */
151
- if (!historyServerCapabilities) {
152
- historyServerCapabilities = createHistoryServerCapabilities(addressSpace, serverCapabilities);
153
- }
154
- setHistoricalServerCapabilities(historyServerCapabilities, historicalCapabilitiesDefaultProperties);
155
- addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Interpolative);
156
- addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Minimum);
157
- addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Maximum);
158
- addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Average);
159
- const addressSpaceInternal = addressSpace;
160
- addressSpaceInternal._readProcessedDetails = read_processed_details_1.readProcessedDetails;
161
- }
162
- exports.addAggregateSupport = addAggregateSupport;
163
- function installAggregateConfigurationOptions(node, options) {
164
- const nodePriv = node;
165
- const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
166
- aggregateConfiguration.percentDataBad.setValueFromSource({ dataType: "Byte", value: options.percentDataBad });
167
- aggregateConfiguration.percentDataGood.setValueFromSource({ dataType: "Byte", value: options.percentDataGood });
168
- aggregateConfiguration.treatUncertainAsBad.setValueFromSource({
169
- dataType: "Boolean",
170
- value: options.treatUncertainAsBad
171
- });
172
- aggregateConfiguration.useSlopedExtrapolation.setValueFromSource({
173
- dataType: "Boolean",
174
- value: options.useSlopedExtrapolation
175
- });
176
- nodePriv.$historicalDataConfiguration.stepped.setValueFromSource({
177
- dataType: "Boolean",
178
- value: options.stepped
179
- });
180
- }
181
- exports.installAggregateConfigurationOptions = installAggregateConfigurationOptions;
182
- function getAggregateConfiguration(node) {
183
- const nodePriv = node;
184
- /* istanbul ignore next */
185
- if (!nodePriv.$historicalDataConfiguration) {
186
- throw new Error("internal error");
187
- }
188
- const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
189
- // Beware ! Stepped value comes from Historical Configuration !
190
- const stepped = nodePriv.$historicalDataConfiguration.stepped.readValue().value.value;
191
- return {
192
- percentDataBad: aggregateConfiguration.percentDataBad.readValue().value.value,
193
- percentDataGood: aggregateConfiguration.percentDataGood.readValue().value.value,
194
- stepped,
195
- treatUncertainAsBad: aggregateConfiguration.treatUncertainAsBad.readValue().value.value,
196
- // xx stepped: aggregateConfiguration.stepped.readValue().value,
197
- useSlopedExtrapolation: aggregateConfiguration.useSlopedExtrapolation.readValue().value.value
198
- };
199
- }
200
- exports.getAggregateConfiguration = getAggregateConfiguration;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAggregateConfiguration = exports.installAggregateConfigurationOptions = exports.addAggregateSupport = exports.createHistoryServerCapabilities = void 0;
4
+ /**
5
+ * @module node-opcua-aggregates
6
+ */
7
+ const node_opcua_constants_1 = require("node-opcua-constants");
8
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
9
+ const utils = require("node-opcua-utils");
10
+ const node_opcua_variant_1 = require("node-opcua-variant");
11
+ const read_processed_details_1 = require("./read_processed_details");
12
+ // import { HistoryServerCapabilities } from "node-opcua-server";
13
+ /*
14
+ HasProperty Variable AccessHistoryDataCapability Boolean PropertyType Mandatory
15
+ HasProperty Variable AccessHistoryEventsCapability Boolean PropertyType Mandatory
16
+ HasProperty Variable MaxReturnDataValues UInt32 PropertyType Mandatory
17
+ HasProperty Variable MaxReturnEventValues UInt32 PropertyType Mandatory
18
+ HasProperty Variable InsertDataCapability Boolean PropertyType Mandatory
19
+ HasProperty Variable ReplaceDataCapability Boolean PropertyType Mandatory
20
+ HasProperty Variable UpdateDataCapability Boolean PropertyType Mandatory
21
+ HasProperty Variable DeleteRawCapability Boolean PropertyType Mandatory
22
+ HasProperty Variable DeleteAtTimeCapability Boolean PropertyType Mandatory
23
+ HasProperty Variable InsertEventCapability Boolean PropertyType Mandatory
24
+ HasProperty Variable ReplaceEventCapability Boolean PropertyType Mandatory
25
+ HasProperty Variable UpdateEventCapability Boolean PropertyType Mandatory
26
+ HasProperty Variable DeleteEventCapability Boolean PropertyType Mandatory
27
+ HasProperty Variable InsertAnnotationsCapability Boolean PropertyType Mandatory
28
+ */
29
+ const historicalCapabilitiesDefaultProperties /*: HistoryServerCapabilities */ = {
30
+ accessHistoryDataCapability: true,
31
+ accessHistoryEventsCapability: true,
32
+ deleteAtTimeCapability: false,
33
+ deleteEventCapability: false,
34
+ deleteRawCapability: false,
35
+ insertAnnotationCapability: false,
36
+ insertDataCapability: false,
37
+ insertEventCapability: false,
38
+ maxReturnDataValues: 0,
39
+ maxReturnEventValues: 0,
40
+ replaceDataCapability: false,
41
+ replaceEventCapability: false,
42
+ updateDataCapability: false,
43
+ updateEventCapability: false // Boolean PropertyType Mandatory
44
+ };
45
+ function createHistoryServerCapabilities(addressSpace, serverCapabilities) {
46
+ /* istanbul ignore next */
47
+ if (serverCapabilities.browseName.toString() !== "ServerCapabilities") {
48
+ throw new Error("Expecting server Capabilities");
49
+ }
50
+ const historyServerCapabilitiesType = addressSpace.getNamespace(0).findObjectType("HistoryServerCapabilitiesType");
51
+ /* istanbul ignore next */
52
+ if (!historyServerCapabilitiesType) {
53
+ throw new Error("Cannot find HistoryServerCapabilitiesType");
54
+ }
55
+ return historyServerCapabilitiesType.instantiate({
56
+ browseName: "HistoryServerCapabilities",
57
+ componentOf: serverCapabilities
58
+ });
59
+ }
60
+ exports.createHistoryServerCapabilities = createHistoryServerCapabilities;
61
+ function setHistoricalServerCapabilities(historyServerCapabilities, defaultProperties) {
62
+ function setBoolean(propName) {
63
+ const lowerCase = utils.lowerFirstLetter(propName);
64
+ /* istanbul ignore next */
65
+ if (!Object.prototype.hasOwnProperty.call(defaultProperties, lowerCase)) {
66
+ throw new Error("cannot find " + lowerCase);
67
+ }
68
+ const value = defaultProperties[lowerCase];
69
+ const prop = historyServerCapabilities.getChildByName(propName);
70
+ /* istanbul ignore next */
71
+ if (!prop) {
72
+ throw new Error(" Cannot find property " + propName);
73
+ }
74
+ prop.setValueFromSource({ dataType: node_opcua_variant_1.DataType.Boolean, value });
75
+ }
76
+ function setUInt32(propName) {
77
+ const lowerCase = utils.lowerFirstLetter(propName);
78
+ /* istanbul ignore next */
79
+ if (!Object.prototype.hasOwnProperty.call(historyServerCapabilities, lowerCase)) {
80
+ throw new Error("cannot find " + lowerCase);
81
+ }
82
+ const value = defaultProperties[lowerCase];
83
+ const prop = historyServerCapabilities.getChildByName(propName);
84
+ prop.setValueFromSource({ dataType: node_opcua_variant_1.DataType.UInt32, value });
85
+ }
86
+ setBoolean("AccessHistoryDataCapability");
87
+ setBoolean("AccessHistoryEventsCapability");
88
+ setUInt32("MaxReturnDataValues");
89
+ setUInt32("MaxReturnEventValues");
90
+ setBoolean("InsertDataCapability");
91
+ setBoolean("ReplaceDataCapability");
92
+ setBoolean("UpdateDataCapability");
93
+ setBoolean("DeleteRawCapability");
94
+ setBoolean("DeleteAtTimeCapability");
95
+ setBoolean("InsertEventCapability");
96
+ setBoolean("ReplaceEventCapability");
97
+ setBoolean("UpdateEventCapability");
98
+ setBoolean("DeleteEventCapability");
99
+ /// FOUND A BUG HERE spec says InsertAnnotationsCapability
100
+ /// Standard nodeset2 says InsertAnnotationCapability ( without s )
101
+ // xx setBoolean("InsertAnnotationsCapability");
102
+ }
103
+ function addAggregateFunctionSupport(addressSpace, functionName) {
104
+ /* istanbul ignore next */
105
+ if (!functionName) {
106
+ throw new Error("Invalid function name");
107
+ }
108
+ const serverCapabilities = addressSpace.rootFolder.objects.server.serverCapabilities;
109
+ /* istanbul ignore next */
110
+ if (!serverCapabilities.historyServerCapabilities) {
111
+ throw new Error("missing serverCapabilities.historyServerCapabilities");
112
+ }
113
+ const aggregateFunctions = serverCapabilities.aggregateFunctions;
114
+ const aggregateFunctionsInHist = serverCapabilities.historyServerCapabilities.aggregateFunctions;
115
+ const functionNodeId = (0, node_opcua_nodeid_1.makeNodeId)(functionName);
116
+ const functionNode = addressSpace.getNamespace(0).findNode(functionNodeId);
117
+ /* istanbul ignore next */
118
+ if (!functionNode) {
119
+ throw new Error("Cannot find node " + functionName + " in addressSpace");
120
+ }
121
+ aggregateFunctions.addReference({
122
+ nodeId: functionNode.nodeId,
123
+ referenceType: "Organizes"
124
+ });
125
+ aggregateFunctionsInHist.addReference({
126
+ nodeId: functionNode.nodeId,
127
+ referenceType: "Organizes"
128
+ });
129
+ }
130
+ function addAggregateSupport(addressSpace) {
131
+ const aggregateConfigurationType = addressSpace.getNamespace(0).findObjectType("AggregateConfigurationType");
132
+ /* istanbul ignore next */
133
+ if (!aggregateConfigurationType) {
134
+ throw new Error("addressSpace do not expose AggregateConfigurationType");
135
+ }
136
+ const aggregateFunctionType = addressSpace.getNamespace(0).findObjectType("AggregateFunctionType");
137
+ /* istanbul ignore next */
138
+ if (!aggregateFunctionType) {
139
+ throw new Error("addressSpace do not expose AggregateFunctionType");
140
+ }
141
+ const serverObject = addressSpace.rootFolder.objects.getFolderElementByName("Server");
142
+ /* istanbul ignore next */
143
+ if (!serverObject) {
144
+ throw new Error("addressSpace do not expose a ServerObject");
145
+ }
146
+ // xx serverObject.
147
+ const serverCapabilities = serverObject.getChildByName("ServerCapabilities");
148
+ // Let see if HistoryServer Capabilities object exists
149
+ let historyServerCapabilities = serverCapabilities.getChildByName("HistoryServerCapabilities");
150
+ /* istanbul ignore next */
151
+ if (!historyServerCapabilities) {
152
+ historyServerCapabilities = createHistoryServerCapabilities(addressSpace, serverCapabilities);
153
+ }
154
+ setHistoricalServerCapabilities(historyServerCapabilities, historicalCapabilitiesDefaultProperties);
155
+ addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Interpolative);
156
+ addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Minimum);
157
+ addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Maximum);
158
+ addAggregateFunctionSupport(addressSpace, node_opcua_constants_1.AggregateFunction.Average);
159
+ const addressSpaceInternal = addressSpace;
160
+ addressSpaceInternal._readProcessedDetails = read_processed_details_1.readProcessedDetails;
161
+ }
162
+ exports.addAggregateSupport = addAggregateSupport;
163
+ function installAggregateConfigurationOptions(node, options) {
164
+ const nodePriv = node;
165
+ const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
166
+ aggregateConfiguration.percentDataBad.setValueFromSource({ dataType: "Byte", value: options.percentDataBad });
167
+ aggregateConfiguration.percentDataGood.setValueFromSource({ dataType: "Byte", value: options.percentDataGood });
168
+ aggregateConfiguration.treatUncertainAsBad.setValueFromSource({
169
+ dataType: "Boolean",
170
+ value: options.treatUncertainAsBad
171
+ });
172
+ aggregateConfiguration.useSlopedExtrapolation.setValueFromSource({
173
+ dataType: "Boolean",
174
+ value: options.useSlopedExtrapolation
175
+ });
176
+ nodePriv.$historicalDataConfiguration.stepped.setValueFromSource({
177
+ dataType: "Boolean",
178
+ value: options.stepped
179
+ });
180
+ }
181
+ exports.installAggregateConfigurationOptions = installAggregateConfigurationOptions;
182
+ function getAggregateConfiguration(node) {
183
+ const nodePriv = node;
184
+ /* istanbul ignore next */
185
+ if (!nodePriv.$historicalDataConfiguration) {
186
+ throw new Error("internal error");
187
+ }
188
+ const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
189
+ // Beware ! Stepped value comes from Historical Configuration !
190
+ const stepped = nodePriv.$historicalDataConfiguration.stepped.readValue().value.value;
191
+ return {
192
+ percentDataBad: aggregateConfiguration.percentDataBad.readValue().value.value,
193
+ percentDataGood: aggregateConfiguration.percentDataGood.readValue().value.value,
194
+ stepped,
195
+ treatUncertainAsBad: aggregateConfiguration.treatUncertainAsBad.readValue().value.value,
196
+ // xx stepped: aggregateConfiguration.stepped.readValue().value,
197
+ useSlopedExtrapolation: aggregateConfiguration.useSlopedExtrapolation.readValue().value.value
198
+ };
199
+ }
200
+ exports.getAggregateConfiguration = getAggregateConfiguration;
201
201
  //# sourceMappingURL=aggregates.js.map
package/dist/average.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { UAVariable } from "node-opcua-address-space";
2
- import { DataValue } from "node-opcua-data-value";
3
- export declare function getAverageData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
1
+ import { UAVariable } from "node-opcua-address-space";
2
+ import { DataValue } from "node-opcua-data-value";
3
+ export declare function getAverageData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
package/dist/average.js CHANGED
@@ -1,62 +1,62 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAverageData = void 0;
4
- const node_opcua_data_value_1 = require("node-opcua-data-value");
5
- const node_opcua_variant_1 = require("node-opcua-variant");
6
- const node_opcua_status_code_1 = require("node-opcua-status-code");
7
- const common_1 = require("./common");
8
- const interval_1 = require("./interval");
9
- function calculateIntervalAverageValue(interval, options) {
10
- const indexStart = interval.index;
11
- let statusCode;
12
- let isPartial = interval.isPartial;
13
- const isRaw = false;
14
- let hasBad = false;
15
- const values = [];
16
- for (let i = indexStart; i < indexStart + interval.count; i++) {
17
- const dataValue = interval.dataValues[i];
18
- if (dataValue.statusCode === node_opcua_status_code_1.StatusCodes.BadNoData) {
19
- isPartial = true;
20
- continue;
21
- }
22
- if (!(0, interval_1.isGood)(dataValue.statusCode)) {
23
- hasBad = true;
24
- continue;
25
- }
26
- values.push(dataValue.value.value);
27
- }
28
- if (isRaw) {
29
- if (hasBad) {
30
- statusCode = node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal;
31
- }
32
- else {
33
- statusCode = node_opcua_status_code_1.StatusCodes.Good;
34
- }
35
- }
36
- else if (hasBad) {
37
- statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, "HistorianCalculated");
38
- }
39
- else {
40
- statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.Good, "HistorianCalculated");
41
- }
42
- if (values.length === 0) {
43
- return new node_opcua_data_value_1.DataValue({
44
- sourceTimestamp: interval.startTime,
45
- statusCode: node_opcua_status_code_1.StatusCodes.BadNoData
46
- });
47
- }
48
- const mean = values.reduce((p, c) => p + c, 0) / values.length;
49
- return new node_opcua_data_value_1.DataValue({
50
- sourceTimestamp: interval.startTime,
51
- statusCode: statusCode,
52
- value: {
53
- dataType: node_opcua_variant_1.DataType.Double,
54
- value: mean
55
- }
56
- });
57
- }
58
- function getAverageData(node, processingInterval, startDate, endDate, callback) {
59
- (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalAverageValue, callback);
60
- }
61
- exports.getAverageData = getAverageData;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAverageData = void 0;
4
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
5
+ const node_opcua_variant_1 = require("node-opcua-variant");
6
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
7
+ const common_1 = require("./common");
8
+ const interval_1 = require("./interval");
9
+ function calculateIntervalAverageValue(interval, options) {
10
+ const indexStart = interval.index;
11
+ let statusCode;
12
+ let isPartial = interval.isPartial;
13
+ const isRaw = false;
14
+ let hasBad = false;
15
+ const values = [];
16
+ for (let i = indexStart; i < indexStart + interval.count; i++) {
17
+ const dataValue = interval.dataValues[i];
18
+ if (dataValue.statusCode === node_opcua_status_code_1.StatusCodes.BadNoData) {
19
+ isPartial = true;
20
+ continue;
21
+ }
22
+ if (!(0, interval_1.isGood)(dataValue.statusCode)) {
23
+ hasBad = true;
24
+ continue;
25
+ }
26
+ values.push(dataValue.value.value);
27
+ }
28
+ if (isRaw) {
29
+ if (hasBad) {
30
+ statusCode = node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal;
31
+ }
32
+ else {
33
+ statusCode = node_opcua_status_code_1.StatusCodes.Good;
34
+ }
35
+ }
36
+ else if (hasBad) {
37
+ statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, "HistorianCalculated");
38
+ }
39
+ else {
40
+ statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.Good, "HistorianCalculated");
41
+ }
42
+ if (values.length === 0) {
43
+ return new node_opcua_data_value_1.DataValue({
44
+ sourceTimestamp: interval.startTime,
45
+ statusCode: node_opcua_status_code_1.StatusCodes.BadNoData
46
+ });
47
+ }
48
+ const mean = values.reduce((p, c) => p + c, 0) / values.length;
49
+ return new node_opcua_data_value_1.DataValue({
50
+ sourceTimestamp: interval.startTime,
51
+ statusCode: statusCode,
52
+ value: {
53
+ dataType: node_opcua_variant_1.DataType.Double,
54
+ value: mean
55
+ }
56
+ });
57
+ }
58
+ function getAverageData(node, processingInterval, startDate, endDate, callback) {
59
+ (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalAverageValue, callback);
60
+ }
61
+ exports.getAverageData = getAverageData;
62
62
  //# sourceMappingURL=average.js.map
package/dist/common.d.ts CHANGED
@@ -1,8 +1,8 @@
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 { Interval, AggregateConfigurationOptionsEx } from "./interval";
7
- export declare function getAggregateData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, lambda: (interval: Interval, aggregateConfiguration: AggregateConfigurationOptionsEx) => DataValue, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
8
- export declare function interpolateValue(dataValue1: DataValue, dataValue2: DataValue, date: Date): DataValue;
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 { Interval, AggregateConfigurationOptionsEx } from "./interval";
7
+ export declare function getAggregateData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, lambda: (interval: Interval, aggregateConfiguration: AggregateConfigurationOptionsEx) => DataValue, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
8
+ export declare function interpolateValue(dataValue1: DataValue, dataValue2: DataValue, date: Date): DataValue;