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 | const command_utils_1 = require("../src/cli/commands/command-utils");
|
17 | chai.should();
|
18 | describe("[SDK] SignalValidationClient", () => {
|
19 | const auth = utils_1.loadAuth();
|
20 | const sdk = new sdk_1.MindSphereSdk({
|
21 | basicAuth: utils_1.decrypt(auth, "passkey.4.unit.test"),
|
22 | tenant: auth.tenant,
|
23 | gateway: auth.gateway
|
24 | });
|
25 | const signalValidationClient = sdk.GetSignalValidationClient();
|
26 | it("SDK should not be undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
27 | sdk.should.not.be.undefined;
|
28 | signalValidationClient.should.not.be.undefined;
|
29 | }));
|
30 | it("Signal Validation should perform a Range Check.", () => __awaiter(void 0, void 0, void 0, function* () {
|
31 | sdk.should.not.be.undefined;
|
32 | signalValidationClient.should.not.be.undefined;
|
33 | const data = command_utils_1.generateTestData(100, x => {
|
34 | return x === 31 ? 120 : Math.sin(x);
|
35 | });
|
36 | const result = yield signalValidationClient.DetectRangeViolations(data, {
|
37 | variableName: "variable1",
|
38 | lowerLimit: -1,
|
39 | upperLimit: 1
|
40 | });
|
41 | result.should.not.be.null;
|
42 | result.length.should.be.equal(1);
|
43 | }));
|
44 | it("Signal Validation should perform a Spike Alert.", () => __awaiter(void 0, void 0, void 0, function* () {
|
45 | const data = command_utils_1.generateTestData(100, x => {
|
46 | return x >= 40 && x <= 42 ? 13 * Math.sin(x) : Math.sin(x);
|
47 | });
|
48 | const result = yield signalValidationClient.DetectSpikes(data, {
|
49 | variableName: "variable1",
|
50 | windowSize: 20
|
51 | });
|
52 | result.length.should.be.equal(2);
|
53 | }));
|
54 | it("Signal Validation should perform Jump Detection.", () => __awaiter(void 0, void 0, void 0, function* () {
|
55 | const data = command_utils_1.generateTestData(100, x => {
|
56 | return x >= 84 && x <= 85 ? 500 * Math.cos(x) : Math.sin(x);
|
57 | });
|
58 | const result = yield signalValidationClient.DetectJumps(data, {
|
59 | variableName: "variable1",
|
60 | windowSize: 10
|
61 | });
|
62 | result.length.should.be.equal(2);
|
63 | }));
|
64 | it("Signal Validation should perform Noise Setection.", () => __awaiter(void 0, void 0, void 0, function* () {
|
65 | const data = command_utils_1.generateTestData(1000, x => {
|
66 | return x % 100 >= 90 && x % 100 <= 100 ? Math.sin(x) * 3.15 : Math.sin(x);
|
67 | });
|
68 | const result = yield signalValidationClient.DetectNoise(data, {
|
69 | variableName: "variable1",
|
70 | windowRadius: 3,
|
71 | threshold: 1
|
72 | });
|
73 | result.length.should.be.equal(7);
|
74 | }));
|
75 | it("Signal Validation should detect Data Gaps.", () => __awaiter(void 0, void 0, void 0, function* () {
|
76 | const data = command_utils_1.generateTestData(1000, x => {
|
77 | if (x % 100 === 80 || x % 100 === 81)
|
78 | return undefined;
|
79 | return Math.sin(x);
|
80 | });
|
81 | const result = yield signalValidationClient.DetectGaps(data, {
|
82 | variableName: "variable1",
|
83 | threshold: 1500
|
84 | });
|
85 | result.events.length.should.be.equal(20);
|
86 | }));
|
87 | it("Signal Validation should interpolate Data Gaps.", () => __awaiter(void 0, void 0, void 0, function* () {
|
88 | const data = command_utils_1.generateTestData(1000, x => {
|
89 | if (x % 100 === 80 || x % 100 === 81)
|
90 | return undefined;
|
91 | return Math.sin(x);
|
92 | });
|
93 | const result = yield signalValidationClient.DetectGapsAndInterpolate(data, {
|
94 | variableName: "variable1",
|
95 | threshold: 1500
|
96 | });
|
97 | result.events.length.should.be.equal(20);
|
98 | result.interpolatedMeasurements.length.should.be.equal(20);
|
99 | }));
|
100 | it("Signal Validation should detect Bias.", () => __awaiter(void 0, void 0, void 0, function* () {
|
101 | const data = command_utils_1.generateTestData(1000, x => {
|
102 | if (x % 100 >= 80 && x % 100 <= 85)
|
103 | return 4 * Math.sin(x);
|
104 | else
|
105 | return 4;
|
106 | });
|
107 | const result = yield signalValidationClient.DetectBias(data, {
|
108 | variableName: "variable1",
|
109 | windowSize: 20,
|
110 | step: 10,
|
111 | threshold: 3
|
112 | });
|
113 | result.length.should.equal(97);
|
114 | }));
|
115 | });
|
116 |
|
\ | No newline at end of file |