Browse Source

172-make-peaks-detector-work

pull/1/head
rozetko 7 years ago
parent
commit
993cd7f35b
  1. 3
      analytics/pattern_detection_model.py
  2. 8
      analytics/peaks_detector.py

3
analytics/pattern_detection_model.py

@ -56,10 +56,13 @@ class PatternDetectionModel:
start_index, stop_index = 0, len(dataframe) start_index, stop_index = 0, len(dataframe)
if len(segments) > 0: if len(segments) > 0:
min_time, max_time = segments_box(segments) min_time, max_time = segments_box(segments)
try:
start_index = dataframe[dataframe['timestamp'] >= min_time].index[0] start_index = dataframe[dataframe['timestamp'] >= min_time].index[0]
stop_index = dataframe[dataframe['timestamp'] > max_time].index[0] stop_index = dataframe[dataframe['timestamp'] > max_time].index[0]
start_index = max(start_index - window_size, 0) start_index = max(start_index - window_size, 0)
stop_index = min(stop_index + window_size, len(dataframe)) stop_index = min(stop_index + window_size, len(dataframe))
except IndexError:
pass
dataframe = dataframe[start_index:stop_index] dataframe = dataframe[start_index:stop_index]

8
analytics/peaks_detector.py

@ -34,8 +34,6 @@ class PeaksDetector:
array = array[window_size:-window_size] array = array[window_size:-window_size]
filtered = np.subtract(array, filtered) filtered = np.subtract(array, filtered)
import matplotlib.pyplot as plt
# filtered = np.convolve(array, step, mode='valid') # filtered = np.convolve(array, step, mode='valid')
# print(len(array)) # print(len(array))
# print(len(filtered)) # print(len(filtered))
@ -53,12 +51,8 @@ class PeaksDetector:
data = filtered data = filtered
data /= data.max() data /= data.max()
#plt.plot(array[:1000])
plt.plot(data[:1000])
plt.show()
result = step_detect.find_steps(data, 0.1) result = step_detect.find_steps(data, 0.1)
return [dataframe.index[x + window_size] for x in result] return [(dataframe.index[x], dataframe.index[x + window_size]) for x in result]
def save(self, model_filename): def save(self, model_filename):
pass pass

Loading…
Cancel
Save