Browse Source

172-make-peaks-detector-work

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

11
analytics/pattern_detection_model.py

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

10
analytics/peaks_detector.py

@ -34,8 +34,6 @@ class PeaksDetector:
array = array[window_size:-window_size]
filtered = np.subtract(array, filtered)
import matplotlib.pyplot as plt
# filtered = np.convolve(array, step, mode='valid')
# print(len(array))
# print(len(filtered))
@ -53,12 +51,8 @@ class PeaksDetector:
data = filtered
data /= data.max()
#plt.plot(array[:1000])
plt.plot(data[:1000])
plt.show()
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):
pass
@ -68,4 +62,4 @@ class PeaksDetector:
def load(self, model_filename):
pass
# with open(model_filename, 'rb') as file:
# self.clf, self.scaler = pickle.load(file)
# self.clf, self.scaler = pickle.load(file)

Loading…
Cancel
Save