UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for MindSphere Connectivity - TypeScript SDK for MindSphere - MindSphere Command Line Interface - MindSphere Development Proxy

265 lines 9.09 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const chai = require("chai"); require("url-search-params-polyfill"); const sdk_1 = require("../src/api/sdk"); const kpi_models_1 = require("../src/api/sdk/kpi/kpi-models"); const utils_1 = require("../src/api/utils"); const test_utils_1 = require("./test-utils"); chai.should(); describe("[SDK] KPICalculationClient", () => { const auth = (0, utils_1.loadAuth)(); const sdk = new sdk_1.MindSphereSdk(Object.assign(Object.assign({}, auth), { basicAuth: (0, utils_1.decrypt)(auth, (0, test_utils_1.getPasskeyForUnitTest)()) })); const kpiCalculationClient = sdk.GetKPICalculationClient(); const data = [ { _time: "2017-05-04T00:00:00.000Z", }, { _time: "2017-05-04T00:30:00.000Z", }, { _time: "2017-05-04T01:00:00.000Z", kpistatus: "UNKNOWN", }, { _time: "2017-05-04T01:30:00.000Z", kpistatus: "UNKNOWN", }, { _time: "2017-05-04T02:00:00.000Z", kpistatus: "UNKNOWN", }, { _time: "2017-05-04T02:30:00.000Z", kpistatus: "SH", }, { _time: "2017-05-04T03:00:00.000Z", kpistatus: "SH", }, { _time: "2017-05-04T03:30:00.000Z", kpistatus: "POH", }, { _time: "2017-05-04T04:00:00.000Z", kpistatus: "SH", }, { _time: "2017-05-04T04:30:00.000Z", kpistatus: "SH", }, { _time: "2017-05-04T05:00:00.000Z", kpistatus: "POH", }, { _time: "2017-05-04T05:30:00.000Z", }, { _time: "2017-05-04T06:00:00.000Z", }, { _time: "2017-05-04T06:30:00.000Z", kpistatus: "UNKNOWN", }, { _time: "2017-05-04T07:00:00.000Z", kpistatus: "FOH", }, { _time: "2017-05-04T07:30:00.000Z", kpistatus: "FOH", }, { _time: "2017-05-04T08:00:00.000Z", kpistatus: "POH", }, ]; const stateCalculationData = { ControlSystemEvents: [ { _time: "2017-01-01T01:29:57.000Z", type: kpi_models_1.KPICalculationModels.ControlSystemEvent.TypeEnum.NORMALSTOP, }, { _time: "2017-01-01T01:30:00.000Z", type: kpi_models_1.KPICalculationModels.ControlSystemEvent.TypeEnum.SHUTDOWN, }, { _time: "2017-01-01T04:30:01.000Z", type: kpi_models_1.KPICalculationModels.ControlSystemEvent.TypeEnum.SHUTDOWN, }, ], calendar: { PlannedOutage: [ { from: "2017-01-01T10:00:00.000Z", to: "2017-01-01T11:00:00.000Z", }, { from: "2017-01-01T06:00:00.000Z", to: "2017-01-01T07:00:00.000Z", }, { from: "2017-01-01T00:00:00.000Z", to: "2017-01-01T01:00:00.000Z", }, { from: "2017-01-01T04:00:00.000Z", to: "2017-01-01T05:00:00.000Z", }, { from: "2017-01-01T02:00:00.000Z", to: "2017-01-01T03:00:00.000Z", }, { from: "2017-01-01T08:00:00.000Z", to: "2017-01-01T09:00:00.000Z", }, { from: "2016-12-31T22:00:00.000Z", to: "2016-12-31T23:00:00.000Z", }, { from: "2017-01-01T03:00:00.000Z", to: "2017-01-01T04:00:00.000Z", }, ], }, timeseries: [ { _time: "2017-01-01T00:10:00.000Z", sensor: "2.0", sensor1: "2.0", }, { _time: "2017-01-01T00:50:00.000Z", sensor: "1.0", }, { _time: "2017-01-01T01:00:00.000Z", sensor: "2.0", }, { _time: "2017-01-01T01:30:00.000Z", sensor: "1.0", }, { _time: "2017-01-01T02:00:00.000Z", sensor: "2.0", }, { _time: "2017-01-01T03:00:00.000Z", sensor: "1.0", }, { _time: "2017-01-01T03:30:00.000Z", sensor: "2.0", }, { _time: "2017-01-01T04:30:00.000Z", sensor: "1.0", }, { _time: "2017-01-01T05:10:00.000Z", sensor: "1.0", }, { _time: "2017-01-01T05:30:00.000Z", sensor1: "1.0", }, { _time: "2017-01-01T05:50:00.000Z", sensor: "2.0", }, { _time: "2017-01-01T06:30:00.000Z", sensor2: "3.0", }, { _time: "2017-01-01T07:10:00.000Z", sensor: "1.0", }, { _time: "2017-01-01T07:20:00.000Z", sensor: "2.0", }, ], }; it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; kpiCalculationClient.should.not.be.undefined; })); it("should calculate kpis", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; kpiCalculationClient.should.not.be.undefined; const from = new Date(); from.setDate(from.getDate() - 2); // console.log(data); const result = yield kpiCalculationClient.ComputeKPI(data, { from: new Date(data[0]["_time"]), to: new Date(data[data.length - 1]["_time"]), variableName: "kpiStatus", initialState: "RSH", }); result.should.not.be.undefined; })); it("should calculate KPI states", () => __awaiter(void 0, void 0, void 0, function* () { sdk.should.not.be.undefined; kpiCalculationClient.should.not.be.undefined; const from = new Date(); from.setDate(from.getDate() - 2); // console.log(data); const result = yield kpiCalculationClient.CaclulateKpiStates(stateCalculationData, { from: new Date(data[0]["_time"]), to: new Date(data[data.length - 1]["_time"]), variableName: "kpiStatus", initialState: "RSH", defaultState: "FOH", threshold: 1.1, shutdownCorrelationThreshold: 5000, }); result.should.not.be.undefined; })); it("should calculate KPI states using direct method", () => __awaiter(void 0, void 0, void 0, function* () { var _a; sdk.should.not.be.undefined; kpiCalculationClient.should.not.be.undefined; if (process.env.CI) { return; } const today = new Date(); const yesterday = new Date(today); yesterday.setDate(yesterday.getDate() - 1); const from = new Date(); from.setDate(from.getDate() - 2); const result = yield kpiCalculationClient.CalculateKpiStatesDirect({ calendar: {}, ControlSystemEvents: [], }, { from: yesterday, to: today, variableName: "Temperature", assetId: "4e268313c91d4dbebade263322f55369", aspectName: "Environment", initialState: "POH", defaultState: "SH", threshold: 1.1, shutdownCorrelationThreshold: 3000, }); result.should.not.be.undefined; (_a = result.indications) === null || _a === void 0 ? void 0 : _a.length.should.be.greaterThan(0); })); }); //# sourceMappingURL=kpi-calculation.spec.js.map