node-opcua-aggregates 2.51.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/.mocharc.yml +7 -0
- package/LICENSE +20 -0
- package/bin/sample_aggregate_server.js +15 -0
- package/dist/aggregates.d.ts +7 -0
- package/dist/aggregates.js +201 -0
- package/dist/aggregates.js.map +1 -0
- package/dist/average.d.ts +3 -0
- package/dist/average.js +61 -0
- package/dist/average.js.map +1 -0
- package/dist/common.d.ts +8 -0
- package/dist/common.js +90 -0
- package/dist/common.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/interpolate.d.ts +16 -0
- package/dist/interpolate.js +135 -0
- package/dist/interpolate.js.map +1 -0
- package/dist/interval.d.ts +49 -0
- package/dist/interval.js +165 -0
- package/dist/interval.js.map +1 -0
- package/dist/minmax.d.ts +18 -0
- package/dist/minmax.js +149 -0
- package/dist/minmax.js.map +1 -0
- package/dist/read_processed_details.d.ts +6 -0
- package/dist/read_processed_details.js +116 -0
- package/dist/read_processed_details.js.map +1 -0
- package/nyc.config.js +16 -0
- package/package.json +51 -0
- package/source/aggregates.ts +277 -0
- package/source/average.ts +74 -0
- package/source/common.ts +118 -0
- package/source/index.ts +17 -0
- package/source/interpolate.ts +201 -0
- package/source/interval.ts +199 -0
- package/source/minmax.ts +231 -0
- package/source/read_processed_details.ts +139 -0
package/.mocharc.yml
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const opcua = require("node-opcua");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const server = new opcua.OPCUAServer({
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
const { addAggregateSupport } = require("..");
|
|
8
|
+
|
|
9
|
+
server.start(function(err){
|
|
10
|
+
|
|
11
|
+
addAggregateSupport(server.engine.addressSpace);
|
|
12
|
+
|
|
13
|
+
console.log("err= ",err);
|
|
14
|
+
|
|
15
|
+
});
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +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 (!defaultProperties.hasOwnProperty(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 (!historyServerCapabilities.hasOwnProperty(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
|
+
//# sourceMappingURL=aggregates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregates.js","sourceRoot":"","sources":["../source/aggregates.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+DAAyD;AACzD,yDAA+C;AAC/C,0CAA0C;AAC1C,2DAA8C;AAK9C,qEAAgE;AAEhE,iEAAiE;AAEjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,uCAAuC,CAAC,gCAAgC,GAAG;IAC7E,2BAA2B,EAAE,IAAI;IACjC,6BAA6B,EAAE,IAAI;IACnC,sBAAsB,EAAE,KAAK;IAC7B,qBAAqB,EAAE,KAAK;IAC5B,mBAAmB,EAAE,KAAK;IAC1B,0BAA0B,EAAE,KAAK;IACjC,oBAAoB,EAAE,KAAK;IAC3B,qBAAqB,EAAE,KAAK;IAC5B,mBAAmB,EAAE,CAAC;IACtB,oBAAoB,EAAE,CAAC;IACvB,qBAAqB,EAAE,KAAK;IAC5B,sBAAsB,EAAE,KAAK;IAC7B,oBAAoB,EAAE,KAAK;IAC3B,qBAAqB,EAAE,KAAK,CAAC,iCAAiC;CACjE,CAAC;AAEF,SAAgB,+BAA+B,CAAC,YAA0B,EAAE,kBAAwC;IAChH,0BAA0B;IAC1B,IAAI,kBAAkB,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,oBAAoB,EAAE;QACnE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KACpD;IAED,MAAM,6BAA6B,GAAG,YAAY,C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C,CAAC,CAAC;IACH,sBAAsB,CAAC,sBAAsB,CAAC,kBAAkB,CAAC;QAC7D,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,OAAO,CAAC,sBAAsB;KACxC,CAAC,CAAC;IAEH,QAAQ,CAAC,4BAA4B,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAC7D,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;AACP,CAAC;AAlBD,oFAkBC;AAED,SAAgB,yBAAyB,CAAC,IAAc;IACpD,MAAM,QAAQ,GAAG,IAAW,CAAC;IAE7B,0BAA0B;IAC1B,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAAE;QACxC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;KACrC;IACD,MAAM,sBAAsB,GAAG,QAAQ,CAAC,4BAA4B,CAAC,sBAAsB,CAAC;IAE5F,+DAA+D;IAC/D,MAAM,OAAO,GAAG,QAAQ,CAAC,4BAA4B,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;IAEtF,OAAO;QACH,cAAc,EAAE,sBAAsB,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,KAAK;QAC7E,eAAe,EAAE,sBAAsB,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,KAAK;QAC/E,OAAO;QACP,mBAAmB,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,KAAK;QACvF,+EAA+E;QAC/E,sBAAsB,EAAE,sBAAsB,CAAC,sBAAsB,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,KAAK;KAChG,CAAC;AACN,CAAC;AApBD,8DAoBC"}
|
|
@@ -0,0 +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;
|
package/dist/average.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 common_1 = require("./common");
|
|
7
|
+
const interval_1 = require("./interval");
|
|
8
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
9
|
+
function calculateIntervalAverageValue(interval, options) {
|
|
10
|
+
const indexStart = interval.index;
|
|
11
|
+
let statusCode;
|
|
12
|
+
let isPartial = interval.isPartial;
|
|
13
|
+
let 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, value: mean
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function getAverageData(node, processingInterval, startDate, endDate, callback) {
|
|
58
|
+
return (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, calculateIntervalAverageValue, callback);
|
|
59
|
+
}
|
|
60
|
+
exports.getAverageData = getAverageData;
|
|
61
|
+
//# sourceMappingURL=average.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"average.js","sourceRoot":"","sources":["../source/average.ts"],"names":[],"mappings":";;;AACA,iEAAkD;AAClD,2DAAuD;AACvD,qCAA4C;AAC5C,yCAA6E;AAC7E,mEAAiE;AAEjE,SAAS,6BAA6B,CAClC,QAAkB,EAClB,OAAsC;IAGtC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC;IAClC,IAAI,UAAsB,CAAC;IAC3B,IAAI,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;IAEnC,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,IAAI,CAAC,GAAG,UAAU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U,EAAE,UAAwB;QACpC,KAAK,EAAE;YACH,QAAQ,EAAE,6BAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI;SACzC;KACJ,CAAC,CAAC;AACP,CAAC;AAED,SAAgB,cAAc,CAC1B,IAAgB,EAChB,kBAA0B,EAC1B,SAAe,EACf,OAAa,EACb,QAA+D;IAE/D,OAAO,IAAA,yBAAgB,EAAC,IAAI,EAAE,kBAAkB,EAAE,SAAS,EAAE,OAAO,EAAE,6BAA6B,EAAE,QAAQ,CAAC,CAAC;AACnH,CAAC;AARD,wCAQC"}
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +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;
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interpolateValue = exports.getAggregateData = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opca-aggregates
|
|
6
|
+
*/
|
|
7
|
+
const node_opcua_address_space_1 = require("node-opcua-address-space");
|
|
8
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
9
|
+
const node_opcua_data_value_1 = require("node-opcua-data-value");
|
|
10
|
+
const node_opcua_service_history_1 = require("node-opcua-service-history");
|
|
11
|
+
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
12
|
+
const aggregates_1 = require("./aggregates");
|
|
13
|
+
const interval_1 = require("./interval");
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
* @param node
|
|
17
|
+
* @param processingInterval
|
|
18
|
+
* @param startDate
|
|
19
|
+
* @param endDate
|
|
20
|
+
* @param dataValues
|
|
21
|
+
* @param lambda
|
|
22
|
+
* @param callback
|
|
23
|
+
*/
|
|
24
|
+
function processAggregateData(node, processingInterval, startDate, endDate, dataValues, lambda, callback) {
|
|
25
|
+
const aggregateConfiguration = (0, aggregates_1.getAggregateConfiguration)(node);
|
|
26
|
+
const results = [];
|
|
27
|
+
const tstart = startDate.getTime();
|
|
28
|
+
const tend = endDate.getTime();
|
|
29
|
+
const indexHint = 0;
|
|
30
|
+
for (let t = tstart; t < tend; t += processingInterval) {
|
|
31
|
+
const sourceTimestamp = new Date();
|
|
32
|
+
sourceTimestamp.setTime(t);
|
|
33
|
+
const interval = (0, interval_1.getInterval)(sourceTimestamp, processingInterval, indexHint, dataValues);
|
|
34
|
+
const dataValue = lambda(interval, aggregateConfiguration);
|
|
35
|
+
/* istanbul ignore next */
|
|
36
|
+
if (!dataValue || !dataValue.sourceTimestamp) {
|
|
37
|
+
// const dataValue = interval.interpolatedValue(aggregateConfiguration);
|
|
38
|
+
throw Error("invalid DataValue");
|
|
39
|
+
}
|
|
40
|
+
results.push(dataValue);
|
|
41
|
+
}
|
|
42
|
+
setImmediate(() => {
|
|
43
|
+
callback(null, results);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function getAggregateData(node, processingInterval, startDate, endDate, lambda, callback) {
|
|
47
|
+
/* istanbul ignore next */
|
|
48
|
+
if (node.nodeClass !== node_opcua_data_model_1.NodeClass.Variable) {
|
|
49
|
+
throw new Error("node must be UAVariable");
|
|
50
|
+
}
|
|
51
|
+
/* istanbul ignore next */
|
|
52
|
+
if (processingInterval <= 0) {
|
|
53
|
+
throw new Error("Invalid processing interval, shall be greater than 0");
|
|
54
|
+
}
|
|
55
|
+
const context = new node_opcua_address_space_1.SessionContext();
|
|
56
|
+
const historyReadDetails = new node_opcua_service_history_1.ReadRawModifiedDetails({
|
|
57
|
+
endTime: endDate,
|
|
58
|
+
startTime: startDate,
|
|
59
|
+
});
|
|
60
|
+
const indexRange = null;
|
|
61
|
+
const dataEncoding = null;
|
|
62
|
+
const continuationPoint = null;
|
|
63
|
+
node.historyRead(context, historyReadDetails, indexRange, dataEncoding, continuationPoint, (err, result) => {
|
|
64
|
+
/* istanbul ignore next */
|
|
65
|
+
if (err) {
|
|
66
|
+
return callback(err);
|
|
67
|
+
}
|
|
68
|
+
const historyData = result.historyData;
|
|
69
|
+
const dataValues = historyData.dataValues || [];
|
|
70
|
+
processAggregateData(node, processingInterval, startDate, endDate, dataValues, lambda, callback);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.getAggregateData = getAggregateData;
|
|
74
|
+
function interpolateValue(dataValue1, dataValue2, date) {
|
|
75
|
+
const t0 = dataValue1.sourceTimestamp.getTime();
|
|
76
|
+
const t = date.getTime();
|
|
77
|
+
const t1 = dataValue2.sourceTimestamp.getTime();
|
|
78
|
+
const coef1 = (t - t0) / (t1 - t0);
|
|
79
|
+
const coef2 = (t1 - t) / (t1 - t0);
|
|
80
|
+
const value = dataValue1.value.clone();
|
|
81
|
+
value.value = coef2 * dataValue1.value.value + coef1 * dataValue2.value.value;
|
|
82
|
+
const statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(dataValue1.statusCode, "HistorianInterpolated");
|
|
83
|
+
return new node_opcua_data_value_1.DataValue({
|
|
84
|
+
sourceTimestamp: date,
|
|
85
|
+
statusCode,
|
|
86
|
+
value
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.interpolateValue = interpolateValue;
|
|
90
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../source/common.ts"],"names":[],"mappings":";;;AA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C;IACzB,MAAM,EAAE,GAAG,UAAU,CAAC,eAAgB,CAAC,OAAO,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvC,KAAK,CAAC,KAAK,GAAG,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC;IAC9E,MAAM,UAAU,GAAG,mCAAU,CAAC,cAAc,CAAC,UAAU,CAAC,UAAU,EAAE,uBAAuB,CAAC,CAAC;IAC7F,OAAO,IAAI,iCAAS,CAAC;QACjB,eAAe,EAAE,IAAI;QACrB,UAAU;QACV,KAAK;KACR,CAAC,CAAC;AACP,CAAC;AAdD,4CAcC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opca-aggregates
|
|
3
|
+
*/
|
|
4
|
+
export { addAggregateSupport, installAggregateConfigurationOptions, getAggregateConfiguration, } from "./aggregates";
|
|
5
|
+
export * from "./interpolate";
|
|
6
|
+
export * from "./minmax";
|
|
7
|
+
export * from "./interval";
|
|
8
|
+
export * from "./common";
|
|
9
|
+
export * from "./average";
|
|
10
|
+
export * from "./read_processed_details";
|
|
11
|
+
export { AggregateFunction } from "node-opcua-constants";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AggregateFunction = exports.getAggregateConfiguration = exports.installAggregateConfigurationOptions = exports.addAggregateSupport = void 0;
|
|
14
|
+
/**
|
|
15
|
+
* @module node-opca-aggregates
|
|
16
|
+
*/
|
|
17
|
+
var aggregates_1 = require("./aggregates");
|
|
18
|
+
Object.defineProperty(exports, "addAggregateSupport", { enumerable: true, get: function () { return aggregates_1.addAggregateSupport; } });
|
|
19
|
+
Object.defineProperty(exports, "installAggregateConfigurationOptions", { enumerable: true, get: function () { return aggregates_1.installAggregateConfigurationOptions; } });
|
|
20
|
+
Object.defineProperty(exports, "getAggregateConfiguration", { enumerable: true, get: function () { return aggregates_1.getAggregateConfiguration; } });
|
|
21
|
+
__exportStar(require("./interpolate"), exports);
|
|
22
|
+
__exportStar(require("./minmax"), exports);
|
|
23
|
+
__exportStar(require("./interval"), exports);
|
|
24
|
+
__exportStar(require("./common"), exports);
|
|
25
|
+
__exportStar(require("./average"), exports);
|
|
26
|
+
__exportStar(require("./read_processed_details"), exports);
|
|
27
|
+
var node_opcua_constants_1 = require("node-opcua-constants");
|
|
28
|
+
Object.defineProperty(exports, "AggregateFunction", { enumerable: true, get: function () { return node_opcua_constants_1.AggregateFunction; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;GAEG;AACH,2CAIsB;AAHlB,iHAAA,mBAAmB,OAAA;AACnB,kIAAA,oCAAoC,OAAA;AACpC,uHAAA,yBAAyB,OAAA;AAE7B,gDAA8B;AAC9B,2CAAyB;AACzB,6CAA2B;AAC3B,2CAAyB;AACzB,4CAA0B;AAC1B,2DAAyC;AACzC,6DAE8B;AAD1B,yHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { AggregateConfigurationOptionsEx, Interval } from "./interval";
|
|
7
|
+
export declare function interpolatedValue(interval: Interval, options: AggregateConfigurationOptionsEx): DataValue;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param node
|
|
11
|
+
* @param processingInterval
|
|
12
|
+
* @param startDate
|
|
13
|
+
* @param endDate
|
|
14
|
+
* @param callback
|
|
15
|
+
*/
|
|
16
|
+
export declare function getInterpolatedData(node: UAVariable, processingInterval: number, startDate: Date, endDate: Date, callback: (err: Error | null, dataValues?: DataValue[]) => void): void;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInterpolatedData = exports.interpolatedValue = void 0;
|
|
4
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
5
|
+
const node_opcua_data_value_1 = require("node-opcua-data-value");
|
|
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
|
+
/*
|
|
10
|
+
For any intervals containing regions where the StatusCodes are Bad,
|
|
11
|
+
the total duration of all Bad regions is calculated and divided by the width of the interval.
|
|
12
|
+
The resulting ratio is multiplied by 100 and compared to the PercentDataBad parameter.
|
|
13
|
+
The StatusCode for the interval is Bad if the ratio is greater than or equal to the PercentDataBad parameter.
|
|
14
|
+
For any interval which is not Bad, the total duration of all Good regions is then calculated and divided by
|
|
15
|
+
the width of the interval. The resulting ratio is multiplied by 100 and compared to the PercentDataGood parameter.
|
|
16
|
+
The StatusCode for the interval is Good if the ratio is greater than or equal to the PercentDataGood parameter.
|
|
17
|
+
If for an interval neither ratio applies then that interval is Uncertain_DataSubNormal.
|
|
18
|
+
*/
|
|
19
|
+
function interpolatedValue(interval, options) {
|
|
20
|
+
options = (0, interval_1.adjustProcessingOptions)(options);
|
|
21
|
+
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "useSlopedExtrapolation"));
|
|
22
|
+
(0, node_opcua_assert_1.assert)(Object.prototype.hasOwnProperty.call(options, "treatUncertainAsBad"));
|
|
23
|
+
const bTreatUncertainAsBad = options.treatUncertainAsBad;
|
|
24
|
+
const steppedValue = (previousDataValue) => {
|
|
25
|
+
if (!previousDataValue.statusCode) {
|
|
26
|
+
throw new Error("Expecting statusCode");
|
|
27
|
+
}
|
|
28
|
+
const interpValue = new node_opcua_data_value_1.DataValue({
|
|
29
|
+
sourceTimestamp: interval.startTime,
|
|
30
|
+
statusCode: node_opcua_status_code_1.StatusCodes.Bad,
|
|
31
|
+
value: previousDataValue.value,
|
|
32
|
+
});
|
|
33
|
+
interpValue.statusCode =
|
|
34
|
+
node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, "HistorianInterpolated");
|
|
35
|
+
return interpValue;
|
|
36
|
+
};
|
|
37
|
+
if (interval.index === -1) {
|
|
38
|
+
// the interval is beyond end Data
|
|
39
|
+
// we need to find previous good value
|
|
40
|
+
// and second previous good value to extrapolate
|
|
41
|
+
const prev1 = (0, interval_1._findGoodDataValueBefore)(interval.dataValues, interval.dataValues.length, bTreatUncertainAsBad);
|
|
42
|
+
if (prev1.index <= 0) {
|
|
43
|
+
return new node_opcua_data_value_1.DataValue({
|
|
44
|
+
sourceTimestamp: interval.startTime,
|
|
45
|
+
statusCode: node_opcua_status_code_1.StatusCodes.BadNoData,
|
|
46
|
+
value: undefined,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (!options.useSlopedExtrapolation) {
|
|
50
|
+
return steppedValue(prev1.dataValue);
|
|
51
|
+
}
|
|
52
|
+
const prev2 = (0, interval_1._findGoodDataValueBefore)(interval.dataValues, prev1.index, bTreatUncertainAsBad);
|
|
53
|
+
if (prev2.index <= 0) {
|
|
54
|
+
// use step value
|
|
55
|
+
return steppedValue(prev1.dataValue);
|
|
56
|
+
}
|
|
57
|
+
// else interpolate
|
|
58
|
+
const interpVal = (0, common_1.interpolateValue)(prev2.dataValue, prev1.dataValue, interval.startTime);
|
|
59
|
+
// tslint:disable:no-bitwise
|
|
60
|
+
if (prev2.index + 1 < prev1.index || prev1.index < interval.dataValues.length - 1) {
|
|
61
|
+
// some bad data exist in between = change status code
|
|
62
|
+
const mask = 0x0000FFFFFF;
|
|
63
|
+
const extraBits = interpVal.statusCode.value & mask;
|
|
64
|
+
interpVal.statusCode = node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, extraBits);
|
|
65
|
+
}
|
|
66
|
+
return interpVal;
|
|
67
|
+
}
|
|
68
|
+
/* istanbul ignore next */
|
|
69
|
+
if (interval.index < 0 && interval.count === 0) {
|
|
70
|
+
return new node_opcua_data_value_1.DataValue({
|
|
71
|
+
sourceTimestamp: interval.startTime,
|
|
72
|
+
statusCode: node_opcua_status_code_1.StatusCodes.BadNoData
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const dataValue1 = interval.dataValues[interval.index];
|
|
76
|
+
// if a non-Bad Raw value exists at the timestamp then it is the bounding value;
|
|
77
|
+
if (!(0, interval_1.isBad)(dataValue1.statusCode) && interval.hasRawDataAsStart()) {
|
|
78
|
+
return dataValue1;
|
|
79
|
+
}
|
|
80
|
+
// find the first non-Bad Raw value before the timestamp;
|
|
81
|
+
// find previous good value
|
|
82
|
+
const before = interval.beforeStartDataValue(bTreatUncertainAsBad);
|
|
83
|
+
if ((0, interval_1.isBad)(before.dataValue.statusCode)) {
|
|
84
|
+
return new node_opcua_data_value_1.DataValue({
|
|
85
|
+
sourceTimestamp: interval.startTime,
|
|
86
|
+
statusCode: node_opcua_status_code_1.StatusCodes.BadNoData
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (options.stepped) {
|
|
90
|
+
if (before.index + 1 === interval.index) {
|
|
91
|
+
return new node_opcua_data_value_1.DataValue({
|
|
92
|
+
sourceTimestamp: interval.startTime,
|
|
93
|
+
statusCode: node_opcua_status_code_1.StatusCode.makeStatusCode(before.dataValue.statusCode, "HistorianInterpolated"),
|
|
94
|
+
value: before.dataValue.value
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return steppedValue(before.dataValue);
|
|
98
|
+
}
|
|
99
|
+
// find the first non-Bad Raw value after the timestamp;
|
|
100
|
+
const next = interval.nextStartDataValue(bTreatUncertainAsBad);
|
|
101
|
+
// draw a line between before value and after value;
|
|
102
|
+
// use point where the line crosses the timestamp as an estimate of the bounding value.
|
|
103
|
+
// The calculation can be expressed with the following formula:
|
|
104
|
+
// V bound = (T bound – T before)x( V after – V before)/( T after – T before) + V before
|
|
105
|
+
// where V
|
|
106
|
+
// x is a value at ‘x’ and Tx is the timestamp associated with Vx.
|
|
107
|
+
const interpolatedDataValue = (0, common_1.interpolateValue)(before.dataValue, next.dataValue, interval.startTime);
|
|
108
|
+
if (before.index + 1 < next.index
|
|
109
|
+
|| !(0, interval_1.isGood)(next.dataValue.statusCode)
|
|
110
|
+
|| !(0, interval_1.isGood)(before.dataValue.statusCode)) {
|
|
111
|
+
// tslint:disable:no-bitwise
|
|
112
|
+
// some bad data exist in between = change status code
|
|
113
|
+
const mask = 0x0000FFFFFF;
|
|
114
|
+
const extraBits = interpolatedDataValue.statusCode.value & mask;
|
|
115
|
+
interpolatedDataValue.statusCode =
|
|
116
|
+
node_opcua_status_code_1.StatusCode.makeStatusCode(node_opcua_status_code_1.StatusCodes.UncertainDataSubNormal, extraBits);
|
|
117
|
+
}
|
|
118
|
+
// check if uncertain or bad value exist between before/next
|
|
119
|
+
// todo
|
|
120
|
+
return interpolatedDataValue;
|
|
121
|
+
}
|
|
122
|
+
exports.interpolatedValue = interpolatedValue;
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
* @param node
|
|
126
|
+
* @param processingInterval
|
|
127
|
+
* @param startDate
|
|
128
|
+
* @param endDate
|
|
129
|
+
* @param callback
|
|
130
|
+
*/
|
|
131
|
+
function getInterpolatedData(node, processingInterval, startDate, endDate, callback) {
|
|
132
|
+
return (0, common_1.getAggregateData)(node, processingInterval, startDate, endDate, interpolatedValue, callback);
|
|
133
|
+
}
|
|
134
|
+
exports.getInterpolatedData = getInterpolatedData;
|
|
135
|
+
//# sourceMappingURL=interpolate.js.map
|