@mindconnect/mindconnect-nodejs
Version:
NodeJS Library for MindSphere Connectivity - TypeScript SDK for MindSphere - MindSphere Command Line Interface - MindSphere Development Proxy
277 lines • 10.8 kB
JavaScript
;
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 utils_1 = require("../src/api/utils");
const test_utils_1 = require("./test-utils");
chai.should();
describe("[SDK] EventAnalytics Client", () => {
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 eventAnalytics = sdk.GetEventAnalyticsClient();
it("should instantiate", () => __awaiter(void 0, void 0, void 0, function* () {
eventAnalytics.should.not.be.undefined;
}));
it("should find top events", () => __awaiter(void 0, void 0, void 0, function* () {
const example = {
eventsMetadata: {
eventTextPropertyName: "text",
},
events: [
{
_time: "2017-10-01T12:00:00.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:01.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:02.001Z",
text: "Status@Flame On",
text_qc: 0,
},
],
numberOfTopPositionsRequired: 5,
};
const result = yield eventAnalytics.FindTopEvents(example);
result.should.not.be.undefined;
result.length.should.equal(2);
}));
it("should filter events", () => __awaiter(void 0, void 0, void 0, function* () {
const data = {
eventsMetadata: {
eventTextPropertyName: "text",
},
events: [
{
_time: "2017-10-01T12:00:00.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:01.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:02.001Z",
text: "Status@Flame Off",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:03.001Z",
text: "Error code: 340",
text_qc: 0,
},
],
filterList: ["INTRODUCING FUEL", "MEANINGLESS ALARM", "Status@Flame On"],
};
const result = yield eventAnalytics.FilterEvents(data);
result.should.not.be.undefined;
result.output.length.should.equal(2);
}));
it("should count events", () => __awaiter(void 0, void 0, void 0, function* () {
const data = {
eventsMetadata: {
eventTextPropertyName: "text",
splitInterval: 5000,
},
events: [
{
_time: "2017-10-01T12:00:00.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:01.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:02.001Z",
text: "Status@Flame Off",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:03.001Z",
text: "Error code: 340",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:04.001Z",
text: "Error code: 340",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:06.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:08.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:09.001Z",
text: "Status@Flame Off",
text_qc: 0,
},
],
};
const result = yield eventAnalytics.CountEvents(data);
result.should.not.be.undefined;
result.output.length.should.be.equal(2);
result.output[0].eventCount.should.be.equal(5); // there are 5 events in the first 5 seconds
result.output[1].eventCount.should.be.equal(3); // there are 3 events in the second 5 seconds
}));
it("should remove duplicate events", () => __awaiter(void 0, void 0, void 0, function* () {
const data = {
eventsMetadata: {
eventTextPropertyName: "text",
splitInterval: 5000,
},
events: [
{
_time: "2017-10-01T12:00:00.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:01.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:02.001Z",
text: "Status@Flame Off",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:03.001Z",
text: "Error code: 340",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:04.001Z",
text: "Error code: 340",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:06.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:08.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:09.001Z",
text: "Status@Flame Off",
text_qc: 0,
},
],
};
const result = yield eventAnalytics.RemoveDuplicateEvents(data);
result.should.not.be.undefined;
result.output.length.should.equal(7);
}));
it("should match event patterns", () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const data = {
maxPatternInterval: 200000,
patternsList: [
{
pattern: [
{
eventText: "INTRODUCING FUEL",
minRepetitions: 1,
maxRepetitions: 2,
},
{
eventText: "Status@Flame On",
minRepetitions: 0,
maxRepetitions: 1,
},
{
eventText: "Module STOP due to parameter assignment",
minRepetitions: 1,
maxRepetitions: 1,
},
],
},
{
pattern: [
{
eventText: "Downloading the module database causes module .. restart",
minRepetitions: 1,
maxRepetitions: 1,
},
{
eventText: "The SIMATIC mode was selected for time-of-day synchronization of the module with Id: ..",
minRepetitions: 1,
maxRepetitions: 1,
},
],
},
],
nonEvents: ["Error 2.. occurred", "STOPPING ENGINE"],
eventsInput: {
eventsMetadata: {
eventTextPropertyName: "text",
},
events: [
{
_time: "2017-10-01T12:00:00.001Z",
text: "Downloading the module database causes module 11 restart",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:01.001Z",
text: "The direction for forwarding the time of day is recognized automatically by the module",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:02.001Z",
text: "Status@Flame On",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:03.001Z",
text: "The SIMATIC mode was selected for time-of-day synchronization of the module with Id: 33",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:06.001Z",
text: "INTRODUCING FUEL",
text_qc: 0,
},
{
_time: "2017-10-01T12:00:09.001Z",
text: "Module STOP due to parameter assignment",
text_qc: 0,
},
],
},
};
const result = yield eventAnalytics.MatchEventPatterns(data);
result.should.not.be.undefined;
(_a = result.output) === null || _a === void 0 ? void 0 : _a.length.should.equal(2);
}));
});
//# sourceMappingURL=event-analytics.spec.js.map