|
|
@ -23,6 +23,8 @@ class PeakModel(Model): |
|
|
|
'convolve_max': 570000, |
|
|
|
'convolve_max': 570000, |
|
|
|
'convolve_min': 530000, |
|
|
|
'convolve_min': 530000, |
|
|
|
'WINDOW_SIZE': 240, |
|
|
|
'WINDOW_SIZE': 240, |
|
|
|
|
|
|
|
'conv_del_min': 54000, |
|
|
|
|
|
|
|
'conv_del_max': 55000, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def do_fit(self, dataframe: pd.DataFrame, segments: list) -> None: |
|
|
|
def do_fit(self, dataframe: pd.DataFrame, segments: list) -> None: |
|
|
@ -47,7 +49,7 @@ class PeakModel(Model): |
|
|
|
patterns_list.append(labeled_peak) |
|
|
|
patterns_list.append(labeled_peak) |
|
|
|
|
|
|
|
|
|
|
|
self.model_peak = utils.get_av_model(patterns_list) |
|
|
|
self.model_peak = utils.get_av_model(patterns_list) |
|
|
|
for n in range(len(segments)): |
|
|
|
for n in range(len(segments)): #labeled segments |
|
|
|
labeled_peak = data[self.ipeaks[n] - self.state['WINDOW_SIZE']: self.ipeaks[n] + self.state['WINDOW_SIZE'] + 1] |
|
|
|
labeled_peak = data[self.ipeaks[n] - self.state['WINDOW_SIZE']: self.ipeaks[n] + self.state['WINDOW_SIZE'] + 1] |
|
|
|
labeled_peak = labeled_peak - min(labeled_peak) |
|
|
|
labeled_peak = labeled_peak - min(labeled_peak) |
|
|
|
auto_convolve = scipy.signal.fftconvolve(labeled_peak, labeled_peak) |
|
|
|
auto_convolve = scipy.signal.fftconvolve(labeled_peak, labeled_peak) |
|
|
@ -55,6 +57,20 @@ class PeakModel(Model): |
|
|
|
convolve_list.append(max(auto_convolve)) |
|
|
|
convolve_list.append(max(auto_convolve)) |
|
|
|
convolve_list.append(max(convolve_peak)) |
|
|
|
convolve_list.append(max(convolve_peak)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del_conv_list = [] |
|
|
|
|
|
|
|
for segment in segments: |
|
|
|
|
|
|
|
if segment['deleted']: |
|
|
|
|
|
|
|
segment_from_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['from'], unit='ms')) |
|
|
|
|
|
|
|
segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'], unit='ms')) |
|
|
|
|
|
|
|
segment_data = data[segment_from_index: segment_to_index + 1] |
|
|
|
|
|
|
|
if len(segment_data) == 0: |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
del_max_index = segment_data.idxmax() |
|
|
|
|
|
|
|
deleted_peak = data[del_max_index - self.state['WINDOW_SIZE']: del_max_index + self.state['WINDOW_SIZE'] + 1] |
|
|
|
|
|
|
|
deleted_peak = deleted_peak - min(deleted_peak) |
|
|
|
|
|
|
|
del_conv_peak = scipy.signal.fftconvolve(deleted_peak, self.model_peak) |
|
|
|
|
|
|
|
del_conv_list.append(max(del_conv_peak)) |
|
|
|
|
|
|
|
|
|
|
|
if len(confidences) > 0: |
|
|
|
if len(confidences) > 0: |
|
|
|
self.state['confidence'] = float(min(confidences)) |
|
|
|
self.state['confidence'] = float(min(confidences)) |
|
|
|
else: |
|
|
|
else: |
|
|
@ -70,6 +86,16 @@ class PeakModel(Model): |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.state['convolve_min'] = self.state['WINDOW_SIZE'] |
|
|
|
self.state['convolve_min'] = self.state['WINDOW_SIZE'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(del_conv_list) > 0: |
|
|
|
|
|
|
|
self.state['conv_del_min'] = float(min(del_conv_list)) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.state['conv_del_min'] = self.state['WINDOW_SIZE'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(del_conv_list) > 0: |
|
|
|
|
|
|
|
self.state['conv_del_max'] = float(max(del_conv_list)) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.state['conv_del_max'] = self.state['WINDOW_SIZE'] |
|
|
|
|
|
|
|
|
|
|
|
def do_predict(self, dataframe: pd.DataFrame): |
|
|
|
def do_predict(self, dataframe: pd.DataFrame): |
|
|
|
data = dataframe['value'] |
|
|
|
data = dataframe['value'] |
|
|
|
window_size = int(len(data)/SMOOTHING_COEFF) #test ws on flat data |
|
|
|
window_size = int(len(data)/SMOOTHING_COEFF) #test ws on flat data |
|
|
@ -108,6 +134,8 @@ class PeakModel(Model): |
|
|
|
conv = scipy.signal.fftconvolve(convol_data, pattern_data) |
|
|
|
conv = scipy.signal.fftconvolve(convol_data, pattern_data) |
|
|
|
if max(conv) > self.state['convolve_max'] * 1.05 or max(conv) < self.state['convolve_min'] * 0.95: |
|
|
|
if max(conv) > self.state['convolve_max'] * 1.05 or max(conv) < self.state['convolve_min'] * 0.95: |
|
|
|
delete_list.append(segment) |
|
|
|
delete_list.append(segment) |
|
|
|
|
|
|
|
if max(conv) < self.state['conv_del_max'] * 1.02 and max(conv) > self.state['conv_del_min'] * 0.98: |
|
|
|
|
|
|
|
delete_list.append(segment) |
|
|
|
else: |
|
|
|
else: |
|
|
|
delete_list.append(segment) |
|
|
|
delete_list.append(segment) |
|
|
|
# TODO: implement filtering |
|
|
|
# TODO: implement filtering |
|
|
|