Exemplo n.º 1
0
 def test_find_drop_parameters_height(self):
     segment = [
         5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 1, 1, 1, 1, 1, 1,
         1, 1, 1, 1, 1
     ]
     segment = pd.Series(segment)
     drop_height = [3.5, 4]
     self.assertGreaterEqual(
         utils.find_parameters(segment, 0, 'drop')[0], drop_height[0])
     self.assertLessEqual(
         utils.find_parameters(segment, 0, 'drop')[0], drop_height[1])
Exemplo n.º 2
0
 def test_find_jump_parameters_height(self):
     segment = [
         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
         5, 5, 5, 5, 5
     ]
     segment = pd.Series(segment)
     jump_height = [3.5, 4]
     self.assertGreaterEqual(
         utils.find_parameters(segment, 0, 'jump')[0], jump_height[0])
     self.assertLessEqual(
         utils.find_parameters(segment, 0, 'jump')[0], jump_height[1])
Exemplo n.º 3
0
 def get_parameters_from_segments(self, dataframe: pd.DataFrame, labeled: List[dict], deleted: List[dict], model: ModelType) -> dict:
     logging.debug('Start parsing segments')
     learning_info = LearningInfo()
     data = dataframe['value']
     for segment in labeled:
         confidence = utils.find_confidence(segment.data)[0]
         learning_info.confidence.append(confidence)
         segment_center = segment.center_index
         learning_info.segment_center_list.append(segment_center)
         learning_info.pattern_timestamp.append(segment.pattern_timestamp)
         aligned_segment = utils.get_interval(data, segment_center, self.state.window_size)
         aligned_segment = utils.subtract_min_without_nan(aligned_segment)
         if len(aligned_segment) == 0:
             logging.warning('cant add segment to learning because segment is empty where segments center is: {}, window_size: {}, and len_data: {}'.format(
                 segment_center, self.state.window_size, len(data)))
             continue
         learning_info.patterns_list.append(aligned_segment)
         # TODO: use Triangle/Stair types
         if model == ModelType.PEAK or model == ModelType.TROUGH:
             learning_info.pattern_height.append(utils.find_confidence(aligned_segment)[1])
             learning_info.patterns_value.append(aligned_segment.values.max())
         if model == ModelType.JUMP or model == ModelType.DROP:
             pattern_height, pattern_length = utils.find_parameters(segment.data, segment.from_index, model.value)
             learning_info.pattern_height.append(pattern_height)
             learning_info.pattern_width.append(pattern_length)
             learning_info.patterns_value.append(aligned_segment.values[self.state.window_size])
     logging.debug('Parsing segments ended correctly with learning_info: {}'.format(learning_info))
     return learning_info
Exemplo n.º 4
0
 def test_find_drop_parameters_length(self):
     segment = [
         5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 1, 1, 1, 1, 1, 1,
         1, 1, 1, 1, 1
     ]
     segment = pd.Series(segment)
     drop_length = 2
     self.assertEqual(
         utils.find_parameters(segment, 0, 'drop')[1], drop_length)
Exemplo n.º 5
0
 def test_find_jump_parameters_length(self):
     segment = [
         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
         5, 5, 5, 5, 5
     ]
     segment = pd.Series(segment)
     jump_length = 2
     self.assertEqual(
         utils.find_parameters(segment, 0, 'jump')[1], jump_length)