def initialize_environment() -> bool:
     try:
         return CacheRedisAdapter.initialize()
     except Exception as ex:
         logger.error(
             'initialize_environment test_method Exception: {}'.format(ex))
         return False
Ejemplo n.º 2
0
    def initialize_catalog() -> bool:
        try:
            CacheRedisAdapter.initialize()

            CacheRedisAdapter.dictionary_create(
                label_info=UtilityCatalogCached.LABEL_DICTIONARY_TOPICS)
            CacheRedisAdapter.dictionary_create(
                label_info=UtilityCatalogCached.
                LABEL_DICTIONARY_DEVICE_REGISTRATION)

            UtilityCatalogCached.configure_catalog_observable_backup(
                [LabelObservationType.LABEL_OBSTYPE_LOCALIZATION])

            return True

        except Exception as ex:
            logger.error('initialize_catalog Exception: {}'.format(ex))
            return False
Ejemplo n.º 3
0
    def test_method_queue_detection() -> bool:
        try:
            CacheRedisAdapter.initialize()

            logger.info('test_method_queue_detection Started')
            crowd_density_local = CrowdDensityLocalObservation()
            crowd_density_local.density_map = UnitTestQueueDetection.get_densitymap(
            )

            camera_registration = CameraRegistration(
                ground_plane_position=Point(x=12.56539, y=55.67474, srid=4326),
                ground_plane_orientation=30)

            logger.info('test_method_queue_detection Third Step')
            dictionary_regions = QueueDetectionAlgorithm.find_queueshape_areas(
                density_map=crowd_density_local.density_map, min_cell_count=3)

            count_queueshapearea_saved = 0

            logger.info('test_method_queue_detection Fourth Step')
            for mean_people in dictionary_regions.keys():

                logger.info(
                    'test_method_queue_detection mean count queue: {}'.format(
                        mean_people))

                group_region = dictionary_regions[mean_people]

                if not group_region or group_region.empty():
                    logger.info(
                        'test_method_queue_detection group_region empty')
                    continue

                logger.info(
                    'test_method_queue_detection group_region count: {}'.
                    format(len(group_region)))

                for region in group_region.get_listregions():
                    if not region:
                        continue

                    logger.info(
                        'test_method_queue_detection single queue detection creation...'
                    )
                    single_queue_detection = QueueDetectionAlert()
                    single_queue_detection.qsma_id = "QSA_ID{0:02d}_Mean{1:03d}".format(
                        count_queueshapearea_saved, mean_people)
                    single_queue_detection.initialize_status()
                    logger.info(
                        'test_method_queue_detection single queue detection created'
                    )

                    single_queue_detection.set_region_queue(
                        region_queue=region,
                        camera_registration=camera_registration)

                    single_queue_detection.mean_people = mean_people
                    single_queue_detection.set_timestamp(
                        timestamp=datetime.datetime.now(tz=pytz.utc))

                    logger.info(
                        'test_method_queue_detection Try Saving SingleQueueDetection'
                    )
                    single_queue_detection.save()
                    logger.info(
                        'test_method_queue_detection saved single_queue_detection: {}'
                        .format(single_queue_detection.qda_id))
                    count_queueshapearea_saved += 1

                    json_test = single_queue_detection.to_dictionary()
                    json_test1 = single_queue_detection.to_ogc_dictionary()
                    string_test = single_queue_detection.to_string()

                    CacheRedisAdapter.set_cache_info(
                        label_info='DATATESTSAVED', data=json_test1)

                    json_test_2 = CacheRedisAdapter.get_cached_info(
                        label_info='DATATESTSAVED', type_data=dict)

                    logger.info('Cached JSON: {}'.format(json_test1))
                    logger.info('Read JSON From Cache: {}'.format(json_test_2))

                    queue_detection_db = UtilityDatabase.get_outputmessage_byid(
                        id=single_queue_detection.qda_id,
                        outputmessagetype=OutputMessageType.
                        OUTPUT_MESSAGE_TYPE_QUEUEDETECTIONALERT)
                    json_test_db = queue_detection_db.to_dictionary()
                    string_test_db = queue_detection_db.to_string()

                    if UnitTestQueueDetection.compare_dictionaries(
                            dict_a=json_test, dict_b=json_test_db):
                        logger.info(
                            'Comparison JSON From hardcoded to DB extracted QueueDetectionAlert info are equals'
                        )
                    else:
                        logger.info(
                            'Comparison JSON From hardcoded to DB extracted QueueDetectionAlert are not equals'
                        )

                    logger.info('String Hardcoded: {}'.format(string_test))
                    logger.info(
                        'String DB Extracted: {}'.format(string_test_db))

            logger.info(
                'test_method_queue_detection saved correctly {} QueueDetectionAlert'
                .format(count_queueshapearea_saved))

            return True
        except Exception as ex:
            logger.error(
                'UnitTestQueueDetection test_method_queue_detection test_method Exception: {}'
                .format(ex))
            return False