コード例 #1
0
 def test_positive_and_negative_segments(self):
     data_val = [
         1.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0, 1.0, 1.0, 1.0, 5.0, 7.0, 5.0,
         1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
     ]
     dataframe = create_dataframe(data_val)
     segments = [{
         '_id': 'Esl7uetLhx4lCqHa',
         'analyticUnitId': 'opnICRJwOmwBELK8',
         'from': 1523889000004,
         'to': 1523889000006,
         'labeled': True,
         'deleted': False
     }, {
         '_id': 'Esl7uetLhx4lCqHa',
         'analyticUnitId': 'opnICRJwOmwBELK8',
         'from': 1523889000001,
         'to': 1523889000003,
         'labeled': False,
         'deleted': False
     }]
     segments = [Segment.from_json(segment) for segment in segments]
     cache = {}
     detector = pattern_detector.PatternDetector('PEAK', 'test_id')
     try:
         detector.train(dataframe, segments, cache)
     except Exception as e:
         self.fail('detector.train fail with error {}'.format(e))
コード例 #2
0
    def test_segment_generator(self):
        detector = anomaly_detector.AnomalyDetector('test_id')
        data = [1, 1, 5, 1, -4, 5, 5, 5, -3, 1]
        timestamps = create_list_of_timestamps(len(data))
        dataframe = create_dataframe(data)
        upper_bound = pd.Series([2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
        lower_bound = pd.Series([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
        segments = list(detector.detections_generator(dataframe, upper_bound, lower_bound, enabled_bounds=Bound.ALL))

        segments_borders = list(map(lambda s: [s.from_timestamp, s.to_timestamp], segments))
        self.assertEqual(segments_borders, [[timestamps[2], timestamps[2]], [timestamps[4], timestamps[8]]])