1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const chai = require("chai");
|
13 | require("url-search-params-polyfill");
|
14 | const sdk_1 = require("../src/api/sdk");
|
15 | const utils_1 = require("../src/api/utils");
|
16 | chai.should();
|
17 | describe("[SDK] KPICalculationClient", () => {
|
18 | const auth = utils_1.loadAuth();
|
19 | const sdk = new sdk_1.MindSphereSdk({
|
20 | basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"),
|
21 | tenant: auth.tenant,
|
22 | gateway: auth.gateway
|
23 | });
|
24 | const kpiCalculationClient = sdk.GetKPICalculationClient();
|
25 | const data = [
|
26 | {
|
27 | _time: "2017-05-04T00:00:00.000Z"
|
28 | },
|
29 | {
|
30 | _time: "2017-05-04T00:30:00.000Z"
|
31 | },
|
32 | {
|
33 | _time: "2017-05-04T01:00:00.000Z",
|
34 | kpistatus: "UNKNOWN"
|
35 | },
|
36 | {
|
37 | _time: "2017-05-04T01:30:00.000Z",
|
38 | kpistatus: "UNKNOWN"
|
39 | },
|
40 | {
|
41 | _time: "2017-05-04T02:00:00.000Z",
|
42 | kpistatus: "UNKNOWN"
|
43 | },
|
44 | {
|
45 | _time: "2017-05-04T02:30:00.000Z",
|
46 | kpistatus: "SH"
|
47 | },
|
48 | {
|
49 | _time: "2017-05-04T03:00:00.000Z",
|
50 | kpistatus: "SH"
|
51 | },
|
52 | {
|
53 | _time: "2017-05-04T03:30:00.000Z",
|
54 | kpistatus: "POH"
|
55 | },
|
56 | {
|
57 | _time: "2017-05-04T04:00:00.000Z",
|
58 | kpistatus: "SH"
|
59 | },
|
60 | {
|
61 | _time: "2017-05-04T04:30:00.000Z",
|
62 | kpistatus: "SH"
|
63 | },
|
64 | {
|
65 | _time: "2017-05-04T05:00:00.000Z",
|
66 | kpistatus: "POH"
|
67 | },
|
68 | {
|
69 | _time: "2017-05-04T05:30:00.000Z"
|
70 | },
|
71 | {
|
72 | _time: "2017-05-04T06:00:00.000Z"
|
73 | },
|
74 | {
|
75 | _time: "2017-05-04T06:30:00.000Z",
|
76 | kpistatus: "UNKNOWN"
|
77 | },
|
78 | {
|
79 | _time: "2017-05-04T07:00:00.000Z",
|
80 | kpistatus: "FOH"
|
81 | },
|
82 | {
|
83 | _time: "2017-05-04T07:30:00.000Z",
|
84 | kpistatus: "FOH"
|
85 | },
|
86 | {
|
87 | _time: "2017-05-04T08:00:00.000Z",
|
88 | kpistatus: "POH"
|
89 | }
|
90 | ];
|
91 | const stateCalculationData = {
|
92 | ControlSystemEvents: [
|
93 | {
|
94 | _time: "2017-01-01T01:29:57.000Z",
|
95 | type: "NORMAL_STOP"
|
96 | },
|
97 | {
|
98 | _time: "2017-01-01T01:30:00.000Z",
|
99 | type: "SHUTDOWN"
|
100 | },
|
101 | {
|
102 | _time: "2017-01-01T04:30:01.000Z",
|
103 | type: "SHUTDOWN"
|
104 | }
|
105 | ],
|
106 | calendar: {
|
107 | PlannedOutage: [
|
108 | {
|
109 | from: "2017-01-01T10:00:00.000Z",
|
110 | to: "2017-01-01T11:00:00.000Z"
|
111 | },
|
112 | {
|
113 | from: "2017-01-01T06:00:00.000Z",
|
114 | to: "2017-01-01T07:00:00.000Z"
|
115 | },
|
116 | {
|
117 | from: "2017-01-01T00:00:00.000Z",
|
118 | to: "2017-01-01T01:00:00.000Z"
|
119 | },
|
120 | {
|
121 | from: "2017-01-01T04:00:00.000Z",
|
122 | to: "2017-01-01T05:00:00.000Z"
|
123 | },
|
124 | {
|
125 | from: "2017-01-01T02:00:00.000Z",
|
126 | to: "2017-01-01T03:00:00.000Z"
|
127 | },
|
128 | {
|
129 | from: "2017-01-01T08:00:00.000Z",
|
130 | to: "2017-01-01T09:00:00.000Z"
|
131 | },
|
132 | {
|
133 | from: "2016-12-31T22:00:00.000Z",
|
134 | to: "2016-12-31T23:00:00.000Z"
|
135 | },
|
136 | {
|
137 | from: "2017-01-01T03:00:00.000Z",
|
138 | to: "2017-01-01T04:00:00.000Z"
|
139 | }
|
140 | ]
|
141 | },
|
142 | timeseries: [
|
143 | {
|
144 | _time: "2017-01-01T00:10:00.000Z",
|
145 | sensor: "2.0",
|
146 | sensor1: "2.0"
|
147 | },
|
148 | {
|
149 | _time: "2017-01-01T00:50:00.000Z",
|
150 | sensor: "1.0"
|
151 | },
|
152 | {
|
153 | _time: "2017-01-01T01:00:00.000Z",
|
154 | sensor: "2.0"
|
155 | },
|
156 | {
|
157 | _time: "2017-01-01T01:30:00.000Z",
|
158 | sensor: "1.0"
|
159 | },
|
160 | {
|
161 | _time: "2017-01-01T02:00:00.000Z",
|
162 | sensor: "2.0"
|
163 | },
|
164 | {
|
165 | _time: "2017-01-01T03:00:00.000Z",
|
166 | sensor: "1.0"
|
167 | },
|
168 | {
|
169 | _time: "2017-01-01T03:30:00.000Z",
|
170 | sensor: "2.0"
|
171 | },
|
172 | {
|
173 | _time: "2017-01-01T04:30:00.000Z",
|
174 | sensor: "1.0"
|
175 | },
|
176 | {
|
177 | _time: "2017-01-01T05:10:00.000Z",
|
178 | sensor: "1.0"
|
179 | },
|
180 | {
|
181 | _time: "2017-01-01T05:30:00.000Z",
|
182 | sensor1: "1.0"
|
183 | },
|
184 | {
|
185 | _time: "2017-01-01T05:50:00.000Z",
|
186 | sensor: "2.0"
|
187 | },
|
188 | {
|
189 | _time: "2017-01-01T06:30:00.000Z",
|
190 | sensor2: "3.0"
|
191 | },
|
192 | {
|
193 | _time: "2017-01-01T07:10:00.000Z",
|
194 | sensor: "1.0"
|
195 | },
|
196 | {
|
197 | _time: "2017-01-01T07:20:00.000Z",
|
198 | sensor: "2.0"
|
199 | }
|
200 | ]
|
201 | };
|
202 | it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
203 | sdk.should.not.be.undefined;
|
204 | kpiCalculationClient.should.not.be.undefined;
|
205 | }));
|
206 | it("should calculate kpis", () => __awaiter(void 0, void 0, void 0, function* () {
|
207 | sdk.should.not.be.undefined;
|
208 | kpiCalculationClient.should.not.be.undefined;
|
209 | const from = new Date();
|
210 | from.setDate(from.getDate() - 2);
|
211 |
|
212 | const result = yield kpiCalculationClient.ComputeKPI(data, {
|
213 | from: new Date(data[0]["_time"]),
|
214 | to: new Date(data[data.length - 1]["_time"]),
|
215 | variableName: "kpiStatus",
|
216 | initialState: "RSH"
|
217 | });
|
218 | result.should.not.be.undefined;
|
219 | }));
|
220 | it("should calculate KPI states", () => __awaiter(void 0, void 0, void 0, function* () {
|
221 | sdk.should.not.be.undefined;
|
222 | kpiCalculationClient.should.not.be.undefined;
|
223 | const from = new Date();
|
224 | from.setDate(from.getDate() - 2);
|
225 |
|
226 | const result = yield kpiCalculationClient.CaclulateKpiStates(stateCalculationData, {
|
227 | from: new Date(data[0]["_time"]),
|
228 | to: new Date(data[data.length - 1]["_time"]),
|
229 | variableName: "kpiStatus",
|
230 | initialState: "RSH",
|
231 | defaultState: "FOH",
|
232 | threshold: 1.1,
|
233 | shutdownCorrelationThreshold: 5000
|
234 | });
|
235 | result.should.not.be.undefined;
|
236 | }));
|
237 | });
|
238 |
|
\ | No newline at end of file |