diff --git a/analytics/detectors/pattern_detection_model.py b/analytics/detectors/pattern_detection_model.py index a78ec13..47fb125 100644 --- a/analytics/detectors/pattern_detection_model.py +++ b/analytics/detectors/pattern_detection_model.py @@ -97,9 +97,9 @@ class PatternDetectionModel: self.data_prov.synchronize() def __create_model(self, pattern): - if pattern == "peaks": + if pattern == "peak": return PeaksDetector() - if pattern == "jumps" or pattern == "drops": + if pattern == "jump" or pattern == "drop": return StepDetector(pattern) raise ValueError('Unknown pattern "%s"' % pattern) diff --git a/analytics/detectors/peaks_detector.py b/analytics/detectors/peaks_detector.py index 25b86e7..cc4170f 100644 --- a/analytics/detectors/peaks_detector.py +++ b/analytics/detectors/peaks_detector.py @@ -4,7 +4,6 @@ from scipy import signal import numpy as np - class PeaksDetector: def __init__(self): pass diff --git a/analytics/detectors/step_detector.py b/analytics/detectors/step_detector.py index 8c3dd4e..4fbf8ef 100644 --- a/analytics/detectors/step_detector.py +++ b/analytics/detectors/step_detector.py @@ -1,9 +1,12 @@ -import numpy as np -import pickle import scipy.signal from scipy.fftpack import fft from scipy.signal import argrelextrema +import numpy as np +import pickle + + + def is_intersect(target_segment, segments): for segment in segments: start = max(segment['start'], target_segment[0]) diff --git a/analytics/worker.py b/analytics/worker.py index e237f9e..6741f3d 100644 --- a/analytics/worker.py +++ b/analytics/worker.py @@ -75,7 +75,7 @@ class Worker(object): last_prediction_time = model.learn(segments) # TODO: we should not do predict before labeling in all models, not just in drops - if pattern == 'drops' and len(segments) == 0: + if pattern == 'drop' and len(segments) == 0: # TODO: move result to a class which renders to json for messaging to analytics result = { 'status': 'success', @@ -101,12 +101,12 @@ class Worker(object): 'lastPredictionTime': last_prediction_time } - def get_model(self, analytic_unit_id, pattern): + def get_model(self, analytic_unit_id, pattern_type): if analytic_unit_id not in self.models_cache: - if pattern.find('general') != -1: + if pattern_type == 'general': model = GeneralDetector(analytic_unit_id) else: - model = PatternDetectionModel(analytic_unit_id, pattern) + model = PatternDetectionModel(analytic_unit_id, pattern_type) self.models_cache[analytic_unit_id] = model return self.models_cache[analytic_unit_id]