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
@@ -1,277 +1,284 @@
1
- /**
2
- * @module node-opcua-aggregates
3
- */
4
- import { AggregateFunction } from "node-opcua-constants";
5
- import { makeNodeId } from "node-opcua-nodeid";
6
- import * as utils from "node-opcua-utils";
7
- import { DataType } from "node-opcua-variant";
8
-
9
- import { AddressSpace, BaseNode, UAHistoryServerCapabilities, UAHistoryServerCapabilities_Base, UAObject, UAServerCapabilities, UAVariable } from "node-opcua-address-space";
10
- import { AggregateConfigurationOptionsEx } from "./interval";
11
- import { AddressSpacePrivate } from "node-opcua-address-space/src/address_space_private";
12
- import { readProcessedDetails } from "./read_processed_details";
13
-
14
- // import { HistoryServerCapabilities } from "node-opcua-server";
15
-
16
- /*
17
- HasProperty Variable AccessHistoryDataCapability Boolean PropertyType Mandatory
18
- HasProperty Variable AccessHistoryEventsCapability Boolean PropertyType Mandatory
19
- HasProperty Variable MaxReturnDataValues UInt32 PropertyType Mandatory
20
- HasProperty Variable MaxReturnEventValues UInt32 PropertyType Mandatory
21
- HasProperty Variable InsertDataCapability Boolean PropertyType Mandatory
22
- HasProperty Variable ReplaceDataCapability Boolean PropertyType Mandatory
23
- HasProperty Variable UpdateDataCapability Boolean PropertyType Mandatory
24
- HasProperty Variable DeleteRawCapability Boolean PropertyType Mandatory
25
- HasProperty Variable DeleteAtTimeCapability Boolean PropertyType Mandatory
26
- HasProperty Variable InsertEventCapability Boolean PropertyType Mandatory
27
- HasProperty Variable ReplaceEventCapability Boolean PropertyType Mandatory
28
- HasProperty Variable UpdateEventCapability Boolean PropertyType Mandatory
29
- HasProperty Variable DeleteEventCapability Boolean PropertyType Mandatory
30
- HasProperty Variable InsertAnnotationsCapability Boolean PropertyType Mandatory
31
- */
32
- const historicalCapabilitiesDefaultProperties /*: HistoryServerCapabilities */ = {
33
- accessHistoryDataCapability: true, // Boolean PropertyType Mandatory
34
- accessHistoryEventsCapability: true, // Boolean PropertyType Mandatory
35
- deleteAtTimeCapability: false, // Boolean PropertyType Mandatory
36
- deleteEventCapability: false, // Boolean PropertyType Mandatory
37
- deleteRawCapability: false, // Boolean PropertyType Mandatory
38
- insertAnnotationCapability: false, // Boolean PropertyType Mandatory
39
- insertDataCapability: false, // Boolean PropertyType Mandatory
40
- insertEventCapability: false, // Boolean PropertyType Mandatory
41
- maxReturnDataValues: 0,
42
- maxReturnEventValues: 0, // UInt32 PropertyType Mandatory
43
- replaceDataCapability: false, // Boolean PropertyType Mandatory
44
- replaceEventCapability: false, // Boolean PropertyType Mandatory
45
- updateDataCapability: false, // Boolean PropertyType Mandatory
46
- updateEventCapability: false // Boolean PropertyType Mandatory
47
- };
48
-
49
- export function createHistoryServerCapabilities(addressSpace: AddressSpace, serverCapabilities: UAServerCapabilities): UAObject {
50
- /* istanbul ignore next */
51
- if (serverCapabilities.browseName.toString() !== "ServerCapabilities") {
52
- throw new Error("Expecting server Capabilities");
53
- }
54
-
55
- const historyServerCapabilitiesType = addressSpace.getNamespace(0).findObjectType("HistoryServerCapabilitiesType")!;
56
-
57
- /* istanbul ignore next */
58
- if (!historyServerCapabilitiesType) {
59
- throw new Error("Cannot find HistoryServerCapabilitiesType");
60
- }
61
- return historyServerCapabilitiesType.instantiate({
62
- browseName: "HistoryServerCapabilities",
63
- componentOf: serverCapabilities
64
- });
65
- }
66
-
67
- function setHistoricalServerCapabilities(historyServerCapabilities: any, defaultProperties: any) {
68
- function setBoolean(propName: string) {
69
- const lowerCase = utils.lowerFirstLetter(propName);
70
-
71
- /* istanbul ignore next */
72
- if (!defaultProperties.hasOwnProperty(lowerCase)) {
73
- throw new Error("cannot find " + lowerCase);
74
- }
75
- const value = defaultProperties[lowerCase];
76
- const prop = historyServerCapabilities.getChildByName(propName);
77
-
78
- /* istanbul ignore next */
79
- if (!prop) {
80
- throw new Error(" Cannot find property " + propName);
81
- }
82
- prop.setValueFromSource({ dataType: DataType.Boolean, value });
83
- }
84
-
85
- function setUInt32(propName: string) {
86
- const lowerCase = utils.lowerFirstLetter(propName);
87
- /* istanbul ignore next */
88
- if (!historyServerCapabilities.hasOwnProperty(lowerCase)) {
89
- throw new Error("cannot find " + lowerCase);
90
- }
91
- const value = defaultProperties[lowerCase];
92
- const prop = historyServerCapabilities.getChildByName(propName);
93
- prop.setValueFromSource({ dataType: DataType.UInt32, value });
94
- }
95
-
96
- setBoolean("AccessHistoryDataCapability");
97
- setBoolean("AccessHistoryEventsCapability");
98
-
99
- setUInt32("MaxReturnDataValues");
100
- setUInt32("MaxReturnEventValues");
101
-
102
- setBoolean("InsertDataCapability");
103
- setBoolean("ReplaceDataCapability");
104
- setBoolean("UpdateDataCapability");
105
- setBoolean("DeleteRawCapability");
106
- setBoolean("DeleteAtTimeCapability");
107
- setBoolean("InsertEventCapability");
108
- setBoolean("ReplaceEventCapability");
109
- setBoolean("UpdateEventCapability");
110
- setBoolean("DeleteEventCapability");
111
-
112
- /// FOUND A BUG HERE spec says InsertAnnotationsCapability
113
- /// Standard nodeset2 says InsertAnnotationCapability ( without s )
114
- // xx setBoolean("InsertAnnotationsCapability");
115
- }
116
-
117
- export type AggregateFunctionName =
118
- | "AnnotationCount"
119
- | "Average"
120
- | "Count"
121
- | "Delta"
122
- | "DeltaBounds"
123
- | "DurationBad"
124
- | "DurationGood"
125
- | "DurationInStateNonZero"
126
- | "DurationInStateZero"
127
- | "EndBound"
128
- | "Interpolative"
129
- | "Maximum"
130
- | "Maximum2"
131
- | "MaximumActualTime"
132
- | "MaximumActualTime2"
133
- | "Minimum"
134
- | "Minimum2"
135
- | "MinimumActualTime"
136
- | "MinimumActualTime2"
137
- | "NumberOfTransitions"
138
- | "PercentBad"
139
- | "PercentGood"
140
- | "Range"
141
- | "Range2"
142
- | "StandardDeviationPopulation"
143
- | "StandardDeviationSample"
144
- | "Start"
145
- | "StartBound"
146
- | "TimeAverage"
147
- | "TimeAverage2"
148
- | "Total"
149
- | "Total2"
150
- | "VariancePopulation"
151
- | "VarianceSample"
152
- | "WorstQuality"
153
- | "WorstQuality2";
154
-
155
- interface UAHistoryServerCapabilitiesWithH extends UAServerCapabilities {
156
- historyServerCapabilities: UAHistoryServerCapabilities;
157
- }
158
- function addAggregateFunctionSupport(addressSpace: AddressSpace, functionName: number): void {
159
- /* istanbul ignore next */
160
- if (!functionName) {
161
- throw new Error("Invalid function name");
162
- }
163
-
164
- const serverCapabilities = addressSpace.rootFolder.objects.server.serverCapabilities as UAHistoryServerCapabilitiesWithH;
165
-
166
- /* istanbul ignore next */
167
- if (!serverCapabilities.historyServerCapabilities) {
168
- throw new Error("missing serverCapabilities.historyServerCapabilities");
169
- }
170
-
171
- const aggregateFunctions = serverCapabilities.aggregateFunctions;
172
-
173
- const aggregateFunctionsInHist = serverCapabilities.historyServerCapabilities.aggregateFunctions;
174
-
175
- const functionNodeId = makeNodeId(functionName);
176
- const functionNode = addressSpace.getNamespace(0).findNode(functionNodeId);
177
-
178
- /* istanbul ignore next */
179
- if (!functionNode) {
180
- throw new Error("Cannot find node " + functionName + " in addressSpace");
181
- }
182
-
183
- aggregateFunctions.addReference({
184
- nodeId: functionNode.nodeId,
185
- referenceType: "Organizes"
186
- });
187
- aggregateFunctionsInHist.addReference({
188
- nodeId: functionNode.nodeId,
189
- referenceType: "Organizes"
190
- });
191
- }
192
-
193
- export function addAggregateSupport(addressSpace: AddressSpace) {
194
- const aggregateConfigurationType = addressSpace.getNamespace(0).findObjectType("AggregateConfigurationType");
195
-
196
- /* istanbul ignore next */
197
- if (!aggregateConfigurationType) {
198
- throw new Error("addressSpace do not expose AggregateConfigurationType");
199
- }
200
-
201
- const aggregateFunctionType = addressSpace.getNamespace(0).findObjectType("AggregateFunctionType");
202
-
203
- /* istanbul ignore next */
204
- if (!aggregateFunctionType) {
205
- throw new Error("addressSpace do not expose AggregateFunctionType");
206
- }
207
-
208
- const serverObject = addressSpace.rootFolder.objects.getFolderElementByName("Server");
209
-
210
- /* istanbul ignore next */
211
- if (!serverObject) {
212
- throw new Error("addressSpace do not expose a ServerObject");
213
- }
214
- // xx serverObject.
215
-
216
- const serverCapabilities = serverObject.getChildByName("ServerCapabilities")! as UAServerCapabilities;
217
-
218
- // Let see if HistoryServer Capabilities object exists
219
- let historyServerCapabilities = serverCapabilities.getChildByName("HistoryServerCapabilities");
220
-
221
- /* istanbul ignore next */
222
- if (!historyServerCapabilities) {
223
- historyServerCapabilities = createHistoryServerCapabilities(addressSpace, serverCapabilities);
224
- }
225
-
226
- setHistoricalServerCapabilities(historyServerCapabilities, historicalCapabilitiesDefaultProperties);
227
-
228
- addAggregateFunctionSupport(addressSpace, AggregateFunction.Interpolative);
229
- addAggregateFunctionSupport(addressSpace, AggregateFunction.Minimum);
230
- addAggregateFunctionSupport(addressSpace, AggregateFunction.Maximum);
231
- addAggregateFunctionSupport(addressSpace, AggregateFunction.Average);
232
-
233
- const addressSpaceInternal = (addressSpace as unknown) as AddressSpacePrivate;
234
- addressSpaceInternal._readProcessedDetails = readProcessedDetails;
235
- }
236
-
237
- export function installAggregateConfigurationOptions(node: UAVariable, options: AggregateConfigurationOptionsEx) {
238
- const nodePriv = node as any;
239
- const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
240
- aggregateConfiguration.percentDataBad.setValueFromSource({ dataType: "Byte", value: options.percentDataBad });
241
- aggregateConfiguration.percentDataGood.setValueFromSource({ dataType: "Byte", value: options.percentDataGood });
242
- aggregateConfiguration.treatUncertainAsBad.setValueFromSource({
243
- dataType: "Boolean",
244
- value: options.treatUncertainAsBad
245
- });
246
- aggregateConfiguration.useSlopedExtrapolation.setValueFromSource({
247
- dataType: "Boolean",
248
- value: options.useSlopedExtrapolation
249
- });
250
-
251
- nodePriv.$historicalDataConfiguration.stepped.setValueFromSource({
252
- dataType: "Boolean",
253
- value: options.stepped
254
- });
255
- }
256
-
257
- export function getAggregateConfiguration(node: BaseNode): AggregateConfigurationOptionsEx {
258
- const nodePriv = node as any;
259
-
260
- /* istanbul ignore next */
261
- if (!nodePriv.$historicalDataConfiguration) {
262
- throw new Error("internal error");
263
- }
264
- const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
265
-
266
- // Beware ! Stepped value comes from Historical Configuration !
267
- const stepped = nodePriv.$historicalDataConfiguration.stepped.readValue().value.value;
268
-
269
- return {
270
- percentDataBad: aggregateConfiguration.percentDataBad.readValue().value.value,
271
- percentDataGood: aggregateConfiguration.percentDataGood.readValue().value.value,
272
- stepped,
273
- treatUncertainAsBad: aggregateConfiguration.treatUncertainAsBad.readValue().value.value,
274
- // xx stepped: aggregateConfiguration.stepped.readValue().value,
275
- useSlopedExtrapolation: aggregateConfiguration.useSlopedExtrapolation.readValue().value.value
276
- };
277
- }
1
+ /**
2
+ * @module node-opcua-aggregates
3
+ */
4
+ import { AggregateFunction } from "node-opcua-constants";
5
+ import { makeNodeId } from "node-opcua-nodeid";
6
+ import * as utils from "node-opcua-utils";
7
+ import { DataType } from "node-opcua-variant";
8
+ import {
9
+ AddressSpace,
10
+ BaseNode,
11
+ UAHistoryServerCapabilities,
12
+ UAObject,
13
+ UAServerCapabilities,
14
+ UAVariable
15
+ } from "node-opcua-address-space";
16
+ import { AddressSpacePrivate } from "node-opcua-address-space/src/address_space_private";
17
+
18
+ import { AggregateConfigurationOptionsEx } from "./interval";
19
+ import { readProcessedDetails } from "./read_processed_details";
20
+
21
+ // import { HistoryServerCapabilities } from "node-opcua-server";
22
+
23
+ /*
24
+ HasProperty Variable AccessHistoryDataCapability Boolean PropertyType Mandatory
25
+ HasProperty Variable AccessHistoryEventsCapability Boolean PropertyType Mandatory
26
+ HasProperty Variable MaxReturnDataValues UInt32 PropertyType Mandatory
27
+ HasProperty Variable MaxReturnEventValues UInt32 PropertyType Mandatory
28
+ HasProperty Variable InsertDataCapability Boolean PropertyType Mandatory
29
+ HasProperty Variable ReplaceDataCapability Boolean PropertyType Mandatory
30
+ HasProperty Variable UpdateDataCapability Boolean PropertyType Mandatory
31
+ HasProperty Variable DeleteRawCapability Boolean PropertyType Mandatory
32
+ HasProperty Variable DeleteAtTimeCapability Boolean PropertyType Mandatory
33
+ HasProperty Variable InsertEventCapability Boolean PropertyType Mandatory
34
+ HasProperty Variable ReplaceEventCapability Boolean PropertyType Mandatory
35
+ HasProperty Variable UpdateEventCapability Boolean PropertyType Mandatory
36
+ HasProperty Variable DeleteEventCapability Boolean PropertyType Mandatory
37
+ HasProperty Variable InsertAnnotationsCapability Boolean PropertyType Mandatory
38
+ */
39
+ const historicalCapabilitiesDefaultProperties /*: HistoryServerCapabilities */ = {
40
+ accessHistoryDataCapability: true, // Boolean PropertyType Mandatory
41
+ accessHistoryEventsCapability: true, // Boolean PropertyType Mandatory
42
+ deleteAtTimeCapability: false, // Boolean PropertyType Mandatory
43
+ deleteEventCapability: false, // Boolean PropertyType Mandatory
44
+ deleteRawCapability: false, // Boolean PropertyType Mandatory
45
+ insertAnnotationCapability: false, // Boolean PropertyType Mandatory
46
+ insertDataCapability: false, // Boolean PropertyType Mandatory
47
+ insertEventCapability: false, // Boolean PropertyType Mandatory
48
+ maxReturnDataValues: 0,
49
+ maxReturnEventValues: 0, // UInt32 PropertyType Mandatory
50
+ replaceDataCapability: false, // Boolean PropertyType Mandatory
51
+ replaceEventCapability: false, // Boolean PropertyType Mandatory
52
+ updateDataCapability: false, // Boolean PropertyType Mandatory
53
+ updateEventCapability: false // Boolean PropertyType Mandatory
54
+ };
55
+
56
+ export function createHistoryServerCapabilities(addressSpace: AddressSpace, serverCapabilities: UAServerCapabilities): UAObject {
57
+ /* istanbul ignore next */
58
+ if (serverCapabilities.browseName.toString() !== "ServerCapabilities") {
59
+ throw new Error("Expecting server Capabilities");
60
+ }
61
+
62
+ const historyServerCapabilitiesType = addressSpace.getNamespace(0).findObjectType("HistoryServerCapabilitiesType")!;
63
+
64
+ /* istanbul ignore next */
65
+ if (!historyServerCapabilitiesType) {
66
+ throw new Error("Cannot find HistoryServerCapabilitiesType");
67
+ }
68
+ return historyServerCapabilitiesType.instantiate({
69
+ browseName: "HistoryServerCapabilities",
70
+ componentOf: serverCapabilities
71
+ });
72
+ }
73
+
74
+ function setHistoricalServerCapabilities(historyServerCapabilities: any, defaultProperties: any) {
75
+ function setBoolean(propName: string) {
76
+ const lowerCase = utils.lowerFirstLetter(propName);
77
+
78
+ /* istanbul ignore next */
79
+ if (!Object.prototype.hasOwnProperty.call(defaultProperties, lowerCase)) {
80
+ throw new Error("cannot find " + lowerCase);
81
+ }
82
+ const value = defaultProperties[lowerCase];
83
+ const prop = historyServerCapabilities.getChildByName(propName);
84
+
85
+ /* istanbul ignore next */
86
+ if (!prop) {
87
+ throw new Error(" Cannot find property " + propName);
88
+ }
89
+ prop.setValueFromSource({ dataType: DataType.Boolean, value });
90
+ }
91
+
92
+ function setUInt32(propName: string) {
93
+ const lowerCase = utils.lowerFirstLetter(propName);
94
+ /* istanbul ignore next */
95
+ if (!Object.prototype.hasOwnProperty.call(historyServerCapabilities, lowerCase)) {
96
+ throw new Error("cannot find " + lowerCase);
97
+ }
98
+ const value = defaultProperties[lowerCase];
99
+ const prop = historyServerCapabilities.getChildByName(propName);
100
+ prop.setValueFromSource({ dataType: DataType.UInt32, value });
101
+ }
102
+
103
+ setBoolean("AccessHistoryDataCapability");
104
+ setBoolean("AccessHistoryEventsCapability");
105
+
106
+ setUInt32("MaxReturnDataValues");
107
+ setUInt32("MaxReturnEventValues");
108
+
109
+ setBoolean("InsertDataCapability");
110
+ setBoolean("ReplaceDataCapability");
111
+ setBoolean("UpdateDataCapability");
112
+ setBoolean("DeleteRawCapability");
113
+ setBoolean("DeleteAtTimeCapability");
114
+ setBoolean("InsertEventCapability");
115
+ setBoolean("ReplaceEventCapability");
116
+ setBoolean("UpdateEventCapability");
117
+ setBoolean("DeleteEventCapability");
118
+
119
+ /// FOUND A BUG HERE spec says InsertAnnotationsCapability
120
+ /// Standard nodeset2 says InsertAnnotationCapability ( without s )
121
+ // xx setBoolean("InsertAnnotationsCapability");
122
+ }
123
+
124
+ export type AggregateFunctionName =
125
+ | "AnnotationCount"
126
+ | "Average"
127
+ | "Count"
128
+ | "Delta"
129
+ | "DeltaBounds"
130
+ | "DurationBad"
131
+ | "DurationGood"
132
+ | "DurationInStateNonZero"
133
+ | "DurationInStateZero"
134
+ | "EndBound"
135
+ | "Interpolative"
136
+ | "Maximum"
137
+ | "Maximum2"
138
+ | "MaximumActualTime"
139
+ | "MaximumActualTime2"
140
+ | "Minimum"
141
+ | "Minimum2"
142
+ | "MinimumActualTime"
143
+ | "MinimumActualTime2"
144
+ | "NumberOfTransitions"
145
+ | "PercentBad"
146
+ | "PercentGood"
147
+ | "Range"
148
+ | "Range2"
149
+ | "StandardDeviationPopulation"
150
+ | "StandardDeviationSample"
151
+ | "Start"
152
+ | "StartBound"
153
+ | "TimeAverage"
154
+ | "TimeAverage2"
155
+ | "Total"
156
+ | "Total2"
157
+ | "VariancePopulation"
158
+ | "VarianceSample"
159
+ | "WorstQuality"
160
+ | "WorstQuality2";
161
+
162
+ interface UAHistoryServerCapabilitiesWithH extends UAServerCapabilities {
163
+ historyServerCapabilities: UAHistoryServerCapabilities;
164
+ }
165
+ function addAggregateFunctionSupport(addressSpace: AddressSpace, functionName: number): void {
166
+ /* istanbul ignore next */
167
+ if (!functionName) {
168
+ throw new Error("Invalid function name");
169
+ }
170
+
171
+ const serverCapabilities = addressSpace.rootFolder.objects.server.serverCapabilities as UAHistoryServerCapabilitiesWithH;
172
+
173
+ /* istanbul ignore next */
174
+ if (!serverCapabilities.historyServerCapabilities) {
175
+ throw new Error("missing serverCapabilities.historyServerCapabilities");
176
+ }
177
+
178
+ const aggregateFunctions = serverCapabilities.aggregateFunctions;
179
+
180
+ const aggregateFunctionsInHist = serverCapabilities.historyServerCapabilities.aggregateFunctions;
181
+
182
+ const functionNodeId = makeNodeId(functionName);
183
+ const functionNode = addressSpace.getNamespace(0).findNode(functionNodeId);
184
+
185
+ /* istanbul ignore next */
186
+ if (!functionNode) {
187
+ throw new Error("Cannot find node " + functionName + " in addressSpace");
188
+ }
189
+
190
+ aggregateFunctions.addReference({
191
+ nodeId: functionNode.nodeId,
192
+ referenceType: "Organizes"
193
+ });
194
+ aggregateFunctionsInHist.addReference({
195
+ nodeId: functionNode.nodeId,
196
+ referenceType: "Organizes"
197
+ });
198
+ }
199
+
200
+ export function addAggregateSupport(addressSpace: AddressSpace): void {
201
+ const aggregateConfigurationType = addressSpace.getNamespace(0).findObjectType("AggregateConfigurationType");
202
+
203
+ /* istanbul ignore next */
204
+ if (!aggregateConfigurationType) {
205
+ throw new Error("addressSpace do not expose AggregateConfigurationType");
206
+ }
207
+
208
+ const aggregateFunctionType = addressSpace.getNamespace(0).findObjectType("AggregateFunctionType");
209
+
210
+ /* istanbul ignore next */
211
+ if (!aggregateFunctionType) {
212
+ throw new Error("addressSpace do not expose AggregateFunctionType");
213
+ }
214
+
215
+ const serverObject = addressSpace.rootFolder.objects.getFolderElementByName("Server");
216
+
217
+ /* istanbul ignore next */
218
+ if (!serverObject) {
219
+ throw new Error("addressSpace do not expose a ServerObject");
220
+ }
221
+ // xx serverObject.
222
+
223
+ const serverCapabilities = serverObject.getChildByName("ServerCapabilities")! as UAServerCapabilities;
224
+
225
+ // Let see if HistoryServer Capabilities object exists
226
+ let historyServerCapabilities = serverCapabilities.getChildByName("HistoryServerCapabilities");
227
+
228
+ /* istanbul ignore next */
229
+ if (!historyServerCapabilities) {
230
+ historyServerCapabilities = createHistoryServerCapabilities(addressSpace, serverCapabilities);
231
+ }
232
+
233
+ setHistoricalServerCapabilities(historyServerCapabilities, historicalCapabilitiesDefaultProperties);
234
+
235
+ addAggregateFunctionSupport(addressSpace, AggregateFunction.Interpolative);
236
+ addAggregateFunctionSupport(addressSpace, AggregateFunction.Minimum);
237
+ addAggregateFunctionSupport(addressSpace, AggregateFunction.Maximum);
238
+ addAggregateFunctionSupport(addressSpace, AggregateFunction.Average);
239
+
240
+ const addressSpaceInternal = addressSpace as unknown as AddressSpacePrivate;
241
+ addressSpaceInternal._readProcessedDetails = readProcessedDetails;
242
+ }
243
+
244
+ export function installAggregateConfigurationOptions(node: UAVariable, options: AggregateConfigurationOptionsEx): void {
245
+ const nodePriv = node as any;
246
+ const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
247
+ aggregateConfiguration.percentDataBad.setValueFromSource({ dataType: "Byte", value: options.percentDataBad });
248
+ aggregateConfiguration.percentDataGood.setValueFromSource({ dataType: "Byte", value: options.percentDataGood });
249
+ aggregateConfiguration.treatUncertainAsBad.setValueFromSource({
250
+ dataType: "Boolean",
251
+ value: options.treatUncertainAsBad
252
+ });
253
+ aggregateConfiguration.useSlopedExtrapolation.setValueFromSource({
254
+ dataType: "Boolean",
255
+ value: options.useSlopedExtrapolation
256
+ });
257
+
258
+ nodePriv.$historicalDataConfiguration.stepped.setValueFromSource({
259
+ dataType: "Boolean",
260
+ value: options.stepped
261
+ });
262
+ }
263
+
264
+ export function getAggregateConfiguration(node: BaseNode): AggregateConfigurationOptionsEx {
265
+ const nodePriv = node as any;
266
+
267
+ /* istanbul ignore next */
268
+ if (!nodePriv.$historicalDataConfiguration) {
269
+ throw new Error("internal error");
270
+ }
271
+ const aggregateConfiguration = nodePriv.$historicalDataConfiguration.aggregateConfiguration;
272
+
273
+ // Beware ! Stepped value comes from Historical Configuration !
274
+ const stepped = nodePriv.$historicalDataConfiguration.stepped.readValue().value.value;
275
+
276
+ return {
277
+ percentDataBad: aggregateConfiguration.percentDataBad.readValue().value.value,
278
+ percentDataGood: aggregateConfiguration.percentDataGood.readValue().value.value,
279
+ stepped,
280
+ treatUncertainAsBad: aggregateConfiguration.treatUncertainAsBad.readValue().value.value,
281
+ // xx stepped: aggregateConfiguration.stepped.readValue().value,
282
+ useSlopedExtrapolation: aggregateConfiguration.useSlopedExtrapolation.readValue().value.value
283
+ };
284
+ }