Beispiel #1
0
    def test_integration_performance(self):
        self.maxDiff = None
        pipeline = Pipeline.from_json(self.load_json('pipeline'))
        input1 = Series.from_array(self.load_json('input1'), unit='ms')
        input2 = Series.from_array(self.load_json('input2'), unit='ms')

        analyzer = Analyzer(pipeline, True)
        result = analyzer.analyze({'1': input1, '2': input2})

        # pr = cProfile.Profile()
        # pr.enable()
        actual_output = result.output_format()

        # pr.disable()
        # pr.dump_stats('output.prof')
        # s = io.StringIO()
        # sortby = 'cumulative'
        # ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
        # ps.print_stats()
        # print(s.getvalue())

        expected_file = os.path.join(os.path.dirname(__file__),
                                     'resources/perf/expected_output.json')
        # Uncomment to fix test
        # print(json.dumps(actual_output, indent=2), file=open(expected_file, 'w'))
        expected_output = json.loads(Path(expected_file).read_text())
        self.assertEqual(expected_output, actual_output)
Beispiel #2
0
    def test_analysis_histogram_heatmap(self):
        self.maxDiff = None
        series = Series.from_array([
            [1628294400, 0],
            [1628337600, 0],
            [1628380800, 1],
            [1628424000, 1],
            [1628467200, 1],
            [1628510400, 0],
            [1628553600, 0],
            [1628596800, 0],
        ])
        factory = NodeFactory.detector('test_node', 'SimpleThreshold')
        factory.set_param_value('inside', False)
        factory.set_param_value('strict', False)
        factory.set_param_value('lower', None)
        factory.set_param_value('upper', 1)
        factory.add_source(InputRef('input'))
        node = factory.build()

        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=True)
        analysis = analyzer.analyze({'input': series})
        actual_output = analysis.output_format()

        expected_file = os.path.join(os.path.dirname(__file__), 'resources/analysis/expected_histogram_heatmap.json')
        # Uncomment to fix test
        # print(json.dumps(actual_output, indent=2), file=open(expected_file, 'w'))
        expected_output = json.loads(Path(expected_file).read_text())
        self.assertEqual(expected_output, actual_output)
Beispiel #3
0
    def case(self, series, node, expected_series):
        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=True)
        inputs = {'input': series}
        analysis = analyzer.analyze(inputs)
        result = analysis.result_for_node(node.id)

        self.assertEqual(expected_series, result.output_series.as_list())
Beispiel #4
0
    def case(self, node, expected_series):
        series = self.build_series()
        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=False)
        analysis = analyzer.analyze({'input': series})
        result = analysis.result_for_node(node.id)

        self.assertEqual(expected_series, result.output_series.as_list())
Beispiel #5
0
    def case(self, node, s1, s2, expected_index, expected_series):
        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=False)
        analysis = analyzer.analyze({'lhs': s1, 'rhs': s2})
        result = analysis.result_for_node(node.id)
        output_series = result.output_series

        self.assertEqual(expected_series, output_series.as_list())
        self.assertEqual(expected_index, list(output_series.pdseries.index))
Beispiel #6
0
 def case(self, node, expected_series, debug_info):
     series = self.build_triangle()
     pipeline = Pipeline([node])
     analyzer = Analyzer(pipeline=pipeline, debug=False)
     analysis = analyzer.analyze({'input': series})
     result = analysis.result_for_node(node.id)
     self.assertEqual(result.debug_info, debug_info)
     actual_series = result.output_series.as_list()
     for i in range(0, len(expected_series)):
         self.assertAlmostEqual(expected_series[i], actual_series[i], 2)
Beispiel #7
0
 def start_all(self):
     for conf in self.camera_service.get_configs():
         analyzer = Analyzer(self.event_service, self.area_service, conf)
         thread = threading.Thread(target=analyzer.video)
         thread.start()
         self.analyzers[conf] = analyzer
     return True
Beispiel #8
0
    def test_analysis_without_debug(self):
        self.maxDiff = None
        series = self.build_triangle()
       
        factory = NodeFactory.transformer('test_node', 'RollingAggregate')
        factory.set_param_value('window', 5)
        factory.set_param_value('center', False)
        factory.set_param_value('min_periods', 0)
        factory.set_param_value('agg_method', 'max')
        factory.add_source(InputRef('input'))
        node = factory.build()

        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=False)
        analysis = analyzer.analyze({'input':series})

        expected = {
            "anomalies": [],
            "series": {
                "input": [
                    [0, 0.0],
                    [1000, 1.0],
                    [2000, 2.0],
                    [3000, 3.0],
                    [4000, 4.0],
                    [5000, 5.0],
                    [6000, 6.0],
                    [7000, 7.0],
                    [8000, 8.0],
                    [9000, 9.0],
                    [10000, 9.0],
                    [11000, 8.0],
                    [12000, 7.0],
                    [13000, 6.0],
                    [14000, 5.0],
                    [15000, 4.0],
                    [16000, 3.0],
                    [17000, 2.0],
                    [18000, 1.0],
                    [19000, 0.0],
                ]
            },
        }

        self.assertEqual(expected, analysis.output_format())
Beispiel #9
0
 def start(self, id):
     conf = self.camera_service.get_config(id)
     if conf is None or conf in self.analyzers.keys():
         return False
     else:
         analyzer = Analyzer(self.event_service, self.area_service, conf)
         thread = threading.Thread(target=analyzer.video)
         thread.start()
         self.analyzers[conf] = analyzer
         return True
Beispiel #10
0
    def case(self, node, expected_anomalies):
        series = self.build_triangle()
        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=False)
        analysis = analyzer.analyze({'input': series})
        anomalies = analysis.anomalies

        for i in range(len(expected_anomalies)):
            expected_anomaly = expected_anomalies[i]
            self.assertEqual(
                {
                    'source_node': node.id,
                    'id': anomalies[i].id(),
                    'from': expected_anomaly[0] * 1000,
                    'to': expected_anomaly[1] * 1000,
                    'duration': expected_anomaly[1] - expected_anomaly[0],
                    'score': 1.0,
                    'source_anomalies': [],
                }, anomalies[i].output_format())
        self.assertEqual(len(expected_anomalies), len(anomalies))
Beispiel #11
0
    def test_analysis_with_debug(self):
        self.maxDiff = None
        series = self.build_triangle()
       
        factory = NodeFactory.transformer('test_node', 'RollingAggregate')
        factory.set_param_value('window', 5)
        factory.set_param_value('center', False)
        factory.set_param_value('min_periods', 0)
        factory.set_param_value('agg_method', 'max')
        factory.add_source(InputRef('input'))
        node = factory.build()

        pipeline = Pipeline([node])
        analyzer = Analyzer(pipeline=pipeline, debug=True)
        analysis = analyzer.analyze({'input': series})
        actual_output = analysis.output_format()

        expected_file = os.path.join(os.path.dirname(__file__), 'resources/analysis/expected_simplified.json')
        # Uncomment to fix test
        # print(json.dumps(actual_output, indent=2), file=open(expected_file, 'w'))
        expected_output = json.loads(Path(expected_file).read_text())
        self.assertEqual(expected_output, actual_output)
Beispiel #12
0
from sys import argv

from config.yoloconfig import YoloConfig
from model.analyzer import Analyzer
from services.areaservice import AreaService
from services.cameraservice import CameraService
from services.eventservice import EventService

event_service = EventService()
area_service = AreaService(event_service)
camera_service = CameraService(area_service)
yolo_config = YoloConfig(608, "yolo/cfg/yolov3-320.weights",
                         "yolo/cfg/yolov3.txt", "yolo/cfg/yolov3-320.cfg")
camera_id = camera_service.add_config("kamera", "192.168.0.119", "admin",
                                      "camera123", False)
area_id = area_service.insert_area(0.5, 50, 50, 600, 600, camera_id)
try:
    camera_config = camera_service.get_config(camera_id)
    camera_analyzer = Analyzer(event_service, area_service, camera_config,
                               yolo_config)
    # camera_analyzer.set_show_size(700, 500)
    camera_analyzer.video()

finally:
    camera_service.delete_config(camera_id)
    for area in area_service.get_areas():
        area_service.delete_area(area.id)