|
|
@ -17,7 +17,7 @@ class TroughModel(Model): |
|
|
|
super() |
|
|
|
super() |
|
|
|
self.segments = [] |
|
|
|
self.segments = [] |
|
|
|
self.itroughs = [] |
|
|
|
self.itroughs = [] |
|
|
|
self.model_trough = [] |
|
|
|
self.model = [] |
|
|
|
self.state = { |
|
|
|
self.state = { |
|
|
|
'confidence': 1.5, |
|
|
|
'confidence': 1.5, |
|
|
|
'convolve_max': 570000, |
|
|
|
'convolve_max': 570000, |
|
|
@ -27,64 +27,34 @@ class TroughModel(Model): |
|
|
|
'conv_del_max': 55000, |
|
|
|
'conv_del_max': 55000, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def do_fit(self, dataframe: pd.DataFrame, segments: list) -> None: |
|
|
|
def do_fit(self, dataframe: pd.DataFrame, labeled_segments: list, deleted_segments: list) -> None: |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = data['value'] |
|
|
|
data = data['value'] |
|
|
|
confidences = [] |
|
|
|
confidences = [] |
|
|
|
convolve_list = [] |
|
|
|
convolve_list = [] |
|
|
|
patterns_list = [] |
|
|
|
patterns_list = [] |
|
|
|
for segment in segments: |
|
|
|
|
|
|
|
if segment['labeled']: |
|
|
|
for segment in labeled_segments: |
|
|
|
segment_from_index = segment.get('from') |
|
|
|
confidence = utils.find_confidence(segment.data) |
|
|
|
segment_to_index = segment.get('to') |
|
|
|
|
|
|
|
segment_data = segment.get('data') |
|
|
|
|
|
|
|
confidence = utils.find_confidence(segment_data) |
|
|
|
|
|
|
|
confidences.append(confidence) |
|
|
|
confidences.append(confidence) |
|
|
|
segment_min_index = segment_data.idxmin() |
|
|
|
segment_min_index = segment.data.idxmin() |
|
|
|
self.itroughs.append(segment_min_index) |
|
|
|
self.itroughs.append(segment_min_index) |
|
|
|
labeled_trough = utils.get_interval(data, segment_min_index, self.state['WINDOW_SIZE']) |
|
|
|
labeled = utils.get_interval(data, segment_min_index, self.state['WINDOW_SIZE']) |
|
|
|
labeled_trough = utils.subtract_min_without_nan(labeled_trough) |
|
|
|
labeled = utils.subtract_min_without_nan(labeled) |
|
|
|
patterns_list.append(labeled_trough) |
|
|
|
patterns_list.append(labeled) |
|
|
|
|
|
|
|
|
|
|
|
self.model_trough = utils.get_av_model(patterns_list) |
|
|
|
self.model = utils.get_av_model(patterns_list) |
|
|
|
convolve_list = utils.get_convolve(self.itroughs, self.model_trough, data, self.state['WINDOW_SIZE']) |
|
|
|
convolve_list = utils.get_convolve(self.itroughs, self.model, data, self.state['WINDOW_SIZE']) |
|
|
|
|
|
|
|
|
|
|
|
del_conv_list = [] |
|
|
|
del_conv_list = [] |
|
|
|
for segment in segments: |
|
|
|
for segment in deleted_segments: |
|
|
|
if segment['deleted']: |
|
|
|
del_min_index = segment.data.idxmin() |
|
|
|
segment_from_index = segment.get('from') |
|
|
|
deleted = utils.get_interval(data, del_min_index, self.state['WINDOW_SIZE']) |
|
|
|
segment_to_index = segment.get('to') |
|
|
|
deleted = utils.subtract_min_without_nan(deleted) |
|
|
|
segment_data = segment.get('data') |
|
|
|
del_conv = scipy.signal.fftconvolve(deleted, self.model) |
|
|
|
del_min_index = segment_data.idxmin() |
|
|
|
if len(del_conv): del_conv_list.append(max(del_conv)) |
|
|
|
deleted_trough = utils.get_interval(data, del_min_index, self.state['WINDOW_SIZE']) |
|
|
|
|
|
|
|
deleted_trough = utils.subtract_min_without_nan(deleted_trough) |
|
|
|
|
|
|
|
del_conv_trough = scipy.signal.fftconvolve(deleted_trough, self.model_trough) |
|
|
|
|
|
|
|
del_conv_list.append(max(del_conv_trough)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(confidences) > 0: |
|
|
|
|
|
|
|
self.state['confidence'] = float(min(confidences)) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.state['confidence'] = 1.5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(convolve_list) > 0: |
|
|
|
|
|
|
|
self.state['convolve_max'] = float(max(convolve_list)) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.state['convolve_max'] = self.state['WINDOW_SIZE'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(convolve_list) > 0: |
|
|
|
self._update_fiting_result(self.state, confidences, convolve_list, del_conv_list) |
|
|
|
self.state['convolve_min'] = float(min(convolve_list)) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
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_detect(self, dataframe: pd.DataFrame): |
|
|
|
def do_detect(self, dataframe: pd.DataFrame): |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
|
data = utils.cut_dataframe(dataframe) |
|
|
@ -111,7 +81,7 @@ class TroughModel(Model): |
|
|
|
if len(segments) == 0 or len(self.itroughs) == 0 : |
|
|
|
if len(segments) == 0 or len(self.itroughs) == 0 : |
|
|
|
segments = [] |
|
|
|
segments = [] |
|
|
|
return segments |
|
|
|
return segments |
|
|
|
pattern_data = self.model_trough |
|
|
|
pattern_data = self.model |
|
|
|
for segment in segments: |
|
|
|
for segment in segments: |
|
|
|
if segment > self.state['WINDOW_SIZE']: |
|
|
|
if segment > self.state['WINDOW_SIZE']: |
|
|
|
convol_data = utils.get_interval(data, segment, self.state['WINDOW_SIZE']) |
|
|
|
convol_data = utils.get_interval(data, segment, self.state['WINDOW_SIZE']) |
|
|
|