From 95b5f697884891dd68a357e51255f2d1b665c08a Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 8 Jul 2018 22:53:22 +0300 Subject: [PATCH] config paths fixs --- analytics/anomaly_model.py | 4 ++-- analytics/config.py | 13 +++++++------ analytics/pattern_detection_model.py | 2 +- server/src/config.ts | 2 +- server/src/controllers/analytics_controller.ts | 1 + 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/analytics/anomaly_model.py b/analytics/anomaly_model.py index f2f38d8..0c3ba72 100644 --- a/analytics/anomaly_model.py +++ b/analytics/anomaly_model.py @@ -124,11 +124,11 @@ class AnomalyModel: self.preprocessor.synchronize() def load_anomaly_config(self): - with open(os.path.join(config.ANOMALIES_FOLDER, self.anomaly_name + ".json"), 'r') as config_file: + with open(os.path.join(config.ANALYTIC_UNITS_FOLDER, self.anomaly_name + ".json"), 'r') as config_file: self.anomaly_config = json.load(config_file) def get_anomalies(self): - labeled_anomalies_file = os.path.join(config.ANOMALIES_FOLDER, self.anomaly_name + "_labeled.json") + labeled_anomalies_file = os.path.join(config.ANALYTIC_UNITS_FOLDER, self.anomaly_name + "_labeled.json") if not os.path.exists(labeled_anomalies_file): return [] with open(labeled_anomalies_file) as file: diff --git a/analytics/config.py b/analytics/config.py index f00ed86..9b8511b 100644 --- a/analytics/config.py +++ b/analytics/config.py @@ -2,8 +2,9 @@ import os import json -DATA_FOLDER = '../data' -CONFIG_FILE = '../config.json' +PARENT_FOLDER = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +DATA_FOLDER = os.path.join(PARENT_FOLDER, 'data') +CONFIG_FILE = os.path.join(PARENT_FOLDER, 'config.json') config_exists = os.path.isfile(CONFIG_FILE) @@ -27,10 +28,10 @@ def get_config_field(field, default_val = None): -DATASET_FOLDER = os.path.join(DATA_FOLDER, 'datasets/') -ANOMALIES_FOLDER = os.path.join(DATA_FOLDER, 'anomalies/') -MODELS_FOLDER = os.path.join(DATA_FOLDER, 'models/') -METRICS_FOLDER = os.path.join(DATA_FOLDER, 'metrics/') +DATASET_FOLDER = os.path.join(DATA_FOLDER, 'datasets') +ANALYTIC_UNITS_FOLDER = os.path.join(DATA_FOLDER, 'analytic_units') +MODELS_FOLDER = os.path.join(DATA_FOLDER, 'models') +METRICS_FOLDER = os.path.join(DATA_FOLDER, 'metrics') HASTIC_API_KEY = get_config_field('HASTIC_API_KEY') ZEROMQ_CONNECTION_STRING = get_config_field('ZEROMQ_CONNECTION_STRING', 'tcp://*:8002') diff --git a/analytics/pattern_detection_model.py b/analytics/pattern_detection_model.py index ae7a269..b735b82 100644 --- a/analytics/pattern_detection_model.py +++ b/analytics/pattern_detection_model.py @@ -101,7 +101,7 @@ class PatternDetectionModel: return StepDetector(pattern) def __load_anomaly_config(self): - with open(os.path.join(config.ANOMALIES_FOLDER, self.analytic_unit_id + ".json"), 'r') as config_file: + with open(os.path.join(config.ANALYTIC_UNITS_FOLDER, self.analytic_unit_id + ".json"), 'r') as config_file: self.anomaly_config = json.load(config_file) def __save_model(self): diff --git a/server/src/config.ts b/server/src/config.ts index ccd731b..d6fd28a 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -11,7 +11,7 @@ export const ANALYTICS_PATH = path.join(__dirname, '../../analytics'); export const DATA_PATH = path.join(__dirname, '../../data'); export const DATASETS_PATH = path.join(DATA_PATH, 'datasets'); -export const ANALYTIC_UNITS_PATH = path.join(DATA_PATH, 'analytic_units '); +export const ANALYTIC_UNITS_PATH = path.join(DATA_PATH, 'analytic_units'); export const MODELS_PATH = path.join(DATA_PATH, 'models'); export const METRICS_PATH = path.join(DATA_PATH, 'metrics'); export const SEGMENTS_PATH = path.join(DATA_PATH, 'segments'); diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 2ae9111..51eb271 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -59,6 +59,7 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId) { } } + export async function runPredict(id: AnalyticUnit.AnalyticUnitId) { let unit = AnalyticUnit.findById(id); let pattern = unit.type;