From 1b2f90e940476cd5701e2202baad625b02c2c63d Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sat, 7 Jul 2018 10:26:58 +0300 Subject: [PATCH] naming++ --- dist/module.js | 4 ++-- src/controllers/analytic_controller.ts | 10 +++++----- src/models/analytic_unit.ts | 22 +++++++++++----------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/dist/module.js b/dist/module.js index 20b1dcb..0504bb5 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__);\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.addAnomalyType(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.byKey(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.byKey(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.removeAnomalyType(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.byKey(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.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?"); /***/ }), @@ -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._mapKeyIndex = 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.addAnomalyType = function (anomalyType) {\n this._panelObject.push(anomalyType.panelObject);\n this._mapKeyIndex[anomalyType.name] = this._items.length;\n this._items.push(anomalyType);\n };\n AnalyticUnitsSet.prototype.removeAnomalyType = function (key) {\n var index = this._mapKeyIndex[key];\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._mapKeyIndex[a.key] = i;\n });\n };\n AnalyticUnitsSet.prototype.byKey = function (key) {\n return this._items[this._mapKeyIndex[key]];\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: '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?"); /***/ }), diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index b3149f3..3f7d399 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -73,7 +73,7 @@ export class AnalyticController { async saveNew(metricExpanded: MetricExpanded, datasourceRequest: DatasourceRequest, panelId: number) { this._savingNewAnalyticUnit = true; await this._analyticService.postNewAnalyticUnit(metricExpanded, datasourceRequest, this._newAnalyticUnitType, panelId); - this._analyticUnitsSet.addAnomalyType(this._newAnalyticUnitType); + this._analyticUnitsSet.addItem(this._newAnalyticUnitType); this._creatingNewAnalyticType = false; this._savingNewAnalyticUnit = false; this.runEnabledWaiter(this._newAnalyticUnitType); @@ -91,7 +91,7 @@ export class AnalyticController { if(this._selectedAnalyticUnitKey === null) { return null; } - return this._analyticUnitsSet.byKey(this._selectedAnalyticUnitKey); + return this._analyticUnitsSet.byId(this._selectedAnalyticUnitKey); } async toggleAnomalyTypeLabelingMode(key: AnalyticUnitId) { @@ -162,7 +162,7 @@ export class AnalyticController { } onAnomalyColorChange(key: AnalyticUnitId, value) { - this._analyticUnitsSet.byKey(key).color = value; + this._analyticUnitsSet.byId(key).color = value; } fetchAnomalyTypesStatuses() { @@ -278,7 +278,7 @@ export class AnalyticController { if(key === this._selectedAnalyticUnitKey) { this.dropLabeling(); } - this._analyticUnitsSet.removeAnomalyType(key); + this._analyticUnitsSet.removeItem(key); } private async _runStatusWaiter(anomalyType: AnalyticUnit) { @@ -336,7 +336,7 @@ export class AnalyticController { } public toggleVisibility(key: AnalyticUnitId, value?: boolean) { - var anomaly = this._analyticUnitsSet.byKey(key); + var anomaly = this._analyticUnitsSet.byId(key); if(value !== undefined) { anomaly.visible = value; } else { diff --git a/src/models/analytic_unit.ts b/src/models/analytic_unit.ts index c0e525e..c8578f0 100644 --- a/src/models/analytic_unit.ts +++ b/src/models/analytic_unit.ts @@ -118,28 +118,28 @@ export class AnalyticUnit { export class AnalyticUnitsSet { - private _mapKeyIndex: Map; + private _mapIdIndex: Map; private _items: AnalyticUnit[]; constructor(private _panelObject: any[]) { if(_panelObject === undefined) { throw new Error('panel object can`t be undefined'); } - this._mapKeyIndex = new Map(); + this._mapIdIndex = new Map(); this._items = _panelObject.map(p => new AnalyticUnit(p)); this._rebuildIndex(); } get items() { return this._items; } - addAnomalyType(anomalyType: AnalyticUnit) { - this._panelObject.push(anomalyType.panelObject); - this._mapKeyIndex[anomalyType.name] = this._items.length; - this._items.push(anomalyType); + addItem(item: AnalyticUnit) { + this._panelObject.push(item.panelObject); + this._mapIdIndex[item.name] = this._items.length; + this._items.push(item); } - removeAnomalyType(key: AnalyticUnitId) { - var index = this._mapKeyIndex[key]; + removeItem(id: AnalyticUnitId) { + var index = this._mapIdIndex[id]; this._panelObject.splice(index, 1); this._items.splice(index, 1); this._rebuildIndex(); @@ -147,12 +147,12 @@ export class AnalyticUnitsSet { _rebuildIndex() { this._items.forEach((a, i) => { - this._mapKeyIndex[a.key] = i; + this._mapIdIndex[a.key] = i; }); } - byKey(key: AnalyticUnitId): AnalyticUnit { - return this._items[this._mapKeyIndex[key]]; + byId(id: AnalyticUnitId): AnalyticUnit { + return this._items[this._mapIdIndex[id]]; } byIndex(index: number): AnalyticUnit {