|
|
|
@ -23,6 +23,8 @@ class GeneralModel(Model):
|
|
|
|
|
'convolve_max': 240, |
|
|
|
|
'convolve_min': 200, |
|
|
|
|
'WINDOW_SIZE': 240, |
|
|
|
|
'conv_del_min': 100, |
|
|
|
|
'conv_del_max': 120, |
|
|
|
|
} |
|
|
|
|
self.all_conv = [] |
|
|
|
|
|
|
|
|
@ -38,7 +40,7 @@ class GeneralModel(Model):
|
|
|
|
|
segment_data = data[segment_from_index: segment_to_index + 1] |
|
|
|
|
if len(segment_data) == 0: |
|
|
|
|
continue |
|
|
|
|
x = segment_from_index + int((segment_to_index - segment_from_index) / 2) |
|
|
|
|
x = segment_from_index + math.ceil((segment_to_index - segment_from_index) / 2) |
|
|
|
|
self.ipats.append(x) |
|
|
|
|
segment_data = data[x - self.state['WINDOW_SIZE'] : x + self.state['WINDOW_SIZE']] |
|
|
|
|
segment_min = min(segment_data) |
|
|
|
@ -54,6 +56,20 @@ class GeneralModel(Model):
|
|
|
|
|
convolve_list.append(max(auto_convolve)) |
|
|
|
|
convolve_list.append(max(convolve_data)) |
|
|
|
|
|
|
|
|
|
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_mid_index = segment_from_index + math.ceil((segment_to_index - segment_from_index) / 2) |
|
|
|
|
deleted_pat = data[del_mid_index - self.state['WINDOW_SIZE']: del_mid_index + self.state['WINDOW_SIZE'] + 1] |
|
|
|
|
deleted_pat = deleted_pat - min(deleted_pat) |
|
|
|
|
del_conv_pat = scipy.signal.fftconvolve(deleted_pat, self.model_gen) |
|
|
|
|
del_conv_list.append(max(del_conv_pat)) |
|
|
|
|
|
|
|
|
|
if len(convolve_list) > 0: |
|
|
|
|
self.state['convolve_max'] = float(max(convolve_list)) |
|
|
|
|
else: |
|
|
|
@ -64,6 +80,16 @@ class GeneralModel(Model):
|
|
|
|
|
else: |
|
|
|
|
self.state['convolve_min'] = self.state['WINDOW_SIZE'] / 3 |
|
|
|
|
|
|
|
|
|
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) -> list: |
|
|
|
|
data = dataframe['value'] |
|
|
|
|
pat_data = self.model_gen |
|
|
|
@ -88,6 +114,8 @@ class GeneralModel(Model):
|
|
|
|
|
for val in segments: |
|
|
|
|
if self.all_conv[val] < self.state['convolve_min'] * 0.8: |
|
|
|
|
delete_list.append(val) |
|
|
|
|
elif (self.all_conv[val] < self.state['conv_del_max'] * 1.02 and self.all_conv[val] > self.state['conv_del_min'] * 0.98): |
|
|
|
|
delete_list.append(val) |
|
|
|
|
|
|
|
|
|
for item in delete_list: |
|
|
|
|
segments.remove(item) |
|
|
|
|