|
|
@ -16,11 +16,11 @@ class GeneralModel(Model): |
|
|
|
def __init__(self): |
|
|
|
def __init__(self): |
|
|
|
super() |
|
|
|
super() |
|
|
|
self.state = { |
|
|
|
self.state = { |
|
|
|
'ipats': [], |
|
|
|
'pattern_center': [], |
|
|
|
'model_gen': [], |
|
|
|
'pattern_model': [], |
|
|
|
'convolve_max': 240, |
|
|
|
'convolve_max': 240, |
|
|
|
'convolve_min': 200, |
|
|
|
'convolve_min': 200, |
|
|
|
'WINDOW_SIZE': 240, |
|
|
|
'WINDOW_SIZE': 0, |
|
|
|
'conv_del_min': 100, |
|
|
|
'conv_del_min': 100, |
|
|
|
'conv_del_max': 120, |
|
|
|
'conv_del_max': 120, |
|
|
|
} |
|
|
|
} |
|
|
@ -40,10 +40,11 @@ class GeneralModel(Model): |
|
|
|
def do_fit(self, dataframe: pd.DataFrame, labeled_segments: list, deleted_segments: list, learning_info: dict) -> None: |
|
|
|
def do_fit(self, dataframe: pd.DataFrame, labeled_segments: list, deleted_segments: list, learning_info: dict) -> None: |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = data['value'] |
|
|
|
data = data['value'] |
|
|
|
self.state['ipats'] = learning_info['segment_center_list'] |
|
|
|
last_pattern_center = self.state.get('pattern_center', []) |
|
|
|
self.state['model_gen'] = utils.get_av_model(learning_info['patterns_list']) |
|
|
|
self.state['pattern_center'] = list(set(last_pattern_center + learning_info['segment_center_list'])) |
|
|
|
convolve_list = utils.get_convolve(self.state['ipats'], self.state['model_gen'], data, self.state['WINDOW_SIZE']) |
|
|
|
self.state['pattern_model'] = utils.get_av_model(learning_info['patterns_list']) |
|
|
|
correlation_list = utils.get_correlation(self.state['ipats'], self.state['model_gen'], data, self.state['WINDOW_SIZE']) |
|
|
|
convolve_list = utils.get_convolve(self.state['pattern_center'], self.state['pattern_model'], data, self.state['WINDOW_SIZE']) |
|
|
|
|
|
|
|
correlation_list = utils.get_correlation(self.state['pattern_center'], self.state['pattern_model'], data, self.state['WINDOW_SIZE']) |
|
|
|
|
|
|
|
|
|
|
|
del_conv_list = [] |
|
|
|
del_conv_list = [] |
|
|
|
delete_pattern_timestamp = [] |
|
|
|
delete_pattern_timestamp = [] |
|
|
@ -52,7 +53,7 @@ class GeneralModel(Model): |
|
|
|
delete_pattern_timestamp.append(segment.pattern_timestamp) |
|
|
|
delete_pattern_timestamp.append(segment.pattern_timestamp) |
|
|
|
deleted_pat = utils.get_interval(data, del_mid_index, self.state['WINDOW_SIZE']) |
|
|
|
deleted_pat = utils.get_interval(data, del_mid_index, self.state['WINDOW_SIZE']) |
|
|
|
deleted_pat = utils.subtract_min_without_nan(deleted_pat) |
|
|
|
deleted_pat = utils.subtract_min_without_nan(deleted_pat) |
|
|
|
del_conv_pat = scipy.signal.fftconvolve(deleted_pat, self.state['model_gen']) |
|
|
|
del_conv_pat = scipy.signal.fftconvolve(deleted_pat, self.state['pattern_model']) |
|
|
|
if len(del_conv_pat): del_conv_list.append(max(del_conv_pat)) |
|
|
|
if len(del_conv_pat): del_conv_list.append(max(del_conv_pat)) |
|
|
|
|
|
|
|
|
|
|
|
self.state['convolve_min'], self.state['convolve_max'] = utils.get_min_max(convolve_list, self.state['WINDOW_SIZE'] / 3) |
|
|
|
self.state['convolve_min'], self.state['convolve_max'] = utils.get_min_max(convolve_list, self.state['WINDOW_SIZE'] / 3) |
|
|
@ -61,7 +62,7 @@ class GeneralModel(Model): |
|
|
|
def do_detect(self, dataframe: pd.DataFrame) -> list: |
|
|
|
def do_detect(self, dataframe: pd.DataFrame) -> list: |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = data['value'] |
|
|
|
data = data['value'] |
|
|
|
pat_data = self.state['model_gen'] |
|
|
|
pat_data = self.state['pattern_model'] |
|
|
|
if pat_data.count(0) == len(pat_data): |
|
|
|
if pat_data.count(0) == len(pat_data): |
|
|
|
raise ValueError('Labeled patterns must not be empty') |
|
|
|
raise ValueError('Labeled patterns must not be empty') |
|
|
|
|
|
|
|
|
|
|
@ -77,7 +78,7 @@ class GeneralModel(Model): |
|
|
|
return set(item + self.state['WINDOW_SIZE'] for item in filtered) |
|
|
|
return set(item + self.state['WINDOW_SIZE'] for item in filtered) |
|
|
|
|
|
|
|
|
|
|
|
def __filter_detection(self, segments: list, data: list): |
|
|
|
def __filter_detection(self, segments: list, data: list): |
|
|
|
if len(segments) == 0 or len(self.state['ipats']) == 0: |
|
|
|
if len(segments) == 0 or len(self.state.get('pattern_center', [])) == 0: |
|
|
|
return [] |
|
|
|
return [] |
|
|
|
delete_list = [] |
|
|
|
delete_list = [] |
|
|
|
for val in segments: |
|
|
|
for val in segments: |
|
|
|