From fcf0b9a1b3840b4923cbe9389e6057dd857bf30a Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sat, 7 Jul 2018 11:04:23 +0300 Subject: [PATCH] renaming++ --- dist/module.js | 10 +++---- src/controllers/analytic_controller.ts | 14 +++++----- src/models/analytic_unit.ts | 8 +++--- src/models/segment.ts | 14 +++++----- src/models/segment_array.ts | 23 ++++++++-------- src/models/segment_set.ts | 8 +++--- src/services/analytic_service.ts | 37 ++++++++++++++------------ 7 files changed, 58 insertions(+), 56 deletions(-) diff --git a/dist/module.js b/dist/module.js index 0504bb5..10f7282 100644 --- a/dist/module.js +++ b/dist/module.js @@ -198,7 +198,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_FILL_ALPHA\", function() { return REGION_FILL_ALPHA; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_STROKE_ALPHA\", function() { return REGION_STROKE_ALPHA; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_DELETE_COLOR_LIGHT\", function() { return REGION_DELETE_COLOR_LIGHT; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_DELETE_COLOR_DARK\", function() { return REGION_DELETE_COLOR_DARK; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticController\", function() { return AnalyticController; });\n/* harmony import */ var _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../models/analytic_unit */ \"./models/analytic_unit.ts\");\n/* harmony import */ var _models_segment_array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../models/segment_array */ \"./models/segment_array.ts\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash */ \"lodash\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);\n// Corresponds to https://github.com/hastic/hastic-server/blob/master/server/src/models/analytic_unit.ts\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar __asyncValues = (undefined && undefined.__asyncValues) || function (o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator];\n return m ? m.call(o) : typeof __values === \"function\" ? __values(o) : o[Symbol.iterator]();\n};\n\n\n\nvar REGION_FILL_ALPHA = 0.7;\nvar REGION_STROKE_ALPHA = 0.9;\nvar REGION_DELETE_COLOR_LIGHT = '#d1d1d1';\nvar REGION_DELETE_COLOR_DARK = 'white';\nvar AnalyticController = /** @class */ (function () {\n function AnalyticController(_panelObject, _analyticService, _emitter) {\n var _this = this;\n this._panelObject = _panelObject;\n this._analyticService = _analyticService;\n this._emitter = _emitter;\n this._selectedAnalyticUnitKey = null;\n this._newAnalyticUnitType = null;\n this._creatingNewAnalyticType = false;\n this._savingNewAnalyticUnit = false;\n this._tempIdCounted = -1;\n this._graphLocked = false;\n this._statusRunners = new Set();\n if (_panelObject.anomalyTypes === undefined) {\n _panelObject.anomalyTypes = [];\n }\n this._labelingDataAddedSegments = new _models_segment_array__WEBPACK_IMPORTED_MODULE_1__[\"SegmentArray\"]();\n this._labelingDataDeletedSegments = new _models_segment_array__WEBPACK_IMPORTED_MODULE_1__[\"SegmentArray\"]();\n this._analyticUnitsSet = new _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__[\"AnalyticUnitsSet\"](this._panelObject.anomalyTypes);\n this.analyticUnits.forEach(function (a) { return _this.runEnabledWaiter(a); });\n }\n AnalyticController.prototype.getSegmentsSearcher = function () {\n return this._segmentsSearcher.bind(this);\n };\n AnalyticController.prototype._segmentsSearcher = function (point, rangeDist) {\n var result = [];\n this._analyticUnitsSet.items.forEach(function (at) {\n var segs = at.segments.findSegments(point, rangeDist);\n segs.forEach(function (s) {\n result.push({ anomalyType: at, segment: s });\n });\n });\n return result;\n };\n AnalyticController.prototype.createNew = function () {\n this._newAnalyticUnitType = new _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__[\"AnalyticUnit\"]();\n this._creatingNewAnalyticType = true;\n this._savingNewAnalyticUnit = false;\n };\n AnalyticController.prototype.saveNew = function (metricExpanded, datasourceRequest, panelId) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this._savingNewAnalyticUnit = true;\n return [4 /*yield*/, this._analyticService.postNewAnalyticUnit(metricExpanded, datasourceRequest, this._newAnalyticUnitType, panelId)];\n case 1:\n _a.sent();\n this._analyticUnitsSet.addItem(this._newAnalyticUnitType);\n this._creatingNewAnalyticType = false;\n this._savingNewAnalyticUnit = false;\n this.runEnabledWaiter(this._newAnalyticUnitType);\n this._runStatusWaiter(this._newAnalyticUnitType);\n return [2 /*return*/];\n }\n });\n });\n };\n Object.defineProperty(AnalyticController.prototype, \"creatingNew\", {\n get: function () { return this._creatingNewAnalyticType; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"saving\", {\n get: function () { return this._savingNewAnalyticUnit; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"newAnalyticUnit\", {\n get: function () { return this._newAnalyticUnitType; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"graphLocked\", {\n get: function () { return this._graphLocked; },\n set: function (value) { this._graphLocked = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"labelingAnomaly\", {\n get: function () {\n if (this._selectedAnalyticUnitKey === null) {\n return null;\n }\n return this._analyticUnitsSet.byId(this._selectedAnalyticUnitKey);\n },\n enumerable: true,\n configurable: true\n });\n AnalyticController.prototype.toggleAnomalyTypeLabelingMode = function (key) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this.labelingAnomaly && this.labelingAnomaly.saving) {\n throw new Error('Can`t toggel during saving');\n }\n if (this._selectedAnalyticUnitKey === key) {\n return [2 /*return*/, this.disableLabeling()];\n }\n return [4 /*yield*/, this.disableLabeling()];\n case 1:\n _a.sent();\n this._selectedAnalyticUnitKey = key;\n this.labelingAnomaly.selected = true;\n this.toggleVisibility(key, true);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.disableLabeling = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var newIds, anomaly;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this._selectedAnalyticUnitKey === null) {\n return [2 /*return*/];\n }\n this.labelingAnomaly.saving = true;\n return [4 /*yield*/, this._saveLabelingData()];\n case 1:\n newIds = _a.sent();\n this._labelingDataAddedSegments.getSegments().forEach(function (s, i) {\n _this.labelingAnomaly.segments.updateKey(s.key, newIds[i]);\n });\n this.labelingAnomaly.saving = false;\n anomaly = this.labelingAnomaly;\n this.dropLabeling();\n this._runStatusWaiter(anomaly);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.undoLabeling = function () {\n var _this = this;\n this._labelingDataAddedSegments.getSegments().forEach(function (s) {\n _this.labelingAnomaly.segments.remove(s.key);\n });\n this._labelingDataDeletedSegments.getSegments().forEach(function (s) {\n _this.labelingAnomaly.segments.addSegment(s);\n });\n this.dropLabeling();\n };\n AnalyticController.prototype.dropLabeling = function () {\n this._labelingDataAddedSegments.clear();\n this._labelingDataDeletedSegments.clear();\n this.labelingAnomaly.selected = false;\n this._selectedAnalyticUnitKey = null;\n this._tempIdCounted = -1;\n };\n Object.defineProperty(AnalyticController.prototype, \"labelingMode\", {\n get: function () {\n return this._selectedAnalyticUnitKey !== null;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"labelingDeleteMode\", {\n get: function () {\n if (!this.labelingMode) {\n return false;\n }\n return this.labelingAnomaly.deleteMode;\n },\n enumerable: true,\n configurable: true\n });\n AnalyticController.prototype.addLabelSegment = function (segment) {\n var asegment = this.labelingAnomaly.addLabeledSegment(segment);\n this._labelingDataAddedSegments.addSegment(asegment);\n };\n Object.defineProperty(AnalyticController.prototype, \"analyticUnits\", {\n get: function () {\n return this._analyticUnitsSet.items;\n },\n enumerable: true,\n configurable: true\n });\n AnalyticController.prototype.onAnomalyColorChange = function (key, value) {\n this._analyticUnitsSet.byId(key).color = value;\n };\n AnalyticController.prototype.fetchAnomalyTypesStatuses = function () {\n var _this = this;\n this.analyticUnits.forEach(function (a) { return _this._runStatusWaiter(a); });\n };\n AnalyticController.prototype.fetchAnomalyTypesSegments = function (from, to) {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var tasks;\n return __generator(this, function (_a) {\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+from)) {\n throw new Error('from isn`t number');\n }\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+to)) {\n throw new Error('to isn`t number');\n }\n tasks = this.analyticUnits.map(function (a) { return _this.fetchSegments(a, from, to); });\n return [2 /*return*/, Promise.all(tasks)];\n });\n });\n };\n AnalyticController.prototype.fetchSegments = function (anomalyType, from, to) {\n return __awaiter(this, void 0, void 0, function () {\n var allSegmentsList, allSegmentsSet;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+from)) {\n throw new Error('from isn`t number');\n }\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+to)) {\n throw new Error('to isn`t number');\n }\n return [4 /*yield*/, this._analyticService.getSegments(anomalyType.key, from, to)];\n case 1:\n allSegmentsList = _a.sent();\n allSegmentsSet = new _models_segment_array__WEBPACK_IMPORTED_MODULE_1__[\"SegmentArray\"](allSegmentsList);\n if (anomalyType.selected) {\n this._labelingDataAddedSegments.getSegments().forEach(function (s) { return allSegmentsSet.addSegment(s); });\n this._labelingDataDeletedSegments.getSegments().forEach(function (s) { return allSegmentsSet.remove(s.key); });\n }\n anomalyType.segments = allSegmentsSet;\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype._saveLabelingData = function () {\n return __awaiter(this, void 0, void 0, function () {\n var anomaly;\n return __generator(this, function (_a) {\n anomaly = this.labelingAnomaly;\n if (anomaly === null) {\n throw new Error('anomaly is not selected');\n }\n if (this._labelingDataAddedSegments.length === 0 &&\n this._labelingDataDeletedSegments.length === 0) {\n return [2 /*return*/, []];\n }\n return [2 /*return*/, this._analyticService.updateSegments(anomaly.key, this._labelingDataAddedSegments, this._labelingDataDeletedSegments)];\n });\n });\n };\n // TODO: move to renderer\n AnalyticController.prototype.updateFlotEvents = function (isEditMode, options) {\n if (options.grid.markings === undefined) {\n options.markings = [];\n }\n for (var i = 0; i < this.analyticUnits.length; i++) {\n var anomalyType = this.analyticUnits[i];\n var borderColor = addAlphaToRGB(anomalyType.color, REGION_STROKE_ALPHA);\n var fillColor = addAlphaToRGB(anomalyType.color, REGION_FILL_ALPHA);\n var segments = anomalyType.segments.getSegments();\n if (!anomalyType.visible) {\n continue;\n }\n if (isEditMode && this.labelingMode) {\n if (anomalyType.selected) {\n borderColor = addAlphaToRGB(borderColor, 0.7);\n fillColor = addAlphaToRGB(borderColor, 0.7);\n }\n else {\n continue;\n }\n }\n var rangeDist = +options.xaxis.max - +options.xaxis.min;\n segments.forEach(function (s) {\n var expanded = s.expandDist(rangeDist, 0.01);\n options.grid.markings.push({\n xaxis: { from: expanded.from, to: expanded.to },\n color: fillColor\n });\n options.grid.markings.push({\n xaxis: { from: expanded.from, to: expanded.from },\n color: borderColor\n });\n options.grid.markings.push({\n xaxis: { from: expanded.to, to: expanded.to },\n color: borderColor\n });\n });\n }\n };\n AnalyticController.prototype.deleteLabelingAnomalySegmentsInRange = function (from, to) {\n var _this = this;\n var allRemovedSegs = this.labelingAnomaly.removeSegmentsInRange(from, to);\n allRemovedSegs.forEach(function (s) {\n if (!_this._labelingDataAddedSegments.has(s.key)) {\n _this._labelingDataDeletedSegments.addSegment(s);\n }\n });\n this._labelingDataAddedSegments.removeInRange(from, to);\n };\n AnalyticController.prototype.toggleDeleteMode = function () {\n if (!this.labelingMode) {\n throw new Error('Cant enter delete mode is labeling mode disabled');\n }\n this.labelingAnomaly.deleteMode = !this.labelingAnomaly.deleteMode;\n };\n AnalyticController.prototype.removeAnomalyType = function (key) {\n if (key === this._selectedAnalyticUnitKey) {\n this.dropLabeling();\n }\n this._analyticUnitsSet.removeItem(key);\n };\n AnalyticController.prototype._runStatusWaiter = function (anomalyType) {\n return __awaiter(this, void 0, void 0, function () {\n var statusGenerator, statusGenerator_1, statusGenerator_1_1, data, status_1, error, e_1_1, e_1, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (anomalyType === undefined || anomalyType === null) {\n throw new Error('anomalyType not defined');\n }\n if (this._statusRunners.has(anomalyType.key)) {\n return [2 /*return*/];\n }\n this._statusRunners.add(anomalyType.key);\n statusGenerator = this._analyticService.getAnomalyTypeStatusGenerator(anomalyType.key, 1000);\n _b.label = 1;\n case 1:\n _b.trys.push([1, 7, 8, 13]);\n statusGenerator_1 = __asyncValues(statusGenerator);\n _b.label = 2;\n case 2: return [4 /*yield*/, statusGenerator_1.next()];\n case 3:\n if (!(statusGenerator_1_1 = _b.sent(), !statusGenerator_1_1.done)) return [3 /*break*/, 6];\n return [4 /*yield*/, statusGenerator_1_1.value];\n case 4:\n data = _b.sent();\n status_1 = data.status;\n error = data.errorMessage;\n if (anomalyType.status !== status_1) {\n anomalyType.status = status_1;\n if (error !== undefined) {\n anomalyType.error = error;\n }\n this._emitter.emit('anomaly-type-status-change', anomalyType);\n }\n if (!anomalyType.isActiveStatus) {\n return [3 /*break*/, 6];\n }\n _b.label = 5;\n case 5: return [3 /*break*/, 2];\n case 6: return [3 /*break*/, 13];\n case 7:\n e_1_1 = _b.sent();\n e_1 = { error: e_1_1 };\n return [3 /*break*/, 13];\n case 8:\n _b.trys.push([8, , 11, 12]);\n if (!(statusGenerator_1_1 && !statusGenerator_1_1.done && (_a = statusGenerator_1.return))) return [3 /*break*/, 10];\n return [4 /*yield*/, _a.call(statusGenerator_1)];\n case 9:\n _b.sent();\n _b.label = 10;\n case 10: return [3 /*break*/, 12];\n case 11:\n if (e_1) throw e_1.error;\n return [7 /*endfinally*/];\n case 12: return [7 /*endfinally*/];\n case 13:\n this._statusRunners.delete(anomalyType.key);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.runEnabledWaiter = function (anomalyType) {\n return __awaiter(this, void 0, void 0, function () {\n var enabled;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._analyticService.getAlertEnabled(anomalyType.key)];\n case 1:\n enabled = _a.sent();\n if (anomalyType.alertEnabled !== enabled) {\n anomalyType.alertEnabled = enabled;\n this._emitter.emit('anomaly-type-alert-change', anomalyType);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.toggleAnomalyTypeAlertEnabled = function (anomalyType) {\n return __awaiter(this, void 0, void 0, function () {\n var enabled;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n enabled = anomalyType.alertEnabled;\n anomalyType.alertEnabled = undefined;\n return [4 /*yield*/, this._analyticService.setAlertEnabled(anomalyType.key, enabled)];\n case 1:\n _a.sent();\n anomalyType.alertEnabled = enabled;\n this._emitter.emit('anomaly-type-alert-change', anomalyType);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.getIdForNewLabelSegment = function () {\n this._tempIdCounted--;\n return this._tempIdCounted;\n };\n AnalyticController.prototype.toggleVisibility = function (key, value) {\n var anomaly = this._analyticUnitsSet.byId(key);\n if (value !== undefined) {\n anomaly.visible = value;\n }\n else {\n anomaly.visible = !anomaly.visible;\n }\n };\n return AnalyticController;\n}());\n\nfunction addAlphaToRGB(colorString, alpha) {\n var color = tinycolor(colorString);\n if (color.isValid()) {\n color.setAlpha(color.getAlpha() * alpha);\n return color.toRgbString();\n }\n else {\n return colorString;\n }\n}\n\n\n//# sourceURL=webpack:///./controllers/analytic_controller.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_FILL_ALPHA\", function() { return REGION_FILL_ALPHA; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_STROKE_ALPHA\", function() { return REGION_STROKE_ALPHA; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_DELETE_COLOR_LIGHT\", function() { return REGION_DELETE_COLOR_LIGHT; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"REGION_DELETE_COLOR_DARK\", function() { return REGION_DELETE_COLOR_DARK; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticController\", function() { return AnalyticController; });\n/* harmony import */ var _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../models/analytic_unit */ \"./models/analytic_unit.ts\");\n/* harmony import */ var _models_segment_array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../models/segment_array */ \"./models/segment_array.ts\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash */ \"lodash\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);\n// Corresponds to https://github.com/hastic/hastic-server/blob/master/server/src/models/analytic_unit.ts\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar __asyncValues = (undefined && undefined.__asyncValues) || function (o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator];\n return m ? m.call(o) : typeof __values === \"function\" ? __values(o) : o[Symbol.iterator]();\n};\n\n\n\nvar REGION_FILL_ALPHA = 0.7;\nvar REGION_STROKE_ALPHA = 0.9;\nvar REGION_DELETE_COLOR_LIGHT = '#d1d1d1';\nvar REGION_DELETE_COLOR_DARK = 'white';\nvar AnalyticController = /** @class */ (function () {\n function AnalyticController(_panelObject, _analyticService, _emitter) {\n var _this = this;\n this._panelObject = _panelObject;\n this._analyticService = _analyticService;\n this._emitter = _emitter;\n this._selectedAnalyticUnitKey = null;\n this._newAnalyticUnitType = null;\n this._creatingNewAnalyticType = false;\n this._savingNewAnalyticUnit = false;\n this._tempIdCounted = -1;\n this._graphLocked = false;\n this._statusRunners = new Set();\n if (_panelObject.anomalyTypes === undefined) {\n _panelObject.anomalyTypes = [];\n }\n this._labelingDataAddedSegments = new _models_segment_array__WEBPACK_IMPORTED_MODULE_1__[\"SegmentArray\"]();\n this._labelingDataDeletedSegments = new _models_segment_array__WEBPACK_IMPORTED_MODULE_1__[\"SegmentArray\"]();\n this._analyticUnitsSet = new _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__[\"AnalyticUnitsSet\"](this._panelObject.anomalyTypes);\n this.analyticUnits.forEach(function (a) { return _this.runEnabledWaiter(a); });\n }\n AnalyticController.prototype.getSegmentsSearcher = function () {\n return this._segmentsSearcher.bind(this);\n };\n AnalyticController.prototype._segmentsSearcher = function (point, rangeDist) {\n var result = [];\n this._analyticUnitsSet.items.forEach(function (at) {\n var segs = at.segments.findSegments(point, rangeDist);\n segs.forEach(function (s) {\n result.push({ anomalyType: at, segment: s });\n });\n });\n return result;\n };\n AnalyticController.prototype.createNew = function () {\n this._newAnalyticUnitType = new _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__[\"AnalyticUnit\"]();\n this._creatingNewAnalyticType = true;\n this._savingNewAnalyticUnit = false;\n };\n AnalyticController.prototype.saveNew = function (metricExpanded, datasourceRequest, panelId) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this._savingNewAnalyticUnit = true;\n return [4 /*yield*/, this._analyticService.postNewItem(metricExpanded, datasourceRequest, this._newAnalyticUnitType, panelId)];\n case 1:\n _a.sent();\n this._analyticUnitsSet.addItem(this._newAnalyticUnitType);\n this._creatingNewAnalyticType = false;\n this._savingNewAnalyticUnit = false;\n this.runEnabledWaiter(this._newAnalyticUnitType);\n this._runStatusWaiter(this._newAnalyticUnitType);\n return [2 /*return*/];\n }\n });\n });\n };\n Object.defineProperty(AnalyticController.prototype, \"creatingNew\", {\n get: function () { return this._creatingNewAnalyticType; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"saving\", {\n get: function () { return this._savingNewAnalyticUnit; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"newAnalyticUnit\", {\n get: function () { return this._newAnalyticUnitType; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"graphLocked\", {\n get: function () { return this._graphLocked; },\n set: function (value) { this._graphLocked = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"labelingAnomaly\", {\n get: function () {\n if (this._selectedAnalyticUnitKey === null) {\n return null;\n }\n return this._analyticUnitsSet.byId(this._selectedAnalyticUnitKey);\n },\n enumerable: true,\n configurable: true\n });\n AnalyticController.prototype.toggleAnomalyTypeLabelingMode = function (key) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this.labelingAnomaly && this.labelingAnomaly.saving) {\n throw new Error('Can`t toggel during saving');\n }\n if (this._selectedAnalyticUnitKey === key) {\n return [2 /*return*/, this.disableLabeling()];\n }\n return [4 /*yield*/, this.disableLabeling()];\n case 1:\n _a.sent();\n this._selectedAnalyticUnitKey = key;\n this.labelingAnomaly.selected = true;\n this.toggleVisibility(key, true);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.disableLabeling = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var newIds, anomaly;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this._selectedAnalyticUnitKey === null) {\n return [2 /*return*/];\n }\n this.labelingAnomaly.saving = true;\n return [4 /*yield*/, this._saveLabelingData()];\n case 1:\n newIds = _a.sent();\n this._labelingDataAddedSegments.getSegments().forEach(function (s, i) {\n _this.labelingAnomaly.segments.updateId(s.id, newIds[i]);\n });\n this.labelingAnomaly.saving = false;\n anomaly = this.labelingAnomaly;\n this.dropLabeling();\n this._runStatusWaiter(anomaly);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.undoLabeling = function () {\n var _this = this;\n this._labelingDataAddedSegments.getSegments().forEach(function (s) {\n _this.labelingAnomaly.segments.remove(s.id);\n });\n this._labelingDataDeletedSegments.getSegments().forEach(function (s) {\n _this.labelingAnomaly.segments.addSegment(s);\n });\n this.dropLabeling();\n };\n AnalyticController.prototype.dropLabeling = function () {\n this._labelingDataAddedSegments.clear();\n this._labelingDataDeletedSegments.clear();\n this.labelingAnomaly.selected = false;\n this._selectedAnalyticUnitKey = null;\n this._tempIdCounted = -1;\n };\n Object.defineProperty(AnalyticController.prototype, \"labelingMode\", {\n get: function () {\n return this._selectedAnalyticUnitKey !== null;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticController.prototype, \"labelingDeleteMode\", {\n get: function () {\n if (!this.labelingMode) {\n return false;\n }\n return this.labelingAnomaly.deleteMode;\n },\n enumerable: true,\n configurable: true\n });\n AnalyticController.prototype.addLabelSegment = function (segment) {\n var asegment = this.labelingAnomaly.addLabeledSegment(segment);\n this._labelingDataAddedSegments.addSegment(asegment);\n };\n Object.defineProperty(AnalyticController.prototype, \"analyticUnits\", {\n get: function () {\n return this._analyticUnitsSet.items;\n },\n enumerable: true,\n configurable: true\n });\n AnalyticController.prototype.onAnomalyColorChange = function (key, value) {\n this._analyticUnitsSet.byId(key).color = value;\n };\n AnalyticController.prototype.fetchAnomalyTypesStatuses = function () {\n var _this = this;\n this.analyticUnits.forEach(function (a) { return _this._runStatusWaiter(a); });\n };\n AnalyticController.prototype.fetchAnomalyTypesSegments = function (from, to) {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var tasks;\n return __generator(this, function (_a) {\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+from)) {\n throw new Error('from isn`t number');\n }\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+to)) {\n throw new Error('to isn`t number');\n }\n tasks = this.analyticUnits.map(function (a) { return _this.fetchSegments(a, from, to); });\n return [2 /*return*/, Promise.all(tasks)];\n });\n });\n };\n AnalyticController.prototype.fetchSegments = function (anomalyType, from, to) {\n return __awaiter(this, void 0, void 0, function () {\n var allSegmentsList, allSegmentsSet;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+from)) {\n throw new Error('from isn`t number');\n }\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isNumber(+to)) {\n throw new Error('to isn`t number');\n }\n return [4 /*yield*/, this._analyticService.getSegments(anomalyType.key, from, to)];\n case 1:\n allSegmentsList = _a.sent();\n allSegmentsSet = new _models_segment_array__WEBPACK_IMPORTED_MODULE_1__[\"SegmentArray\"](allSegmentsList);\n if (anomalyType.selected) {\n this._labelingDataAddedSegments.getSegments().forEach(function (s) { return allSegmentsSet.addSegment(s); });\n this._labelingDataDeletedSegments.getSegments().forEach(function (s) { return allSegmentsSet.remove(s.id); });\n }\n anomalyType.segments = allSegmentsSet;\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype._saveLabelingData = function () {\n return __awaiter(this, void 0, void 0, function () {\n var anomaly;\n return __generator(this, function (_a) {\n anomaly = this.labelingAnomaly;\n if (anomaly === null) {\n throw new Error('anomaly is not selected');\n }\n if (this._labelingDataAddedSegments.length === 0 &&\n this._labelingDataDeletedSegments.length === 0) {\n return [2 /*return*/, []];\n }\n return [2 /*return*/, this._analyticService.updateSegments(anomaly.key, this._labelingDataAddedSegments, this._labelingDataDeletedSegments)];\n });\n });\n };\n // TODO: move to renderer\n AnalyticController.prototype.updateFlotEvents = function (isEditMode, options) {\n if (options.grid.markings === undefined) {\n options.markings = [];\n }\n for (var i = 0; i < this.analyticUnits.length; i++) {\n var anomalyType = this.analyticUnits[i];\n var borderColor = addAlphaToRGB(anomalyType.color, REGION_STROKE_ALPHA);\n var fillColor = addAlphaToRGB(anomalyType.color, REGION_FILL_ALPHA);\n var segments = anomalyType.segments.getSegments();\n if (!anomalyType.visible) {\n continue;\n }\n if (isEditMode && this.labelingMode) {\n if (anomalyType.selected) {\n borderColor = addAlphaToRGB(borderColor, 0.7);\n fillColor = addAlphaToRGB(borderColor, 0.7);\n }\n else {\n continue;\n }\n }\n var rangeDist = +options.xaxis.max - +options.xaxis.min;\n segments.forEach(function (s) {\n var expanded = s.expandDist(rangeDist, 0.01);\n options.grid.markings.push({\n xaxis: { from: expanded.from, to: expanded.to },\n color: fillColor\n });\n options.grid.markings.push({\n xaxis: { from: expanded.from, to: expanded.from },\n color: borderColor\n });\n options.grid.markings.push({\n xaxis: { from: expanded.to, to: expanded.to },\n color: borderColor\n });\n });\n }\n };\n AnalyticController.prototype.deleteLabelingAnomalySegmentsInRange = function (from, to) {\n var _this = this;\n var allRemovedSegs = this.labelingAnomaly.removeSegmentsInRange(from, to);\n allRemovedSegs.forEach(function (s) {\n if (!_this._labelingDataAddedSegments.has(s.id)) {\n _this._labelingDataDeletedSegments.addSegment(s);\n }\n });\n this._labelingDataAddedSegments.removeInRange(from, to);\n };\n AnalyticController.prototype.toggleDeleteMode = function () {\n if (!this.labelingMode) {\n throw new Error('Cant enter delete mode is labeling mode disabled');\n }\n this.labelingAnomaly.deleteMode = !this.labelingAnomaly.deleteMode;\n };\n AnalyticController.prototype.removeAnomalyType = function (key) {\n if (key === this._selectedAnalyticUnitKey) {\n this.dropLabeling();\n }\n this._analyticUnitsSet.removeItem(key);\n };\n AnalyticController.prototype._runStatusWaiter = function (anomalyType) {\n return __awaiter(this, void 0, void 0, function () {\n var statusGenerator, statusGenerator_1, statusGenerator_1_1, data, status_1, error, e_1_1, e_1, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (anomalyType === undefined || anomalyType === null) {\n throw new Error('anomalyType not defined');\n }\n if (this._statusRunners.has(anomalyType.key)) {\n return [2 /*return*/];\n }\n this._statusRunners.add(anomalyType.key);\n statusGenerator = this._analyticService.getAnomalyTypeStatusGenerator(anomalyType.key, 1000);\n _b.label = 1;\n case 1:\n _b.trys.push([1, 7, 8, 13]);\n statusGenerator_1 = __asyncValues(statusGenerator);\n _b.label = 2;\n case 2: return [4 /*yield*/, statusGenerator_1.next()];\n case 3:\n if (!(statusGenerator_1_1 = _b.sent(), !statusGenerator_1_1.done)) return [3 /*break*/, 6];\n return [4 /*yield*/, statusGenerator_1_1.value];\n case 4:\n data = _b.sent();\n status_1 = data.status;\n error = data.errorMessage;\n if (anomalyType.status !== status_1) {\n anomalyType.status = status_1;\n if (error !== undefined) {\n anomalyType.error = error;\n }\n this._emitter.emit('anomaly-type-status-change', anomalyType);\n }\n if (!anomalyType.isActiveStatus) {\n return [3 /*break*/, 6];\n }\n _b.label = 5;\n case 5: return [3 /*break*/, 2];\n case 6: return [3 /*break*/, 13];\n case 7:\n e_1_1 = _b.sent();\n e_1 = { error: e_1_1 };\n return [3 /*break*/, 13];\n case 8:\n _b.trys.push([8, , 11, 12]);\n if (!(statusGenerator_1_1 && !statusGenerator_1_1.done && (_a = statusGenerator_1.return))) return [3 /*break*/, 10];\n return [4 /*yield*/, _a.call(statusGenerator_1)];\n case 9:\n _b.sent();\n _b.label = 10;\n case 10: return [3 /*break*/, 12];\n case 11:\n if (e_1) throw e_1.error;\n return [7 /*endfinally*/];\n case 12: return [7 /*endfinally*/];\n case 13:\n this._statusRunners.delete(anomalyType.key);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.runEnabledWaiter = function (anomalyType) {\n return __awaiter(this, void 0, void 0, function () {\n var enabled;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._analyticService.getAlertEnabled(anomalyType.key)];\n case 1:\n enabled = _a.sent();\n if (anomalyType.alertEnabled !== enabled) {\n anomalyType.alertEnabled = enabled;\n this._emitter.emit('anomaly-type-alert-change', anomalyType);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.toggleAnomalyTypeAlertEnabled = function (anomalyType) {\n return __awaiter(this, void 0, void 0, function () {\n var enabled;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n enabled = anomalyType.alertEnabled;\n anomalyType.alertEnabled = undefined;\n return [4 /*yield*/, this._analyticService.setAlertEnabled(anomalyType.key, enabled)];\n case 1:\n _a.sent();\n anomalyType.alertEnabled = enabled;\n this._emitter.emit('anomaly-type-alert-change', anomalyType);\n return [2 /*return*/];\n }\n });\n });\n };\n AnalyticController.prototype.getIdForNewLabelSegment = function () {\n this._tempIdCounted--;\n return this._tempIdCounted;\n };\n AnalyticController.prototype.toggleVisibility = function (key, value) {\n var anomaly = this._analyticUnitsSet.byId(key);\n if (value !== undefined) {\n anomaly.visible = value;\n }\n else {\n anomaly.visible = !anomaly.visible;\n }\n };\n return AnalyticController;\n}());\n\nfunction addAlphaToRGB(colorString, alpha) {\n var color = tinycolor(colorString);\n if (color.isValid()) {\n color.setAlpha(color.getAlpha() * alpha);\n return color.toRgbString();\n }\n else {\n return colorString;\n }\n}\n\n\n//# sourceURL=webpack:///./controllers/analytic_controller.ts?"); /***/ }), @@ -270,7 +270,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticSegment\", function() { return AnalyticSegment; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticUnit\", function() { return AnalyticUnit; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticUnitsSet\", function() { return AnalyticUnitsSet; });\n/* harmony import */ var _segment_array__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./segment_array */ \"./models/segment_array.ts\");\n/* harmony import */ var _segment__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./segment */ \"./models/segment.ts\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash */ \"lodash\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n\nvar AnalyticSegment = /** @class */ (function (_super) {\n __extends(AnalyticSegment, _super);\n function AnalyticSegment(labeled, key, from, to) {\n var _this = _super.call(this, key, from, to) || this;\n _this.labeled = labeled;\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isBoolean(labeled)) {\n throw new Error('labeled value is not boolean');\n }\n return _this;\n }\n return AnalyticSegment;\n}(_segment__WEBPACK_IMPORTED_MODULE_1__[\"Segment\"]));\n\nvar AnalyticUnit = /** @class */ (function () {\n function AnalyticUnit(_panelObject) {\n this._panelObject = _panelObject;\n this._selected = false;\n this._deleteMode = false;\n this._saving = false;\n this._segmentSet = new _segment_array__WEBPACK_IMPORTED_MODULE_0__[\"SegmentArray\"]();\n if (_panelObject === undefined) {\n this._panelObject = {};\n }\n lodash__WEBPACK_IMPORTED_MODULE_2___default.a.defaults(this._panelObject, {\n name: 'anomaly_name', confidence: 0.2, color: 'red', pattern: 'General'\n });\n //this._metric = new Metric(_panelObject.metric);\n }\n Object.defineProperty(AnalyticUnit.prototype, \"key\", {\n get: function () { return this.name; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"name\", {\n get: function () { return this._panelObject.name; },\n set: function (value) { this._panelObject.name = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"pattern\", {\n get: function () { return this._panelObject.pattern.split(' ')[0]; },\n set: function (value) { this._panelObject.pattern = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"confidence\", {\n get: function () { return this._panelObject.confidence; },\n set: function (value) { this._panelObject.confidence = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"color\", {\n get: function () { return this._panelObject.color; },\n set: function (value) { this._panelObject.color = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"selected\", {\n get: function () { return this._selected; },\n set: function (value) { this._selected = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"deleteMode\", {\n get: function () { return this._deleteMode; },\n set: function (value) { this._deleteMode = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"saving\", {\n get: function () { return this._saving; },\n set: function (value) { this._saving = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"visible\", {\n get: function () {\n return (this._panelObject.visible === undefined) ? true : this._panelObject.visible;\n },\n set: function (value) {\n this._panelObject.visible = value;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"metric\", {\n get: function () { return this._metric; },\n enumerable: true,\n configurable: true\n });\n AnalyticUnit.prototype.addLabeledSegment = function (segment) {\n var asegment = new AnalyticSegment(true, segment.key, segment.from, segment.to);\n this._segmentSet.addSegment(asegment);\n return asegment;\n };\n AnalyticUnit.prototype.removeSegmentsInRange = function (from, to) {\n return this._segmentSet.removeInRange(from, to);\n };\n Object.defineProperty(AnalyticUnit.prototype, \"segments\", {\n get: function () { return this._segmentSet; },\n set: function (value) {\n this._segmentSet.setSegments(value.getSegments());\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"status\", {\n get: function () { return this._status; },\n set: function (value) {\n if (value !== 'ready' &&\n value !== 'learning' &&\n value !== 'pending' &&\n value !== 'failed') {\n throw new Error('Unsupported status value: ' + value);\n }\n this._status = value;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"error\", {\n get: function () { return this._error; },\n set: function (value) { this._error = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"isActiveStatus\", {\n get: function () {\n return this.status !== 'ready' && this.status !== 'failed';\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"panelObject\", {\n get: function () { return this._panelObject; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"alertEnabled\", {\n get: function () { return this._alertEnabled; },\n set: function (value) { this._alertEnabled = value; },\n enumerable: true,\n configurable: true\n });\n return AnalyticUnit;\n}());\n\nvar AnalyticUnitsSet = /** @class */ (function () {\n function AnalyticUnitsSet(_panelObject) {\n this._panelObject = _panelObject;\n if (_panelObject === undefined) {\n throw new Error('panel object can`t be undefined');\n }\n this._mapIdIndex = new Map();\n this._items = _panelObject.map(function (p) { return new AnalyticUnit(p); });\n this._rebuildIndex();\n }\n Object.defineProperty(AnalyticUnitsSet.prototype, \"items\", {\n get: function () { return this._items; },\n enumerable: true,\n configurable: true\n });\n AnalyticUnitsSet.prototype.addItem = function (item) {\n this._panelObject.push(item.panelObject);\n this._mapIdIndex[item.name] = this._items.length;\n this._items.push(item);\n };\n AnalyticUnitsSet.prototype.removeItem = function (id) {\n var index = this._mapIdIndex[id];\n this._panelObject.splice(index, 1);\n this._items.splice(index, 1);\n this._rebuildIndex();\n };\n AnalyticUnitsSet.prototype._rebuildIndex = function () {\n var _this = this;\n this._items.forEach(function (a, i) {\n _this._mapIdIndex[a.key] = i;\n });\n };\n AnalyticUnitsSet.prototype.byId = function (id) {\n return this._items[this._mapIdIndex[id]];\n };\n AnalyticUnitsSet.prototype.byIndex = function (index) {\n return this._items[index];\n };\n return AnalyticUnitsSet;\n}());\n\n\n\n//# sourceURL=webpack:///./models/analytic_unit.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticSegment\", function() { return AnalyticSegment; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticUnit\", function() { return AnalyticUnit; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticUnitsSet\", function() { return AnalyticUnitsSet; });\n/* harmony import */ var _segment_array__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./segment_array */ \"./models/segment_array.ts\");\n/* harmony import */ var _segment__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./segment */ \"./models/segment.ts\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash */ \"lodash\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\n\n\n\nvar AnalyticSegment = /** @class */ (function (_super) {\n __extends(AnalyticSegment, _super);\n function AnalyticSegment(labeled, key, from, to) {\n var _this = _super.call(this, key, from, to) || this;\n _this.labeled = labeled;\n if (!lodash__WEBPACK_IMPORTED_MODULE_2___default.a.isBoolean(labeled)) {\n throw new Error('labeled value is not boolean');\n }\n return _this;\n }\n return AnalyticSegment;\n}(_segment__WEBPACK_IMPORTED_MODULE_1__[\"Segment\"]));\n\nvar AnalyticUnit = /** @class */ (function () {\n function AnalyticUnit(_panelObject) {\n this._panelObject = _panelObject;\n this._selected = false;\n this._deleteMode = false;\n this._saving = false;\n this._segmentSet = new _segment_array__WEBPACK_IMPORTED_MODULE_0__[\"SegmentArray\"]();\n if (_panelObject === undefined) {\n this._panelObject = {};\n }\n lodash__WEBPACK_IMPORTED_MODULE_2___default.a.defaults(this._panelObject, {\n name: 'analytcUnitName', confidence: 0.2, color: 'red', pattern: 'General'\n });\n //this._metric = new Metric(_panelObject.metric);\n }\n Object.defineProperty(AnalyticUnit.prototype, \"key\", {\n get: function () { return this.name; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"name\", {\n get: function () { return this._panelObject.name; },\n set: function (value) { this._panelObject.name = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"pattern\", {\n get: function () { return this._panelObject.pattern.split(' ')[0]; },\n set: function (value) { this._panelObject.pattern = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"confidence\", {\n get: function () { return this._panelObject.confidence; },\n set: function (value) { this._panelObject.confidence = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"color\", {\n get: function () { return this._panelObject.color; },\n set: function (value) { this._panelObject.color = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"selected\", {\n get: function () { return this._selected; },\n set: function (value) { this._selected = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"deleteMode\", {\n get: function () { return this._deleteMode; },\n set: function (value) { this._deleteMode = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"saving\", {\n get: function () { return this._saving; },\n set: function (value) { this._saving = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"visible\", {\n get: function () {\n return (this._panelObject.visible === undefined) ? true : this._panelObject.visible;\n },\n set: function (value) {\n this._panelObject.visible = value;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"metric\", {\n get: function () { return this._metric; },\n enumerable: true,\n configurable: true\n });\n AnalyticUnit.prototype.addLabeledSegment = function (segment) {\n var asegment = new AnalyticSegment(true, segment.id, segment.from, segment.to);\n this._segmentSet.addSegment(asegment);\n return asegment;\n };\n AnalyticUnit.prototype.removeSegmentsInRange = function (from, to) {\n return this._segmentSet.removeInRange(from, to);\n };\n Object.defineProperty(AnalyticUnit.prototype, \"segments\", {\n get: function () { return this._segmentSet; },\n set: function (value) {\n this._segmentSet.setSegments(value.getSegments());\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"status\", {\n get: function () { return this._status; },\n set: function (value) {\n if (value !== 'ready' &&\n value !== 'learning' &&\n value !== 'pending' &&\n value !== 'failed') {\n throw new Error('Unsupported status value: ' + value);\n }\n this._status = value;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"error\", {\n get: function () { return this._error; },\n set: function (value) { this._error = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"isActiveStatus\", {\n get: function () {\n return this.status !== 'ready' && this.status !== 'failed';\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"panelObject\", {\n get: function () { return this._panelObject; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(AnalyticUnit.prototype, \"alertEnabled\", {\n get: function () { return this._alertEnabled; },\n set: function (value) { this._alertEnabled = value; },\n enumerable: true,\n configurable: true\n });\n return AnalyticUnit;\n}());\n\nvar AnalyticUnitsSet = /** @class */ (function () {\n function AnalyticUnitsSet(_panelObject) {\n this._panelObject = _panelObject;\n if (_panelObject === undefined) {\n throw new Error('panel object can`t be undefined');\n }\n this._mapIdIndex = new Map();\n this._items = _panelObject.map(function (p) { return new AnalyticUnit(p); });\n this._rebuildIndex();\n }\n Object.defineProperty(AnalyticUnitsSet.prototype, \"items\", {\n get: function () { return this._items; },\n enumerable: true,\n configurable: true\n });\n AnalyticUnitsSet.prototype.addItem = function (item) {\n this._panelObject.push(item.panelObject);\n this._mapIdIndex[item.name] = this._items.length;\n this._items.push(item);\n };\n AnalyticUnitsSet.prototype.removeItem = function (id) {\n var index = this._mapIdIndex[id];\n this._panelObject.splice(index, 1);\n this._items.splice(index, 1);\n this._rebuildIndex();\n };\n AnalyticUnitsSet.prototype._rebuildIndex = function () {\n var _this = this;\n this._items.forEach(function (a, i) {\n _this._mapIdIndex[a.key] = i;\n });\n };\n AnalyticUnitsSet.prototype.byId = function (id) {\n return this._items[this._mapIdIndex[id]];\n };\n AnalyticUnitsSet.prototype.byIndex = function (index) {\n return this._items[index];\n };\n return AnalyticUnitsSet;\n}());\n\n\n\n//# sourceURL=webpack:///./models/analytic_unit.ts?"); /***/ }), @@ -294,7 +294,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Segment\", function() { return Segment; });\nvar Segment = /** @class */ (function () {\n function Segment(_key, from, to) {\n this._key = _key;\n this.from = from;\n this.to = to;\n if (isNaN(this._key)) {\n throw new Error('Key can`t be NaN');\n }\n if (isNaN(+from)) {\n throw new Error('from can`t be NaN');\n }\n if (isNaN(+to)) {\n throw new Error('to can`t be NaN');\n }\n }\n Object.defineProperty(Segment.prototype, \"key\", {\n get: function () { return this._key; },\n set: function (value) { this._key = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Segment.prototype, \"middle\", {\n get: function () { return (this.from + this.to) / 2; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Segment.prototype, \"length\", {\n get: function () {\n return Math.max(this.from, this.to) - Math.min(this.from, this.to);\n },\n enumerable: true,\n configurable: true\n });\n Segment.prototype.expandDist = function (allDist, portion) {\n var p = Math.round(this.middle - allDist * portion / 2);\n var q = Math.round(this.middle + allDist * portion / 2);\n p = Math.min(p, this.from);\n q = Math.max(q, this.to);\n return new Segment(this._key, p, q);\n };\n Segment.prototype.equals = function (segment) {\n return this._key === segment._key;\n };\n return Segment;\n}());\n\n\n\n//# sourceURL=webpack:///./models/segment.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Segment\", function() { return Segment; });\nvar Segment = /** @class */ (function () {\n function Segment(_id, from, to) {\n this._id = _id;\n this.from = from;\n this.to = to;\n if (isNaN(this._id)) {\n throw new Error('Key can`t be NaN');\n }\n if (isNaN(+from)) {\n throw new Error('from can`t be NaN');\n }\n if (isNaN(+to)) {\n throw new Error('to can`t be NaN');\n }\n }\n Object.defineProperty(Segment.prototype, \"id\", {\n get: function () { return this._id; },\n set: function (value) { this._id = value; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Segment.prototype, \"middle\", {\n get: function () { return (this.from + this.to) / 2; },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Segment.prototype, \"length\", {\n get: function () {\n return Math.max(this.from, this.to) - Math.min(this.from, this.to);\n },\n enumerable: true,\n configurable: true\n });\n Segment.prototype.expandDist = function (allDist, portion) {\n var p = Math.round(this.middle - allDist * portion / 2);\n var q = Math.round(this.middle + allDist * portion / 2);\n p = Math.min(p, this.from);\n q = Math.max(q, this.to);\n return new Segment(this._id, p, q);\n };\n Segment.prototype.equals = function (segment) {\n return this._id === segment._id;\n };\n return Segment;\n}());\n\n\n\n//# sourceURL=webpack:///./models/segment.ts?"); /***/ }), @@ -306,7 +306,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"SegmentArray\", function() { return SegmentArray; });\nvar SegmentArray = /** @class */ (function () {\n function SegmentArray(segments) {\n this.segments = segments;\n this._keyToSegment = new Map();\n this.setSegments(segments);\n }\n SegmentArray.prototype.getSegments = function (from, to) {\n if (from === undefined) {\n from = -Infinity;\n }\n if (to === undefined) {\n to = Infinity;\n }\n var result = [];\n for (var i = 0; i < this._segments.length; i++) {\n var s = this._segments[i];\n if (from <= s.from && s.to <= to) {\n result.push(s);\n }\n }\n return result;\n };\n SegmentArray.prototype.setSegments = function (segments) {\n var _this = this;\n this._segments = [];\n this._keyToSegment.clear();\n if (segments) {\n segments.forEach(function (s) {\n _this.addSegment(s);\n });\n }\n };\n SegmentArray.prototype.addSegment = function (segment) {\n if (this.has(segment.key)) {\n throw new Error(\"Segment with key \" + segment.key + \" exists in set\");\n }\n this._keyToSegment.set(segment.key, segment);\n this._segments.push(segment);\n };\n SegmentArray.prototype.findSegments = function (point, rangeDist) {\n return this._segments.filter(function (s) {\n var expanded = s.expandDist(rangeDist, 0.01);\n return (expanded.from <= point) && (point <= expanded.to);\n });\n };\n SegmentArray.prototype.removeInRange = function (from, to) {\n var deleted = [];\n var newSegments = [];\n for (var i = 0; i < this._segments.length; i++) {\n var s = this._segments[i];\n if (from <= s.from && s.to <= to) {\n this._keyToSegment.delete(s.key);\n deleted.push(s);\n }\n else {\n newSegments.push(s);\n }\n }\n this._segments = newSegments;\n return deleted;\n };\n Object.defineProperty(SegmentArray.prototype, \"length\", {\n get: function () {\n return this._segments.length;\n },\n enumerable: true,\n configurable: true\n });\n SegmentArray.prototype.clear = function () {\n this._segments = [];\n this._keyToSegment.clear();\n };\n SegmentArray.prototype.has = function (key) {\n return this._keyToSegment.has(key);\n };\n SegmentArray.prototype.remove = function (key) {\n if (!this.has(key)) {\n return false;\n }\n var index = this._segments.findIndex(function (s) { return s.key === key; });\n this._segments.splice(index, 1);\n this._keyToSegment.delete(key);\n return true;\n };\n SegmentArray.prototype.updateKey = function (fromKey, toKey) {\n var segment = this._keyToSegment.get(fromKey);\n this._keyToSegment.delete(fromKey);\n segment.key = toKey;\n this._keyToSegment.set(toKey, segment);\n };\n return SegmentArray;\n}());\n\n\n\n//# sourceURL=webpack:///./models/segment_array.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"SegmentArray\", function() { return SegmentArray; });\nvar SegmentArray = /** @class */ (function () {\n function SegmentArray(segments) {\n this.segments = segments;\n this._keyToSegment = new Map();\n this.setSegments(segments);\n }\n SegmentArray.prototype.getSegments = function (from, to) {\n if (from === undefined) {\n from = -Infinity;\n }\n if (to === undefined) {\n to = Infinity;\n }\n var result = [];\n for (var i = 0; i < this._segments.length; i++) {\n var s = this._segments[i];\n if (from <= s.from && s.to <= to) {\n result.push(s);\n }\n }\n return result;\n };\n SegmentArray.prototype.setSegments = function (segments) {\n var _this = this;\n this._segments = [];\n this._keyToSegment.clear();\n if (segments) {\n segments.forEach(function (s) {\n _this.addSegment(s);\n });\n }\n };\n SegmentArray.prototype.addSegment = function (segment) {\n if (this.has(segment.id)) {\n throw new Error(\"Segment with key \" + segment.id + \" exists in set\");\n }\n this._keyToSegment.set(segment.id, segment);\n this._segments.push(segment);\n };\n SegmentArray.prototype.findSegments = function (point, rangeDist) {\n return this._segments.filter(function (s) {\n var expanded = s.expandDist(rangeDist, 0.01);\n return (expanded.from <= point) && (point <= expanded.to);\n });\n };\n SegmentArray.prototype.removeInRange = function (from, to) {\n var deleted = [];\n var newSegments = [];\n for (var i = 0; i < this._segments.length; i++) {\n var s = this._segments[i];\n if (from <= s.from && s.to <= to) {\n this._keyToSegment.delete(s.id);\n deleted.push(s);\n }\n else {\n newSegments.push(s);\n }\n }\n this._segments = newSegments;\n return deleted;\n };\n Object.defineProperty(SegmentArray.prototype, \"length\", {\n get: function () {\n return this._segments.length;\n },\n enumerable: true,\n configurable: true\n });\n SegmentArray.prototype.clear = function () {\n this._segments = [];\n this._keyToSegment.clear();\n };\n SegmentArray.prototype.has = function (key) {\n return this._keyToSegment.has(key);\n };\n SegmentArray.prototype.remove = function (key) {\n if (!this.has(key)) {\n return false;\n }\n var index = this._segments.findIndex(function (s) { return s.id === key; });\n this._segments.splice(index, 1);\n this._keyToSegment.delete(key);\n return true;\n };\n SegmentArray.prototype.updateId = function (fromKey, toKey) {\n var segment = this._keyToSegment.get(fromKey);\n this._keyToSegment.delete(fromKey);\n segment.id = toKey;\n this._keyToSegment.set(toKey, segment);\n };\n return SegmentArray;\n}());\n\n\n\n//# sourceURL=webpack:///./models/segment_array.ts?"); /***/ }), @@ -342,7 +342,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticService\", function() { return AnalyticService; });\n/* harmony import */ var _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../models/analytic_unit */ \"./models/analytic_unit.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar __await = (undefined && undefined.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }\nvar __asyncGenerator = (undefined && undefined.__asyncGenerator) || function (thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n};\n\nvar AnalyticService = /** @class */ (function () {\n function AnalyticService(_backendURL, _backendSrv) {\n this._backendURL = _backendURL;\n this._backendSrv = _backendSrv;\n }\n AnalyticService.prototype.postNewAnalyticUnit = function (metric, datasourceRequest, newAnomalyType, panelId) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, this._backendSrv.post(this._backendURL + '/anomalies', {\n name: newAnomalyType.name,\n metric: metric.toJSON(),\n panelUrl: window.location.origin + window.location.pathname + (\"?panelId=\" + panelId + \"&fullscreen\"),\n datasource: datasourceRequest,\n pattern: newAnomalyType.pattern\n })];\n });\n });\n };\n ;\n AnalyticService.prototype.isBackendOk = function () {\n return __awaiter(this, void 0, void 0, function () {\n var data, e_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n return [4 /*yield*/, this._backendSrv.get(this._backendURL)];\n case 1:\n data = _a.sent();\n return [2 /*return*/, true];\n case 2:\n e_1 = _a.sent();\n return [2 /*return*/, false];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n AnalyticService.prototype.updateSegments = function (key, addedSegments, removedSegments) {\n return __awaiter(this, void 0, void 0, function () {\n var getJSONs, payload, data;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n getJSONs = function (segs) { return segs.getSegments().map(function (segment) { return ({\n \"start\": segment.from,\n \"finish\": segment.to\n }); }); };\n payload = {\n name: key,\n added_segments: getJSONs(addedSegments),\n removed_segments: removedSegments.getSegments().map(function (s) { return s.key; })\n };\n return [4 /*yield*/, this._backendSrv.patch(this._backendURL + '/segments', payload)];\n case 1:\n data = _a.sent();\n if (data.added_ids === undefined) {\n throw new Error('Server didn`t send added_ids');\n }\n return [2 /*return*/, data.added_ids];\n }\n });\n });\n };\n AnalyticService.prototype.getSegments = function (key, from, to) {\n return __awaiter(this, void 0, void 0, function () {\n var payload, data, segments;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n payload = { predictor_id: key };\n if (from !== undefined) {\n payload['from'] = from;\n }\n if (to !== undefined) {\n payload['to'] = to;\n }\n return [4 /*yield*/, this._backendSrv.get(this._backendURL + '/segments', payload)];\n case 1:\n data = _a.sent();\n if (data.segments === undefined) {\n throw new Error('Server didn`t return segments array');\n }\n segments = data.segments;\n return [2 /*return*/, segments.map(function (s) { return new _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__[\"AnalyticSegment\"](s.labeled, s.id, s.start, s.finish); })];\n }\n });\n });\n };\n AnalyticService.prototype.getAnomalyTypeStatusGenerator = function (key, duration) {\n return __asyncGenerator(this, arguments, function getAnomalyTypeStatusGenerator_1() {\n var _this = this;\n var statusCheck, timeout;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n statusCheck = function () { return __awaiter(_this, void 0, void 0, function () {\n var data;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._backendSrv.get(this._backendURL + '/anomalies/status', { name: key })];\n case 1:\n data = _a.sent();\n return [2 /*return*/, data];\n }\n });\n }); };\n timeout = function () { return __awaiter(_this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, duration); })];\n });\n }); };\n _a.label = 1;\n case 1:\n if (false) {}\n return [4 /*yield*/, __await(statusCheck())];\n case 2: return [4 /*yield*/, _a.sent()];\n case 3:\n _a.sent();\n return [4 /*yield*/, __await(timeout())];\n case 4:\n _a.sent();\n return [3 /*break*/, 1];\n case 5: return [2 /*return*/];\n }\n });\n });\n };\n AnalyticService.prototype.getAlertEnabled = function (key) {\n return __awaiter(this, void 0, void 0, function () {\n var data;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._backendSrv.get(this._backendURL + '/alerts', { predictor_id: key })];\n case 1:\n data = _a.sent();\n return [2 /*return*/, data.enable];\n }\n });\n });\n };\n AnalyticService.prototype.setAlertEnabled = function (key, value) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, this._backendSrv.post(this._backendURL + '/alerts', { predictor_id: key, enable: value })];\n });\n });\n };\n return AnalyticService;\n}());\n\n\n\n//# sourceURL=webpack:///./services/analytic_service.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"AnalyticService\", function() { return AnalyticService; });\n/* harmony import */ var _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../models/analytic_unit */ \"./models/analytic_unit.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nvar __await = (undefined && undefined.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }\nvar __asyncGenerator = (undefined && undefined.__asyncGenerator) || function (thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n};\n\nvar AnalyticService = /** @class */ (function () {\n function AnalyticService(_backendURL, _backendSrv) {\n this._backendURL = _backendURL;\n this._backendSrv = _backendSrv;\n }\n AnalyticService.prototype.postNewItem = function (metric, datasourceRequest, newItem, panelId) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, this._backendSrv.post(this._backendURL + '/analyticUnits', {\n name: newItem.name,\n metric: metric.toJSON(),\n panelUrl: window.location.origin + window.location.pathname + (\"?panelId=\" + panelId + \"&fullscreen\"),\n datasource: datasourceRequest,\n pattern: newItem.pattern\n })];\n });\n });\n };\n ;\n AnalyticService.prototype.isBackendOk = function () {\n return __awaiter(this, void 0, void 0, function () {\n var data, e_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 2, , 3]);\n return [4 /*yield*/, this._backendSrv.get(this._backendURL)];\n case 1:\n data = _a.sent();\n return [2 /*return*/, true];\n case 2:\n e_1 = _a.sent();\n return [2 /*return*/, false];\n case 3: return [2 /*return*/];\n }\n });\n });\n };\n AnalyticService.prototype.updateSegments = function (key, addedSegments, removedSegments) {\n return __awaiter(this, void 0, void 0, function () {\n var getJSONs, payload, data;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n getJSONs = function (segs) { return segs.getSegments().map(function (segment) { return ({\n \"start\": segment.from,\n \"finish\": segment.to\n }); }); };\n payload = {\n name: key,\n addedSegments: getJSONs(addedSegments),\n removedSegments: removedSegments.getSegments().map(function (s) { return s.id; })\n };\n return [4 /*yield*/, this._backendSrv.patch(this._backendURL + '/segments', payload)];\n case 1:\n data = _a.sent();\n if (data.addedIds === undefined) {\n throw new Error('Server didn`t send added_ids');\n }\n return [2 /*return*/, data.addedIds];\n }\n });\n });\n };\n AnalyticService.prototype.getSegments = function (id, from, to) {\n return __awaiter(this, void 0, void 0, function () {\n var payload, data, segments;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n payload = { id: id };\n if (from !== undefined) {\n payload['from'] = from;\n }\n if (to !== undefined) {\n payload['to'] = to;\n }\n return [4 /*yield*/, this._backendSrv.get(this._backendURL + '/segments', payload)];\n case 1:\n data = _a.sent();\n if (data.segments === undefined) {\n throw new Error('Server didn`t return segments array');\n }\n segments = data.segments;\n return [2 /*return*/, segments.map(function (s) { return new _models_analytic_unit__WEBPACK_IMPORTED_MODULE_0__[\"AnalyticSegment\"](s.labeled, s.id, s.start, s.finish); })];\n }\n });\n });\n };\n AnalyticService.prototype.getAnomalyTypeStatusGenerator = function (key, duration) {\n return __asyncGenerator(this, arguments, function getAnomalyTypeStatusGenerator_1() {\n var _this = this;\n var statusCheck, timeout;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n statusCheck = function () { return __awaiter(_this, void 0, void 0, function () {\n var data;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._backendSrv.get(this._backendURL + '/analyticUnits/status', { name: key })];\n case 1:\n data = _a.sent();\n return [2 /*return*/, data];\n }\n });\n }); };\n timeout = function () { return __awaiter(_this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, duration); })];\n });\n }); };\n _a.label = 1;\n case 1:\n if (false) {}\n return [4 /*yield*/, __await(statusCheck())];\n case 2: return [4 /*yield*/, _a.sent()];\n case 3:\n _a.sent();\n return [4 /*yield*/, __await(timeout())];\n case 4:\n _a.sent();\n return [3 /*break*/, 1];\n case 5: return [2 /*return*/];\n }\n });\n });\n };\n AnalyticService.prototype.getAlertEnabled = function (id) {\n return __awaiter(this, void 0, void 0, function () {\n var data;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._backendSrv.get(this._backendURL + '/alerts', { id: id })];\n case 1:\n data = _a.sent();\n return [2 /*return*/, data.enable];\n }\n });\n });\n };\n AnalyticService.prototype.setAlertEnabled = function (id, enabled) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2 /*return*/, this._backendSrv.post(this._backendURL + '/alerts', { id: id, enabled: enabled })];\n });\n });\n };\n return AnalyticService;\n}());\n\n\n\n//# sourceURL=webpack:///./services/analytic_service.ts?"); /***/ }), diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 3f7d399..f9fb016 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -8,7 +8,7 @@ import { } from '../models/analytic_unit'; import { MetricExpanded } from '../models/metric'; import { DatasourceRequest } from '../models/datasource'; -import { Segment, SegmentKey } from '../models/segment'; +import { Segment, SegmentId } from '../models/segment'; import { SegmentsSet } from '../models/segment_set'; import { SegmentArray } from '../models/segment_array'; @@ -72,7 +72,7 @@ export class AnalyticController { async saveNew(metricExpanded: MetricExpanded, datasourceRequest: DatasourceRequest, panelId: number) { this._savingNewAnalyticUnit = true; - await this._analyticService.postNewAnalyticUnit(metricExpanded, datasourceRequest, this._newAnalyticUnitType, panelId); + await this._analyticService.postNewItem(metricExpanded, datasourceRequest, this._newAnalyticUnitType, panelId); this._analyticUnitsSet.addItem(this._newAnalyticUnitType); this._creatingNewAnalyticType = false; this._savingNewAnalyticUnit = false; @@ -114,7 +114,7 @@ export class AnalyticController { this.labelingAnomaly.saving = true; var newIds = await this._saveLabelingData(); this._labelingDataAddedSegments.getSegments().forEach((s, i) => { - this.labelingAnomaly.segments.updateKey(s.key, newIds[i]); + this.labelingAnomaly.segments.updateId(s.id, newIds[i]); }) this.labelingAnomaly.saving = false; @@ -125,7 +125,7 @@ export class AnalyticController { undoLabeling() { this._labelingDataAddedSegments.getSegments().forEach(s => { - this.labelingAnomaly.segments.remove(s.key); + this.labelingAnomaly.segments.remove(s.id); }); this._labelingDataDeletedSegments.getSegments().forEach(s => { this.labelingAnomaly.segments.addSegment(s); @@ -191,12 +191,12 @@ export class AnalyticController { var allSegmentsSet = new SegmentArray(allSegmentsList); if(anomalyType.selected) { this._labelingDataAddedSegments.getSegments().forEach(s => allSegmentsSet.addSegment(s)); - this._labelingDataDeletedSegments.getSegments().forEach(s => allSegmentsSet.remove(s.key)); + this._labelingDataDeletedSegments.getSegments().forEach(s => allSegmentsSet.remove(s.id)); } anomalyType.segments = allSegmentsSet; } - private async _saveLabelingData(): Promise { + private async _saveLabelingData(): Promise { var anomaly = this.labelingAnomaly; if(anomaly === null) { throw new Error('anomaly is not selected'); @@ -260,7 +260,7 @@ export class AnalyticController { deleteLabelingAnomalySegmentsInRange(from: number, to: number) { var allRemovedSegs = this.labelingAnomaly.removeSegmentsInRange(from, to); allRemovedSegs.forEach(s => { - if(!this._labelingDataAddedSegments.has(s.key)) { + if(!this._labelingDataAddedSegments.has(s.id)) { this._labelingDataDeletedSegments.addSegment(s); } }); diff --git a/src/models/analytic_unit.ts b/src/models/analytic_unit.ts index c8578f0..f81288a 100644 --- a/src/models/analytic_unit.ts +++ b/src/models/analytic_unit.ts @@ -1,6 +1,6 @@ import { SegmentsSet } from './segment_set'; import { SegmentArray } from './segment_array'; -import { Segment, SegmentKey } from './segment'; +import { Segment, SegmentId } from './segment'; import { Metric } from './metric'; import _ from 'lodash'; @@ -11,7 +11,7 @@ export type AnalyticSegmentsSearcher = (point: number, rangeDist: number) => Ana export type AnalyticUnitId = string; export class AnalyticSegment extends Segment { - constructor(public labeled: boolean, key: SegmentKey, from: number, to: number) { + constructor(public labeled: boolean, key: SegmentId, from: number, to: number) { super(key, from, to); if(!_.isBoolean(labeled)) { throw new Error('labeled value is not boolean'); @@ -36,7 +36,7 @@ export class AnalyticUnit { this._panelObject = {}; } _.defaults(this._panelObject, { - name: 'anomaly_name', confidence: 0.2, color: 'red', pattern: 'General' + name: 'analytcUnitName', confidence: 0.2, color: 'red', pattern: 'General' }); //this._metric = new Metric(_panelObject.metric); @@ -75,7 +75,7 @@ export class AnalyticUnit { get metric() { return this._metric; } addLabeledSegment(segment: Segment): AnalyticSegment { - var asegment = new AnalyticSegment(true, segment.key, segment.from, segment.to); + var asegment = new AnalyticSegment(true, segment.id, segment.from, segment.to); this._segmentSet.addSegment(asegment); return asegment; } diff --git a/src/models/segment.ts b/src/models/segment.ts index b10a65e..332dac0 100644 --- a/src/models/segment.ts +++ b/src/models/segment.ts @@ -1,8 +1,8 @@ -export type SegmentKey = number; +export type SegmentId = number; export class Segment { - constructor(private _key: SegmentKey, public from: number, public to: number) { - if(isNaN(this._key)) { + constructor(private _id: SegmentId, public from: number, public to: number) { + if(isNaN(this._id)) { throw new Error('Key can`t be NaN'); } if(isNaN(+from)) { @@ -13,8 +13,8 @@ export class Segment { } } - get key(): SegmentKey { return this._key; } - set key(value) { this._key = value; } + get id(): SegmentId { return this._id; } + set id(value) { this._id = value; } get middle() { return (this.from + this.to) / 2; } @@ -27,10 +27,10 @@ export class Segment { var q = Math.round(this.middle + allDist * portion / 2); p = Math.min(p, this.from); q = Math.max(q, this.to); - return new Segment(this._key, p, q); + return new Segment(this._id, p, q); } equals(segment: Segment) { - return this._key === segment._key; + return this._id === segment._id; } } diff --git a/src/models/segment_array.ts b/src/models/segment_array.ts index ed4ef0b..db74941 100644 --- a/src/models/segment_array.ts +++ b/src/models/segment_array.ts @@ -1,12 +1,12 @@ import { SegmentsSet } from './segment_set'; -import { Segment, SegmentKey } from './segment'; +import { Segment, SegmentId } from './segment'; import _ from 'lodash'; export class SegmentArray implements SegmentsSet { private _segments: T[]; - private _keyToSegment: Map = new Map(); + private _keyToSegment: Map = new Map(); constructor(private segments?: T[]) { this.setSegments(segments); @@ -40,10 +40,10 @@ export class SegmentArray implements SegmentsSet { } addSegment(segment: T) { - if(this.has(segment.key)) { - throw new Error(`Segment with key ${segment.key} exists in set`); + if(this.has(segment.id)) { + throw new Error(`Segment with key ${segment.id} exists in set`); } - this._keyToSegment.set(segment.key, segment); + this._keyToSegment.set(segment.id, segment); this._segments.push(segment); } @@ -60,7 +60,7 @@ export class SegmentArray implements SegmentsSet { for(var i = 0; i < this._segments.length; i++) { var s = this._segments[i]; if(from <= s.from && s.to <= to) { - this._keyToSegment.delete(s.key); + this._keyToSegment.delete(s.id); deleted.push(s); } else { newSegments.push(s); @@ -79,26 +79,25 @@ export class SegmentArray implements SegmentsSet { this._keyToSegment.clear(); } - has(key: SegmentKey): boolean { + has(key: SegmentId): boolean { return this._keyToSegment.has(key); } - remove(key: SegmentKey): boolean { + remove(key: SegmentId): boolean { if(!this.has(key)) { return false; } - var index = this._segments.findIndex(s => s.key === key); + var index = this._segments.findIndex(s => s.id === key); this._segments.splice(index, 1); this._keyToSegment.delete(key); return true; } - updateKey(fromKey: SegmentKey, toKey: SegmentKey) { + updateId(fromKey: SegmentId, toKey: SegmentId) { var segment = this._keyToSegment.get(fromKey); this._keyToSegment.delete(fromKey); - segment.key = toKey; + segment.id = toKey; this._keyToSegment.set(toKey, segment); - } } diff --git a/src/models/segment_set.ts b/src/models/segment_set.ts index cb27e5f..a7374d8 100644 --- a/src/models/segment_set.ts +++ b/src/models/segment_set.ts @@ -1,4 +1,4 @@ -import { Segment, SegmentKey } from './segment' +import { Segment, SegmentId } from './segment' export interface SegmentsSet { getSegments(from?: number, to?: number): T[]; @@ -6,9 +6,9 @@ export interface SegmentsSet { addSegment(segment: T): void; findSegments(point: number, rangeDist: number): T[]; removeInRange(from: number, to: number): T[]; - remove(key: SegmentKey): boolean; - has(key: SegmentKey): boolean; + remove(id: SegmentId): boolean; + has(id: SegmentId): boolean; clear(): void; - updateKey(fromKey: SegmentKey, toKey: SegmentKey): void; + updateId(fromId: SegmentId, toId: SegmentId): void; length: number; } diff --git a/src/services/analytic_service.ts b/src/services/analytic_service.ts index 02b0db7..0c575ff 100644 --- a/src/services/analytic_service.ts +++ b/src/services/analytic_service.ts @@ -1,4 +1,4 @@ -import { Segment, SegmentKey } from '../models/segment'; +import { Segment, SegmentId } from '../models/segment'; import { MetricExpanded } from '../models/metric'; import { DatasourceRequest } from '../models/datasource'; import { SegmentsSet } from '../models/segment_set'; @@ -12,15 +12,18 @@ export class AnalyticService { constructor(private _backendURL: string, private _backendSrv: BackendSrv) { } - async postNewAnalyticUnit(metric: MetricExpanded, datasourceRequest: DatasourceRequest, newAnomalyType: AnalyticUnit, panelId: number) { + async postNewItem( + metric: MetricExpanded, datasourceRequest: DatasourceRequest, + newItem: AnalyticUnit, panelId: number + ) { return this._backendSrv.post( - this._backendURL + '/anomalies', + this._backendURL + '/analyticUnits', { - name: newAnomalyType.name, + name: newItem.name, metric: metric.toJSON(), panelUrl: window.location.origin + window.location.pathname + `?panelId=${panelId}&fullscreen`, datasource: datasourceRequest, - pattern: newAnomalyType.pattern + pattern: newItem.pattern } ) }; @@ -36,7 +39,7 @@ export class AnalyticService { async updateSegments( key: AnalyticUnitId, addedSegments: SegmentsSet, removedSegments: SegmentsSet - ): Promise { + ): Promise { const getJSONs = (segs: SegmentsSet) => segs.getSegments().map(segment => ({ "start": segment.from, @@ -45,20 +48,20 @@ export class AnalyticService { var payload = { name: key, - added_segments: getJSONs(addedSegments), - removed_segments: removedSegments.getSegments().map(s => s.key) + addedSegments: getJSONs(addedSegments), + removedSegments: removedSegments.getSegments().map(s => s.id) } var data = await this._backendSrv.patch(this._backendURL + '/segments', payload); - if(data.added_ids === undefined) { + if(data.addedIds === undefined) { throw new Error('Server didn`t send added_ids'); } - return data.added_ids as SegmentKey[]; + return data.addedIds as SegmentId[]; } - async getSegments(key: AnalyticUnitId, from?: number, to?: number): Promise { - var payload: any = { predictor_id: key }; + async getSegments(id: AnalyticUnitId, from?: number, to?: number): Promise { + var payload: any = { id }; if(from !== undefined) { payload['from'] = from; } @@ -79,7 +82,7 @@ export class AnalyticService { async * getAnomalyTypeStatusGenerator(key: AnalyticUnitId, duration: number) { let statusCheck = async () => { var data = await this._backendSrv.get( - this._backendURL + '/anomalies/status', { name: key } + this._backendURL + '/analyticUnits/status', { name: key } ); return data; } @@ -95,17 +98,17 @@ export class AnalyticService { } - async getAlertEnabled(key: AnalyticUnitId): Promise { + async getAlertEnabled(id: AnalyticUnitId): Promise { var data = await this._backendSrv.get( - this._backendURL + '/alerts', { predictor_id: key } + this._backendURL + '/alerts', { id } ); return data.enable as boolean; } - async setAlertEnabled(key: AnalyticUnitId, value: boolean): Promise { + async setAlertEnabled(id: AnalyticUnitId, enabled: boolean): Promise { return this._backendSrv.post( - this._backendURL + '/alerts', { predictor_id: key, enable: value } + this._backendURL + '/alerts', { id, enabled } ); }