From f9867aec26a12fc5cf3d26a005c0a3c0f2129ca6 Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 21 Jun 2018 23:14:33 +0300 Subject: [PATCH] tmp drops fix --- analytics/step_detector.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/analytics/step_detector.py b/analytics/step_detector.py index 7fabc63..626c1e6 100644 --- a/analytics/step_detector.py +++ b/analytics/step_detector.py @@ -49,8 +49,8 @@ class StepDetector: return result def __predict(self, data): - all_normal_flatten_data = data.rolling(window=10).mean() - all_max_flatten_data = data.rolling(window=24).mean() + window_size = 24 + all_max_flatten_data = data.rolling(window=window_size).mean() all_mins = argrelextrema(np.array(all_max_flatten_data), np.less)[0] extrema_list = [] @@ -60,32 +60,24 @@ class StepDetector: segments = [] for i in all_mins: if all_max_flatten_data[i] < extrema_list[i]: - segments.append(i - 20) + segments.append(i - window_size) return [(x - 1, x + 1) for x in self.__filter_prediction(segments, all_max_flatten_data)] def __filter_prediction(self, segments, all_max_flatten_data): delete_list = [] - for i in range(1, len(segments)): - if segments[i] < segments[i-1] + 500: - delete_list.append(segments[i]) - + for i in segments: + new_data = all_max_flatten_data[i-50:i+250] + min_value = 100 + for val in new_data: + if val < min_value: + min_value = val + if all_max_flatten_data[i] > min_value: + delete_list.append(i) + for item in delete_list: segments.remove(item) - # delete_list = [] - # for i in segments: - # new_data = all_max_flatten_data[i-150:i+50] - # min_value = 100 - # for j in new_data: - # if j < min_value: - # min_value = j - # if all_max_flatten_data[i] > min_value: - # delete_list.append(i) - - # for item in delete_list: - # segments.remove(item) - return segments def save(self, model_filename):