def main(config):
    logging.basicConfig(level=logging.INFO)
    if isinstance(config, str):
        config = ConfigEngine(config)
    libs.pubsub.init_shared_resources()

    video_path = config.get_section_dict("App")["VideoPath"]
    process_engine = Process(target=start_engine, args=(config, video_path,))
    process_api = Process(target=start_web_gui, args=(config,))

    process_api.start()
    process_engine.start()
    logger.info("Services Started.")

    forever = threading.Event()
    try:
        forever.wait()
    except KeyboardInterrupt:
        logger.info("Received interrupt. Terminating...")

    process_engine.terminate()
    process_engine.join()
    logger.info("CV Engine terminated.")
    process_api.terminate()
    process_api.join()
    logger.info("Web GUI terminated.")
Exemple #2
0
def main(config):
    logging.basicConfig(level=logging.INFO)
    if isinstance(config, str):
        config = ConfigEngine(config)

    if not config.get_boolean('Logger', 'EnableReports'):
        logger.info("Reporting disabled!")
    else:
        logger.info("Reporting enabled!")
        schedule.every().day.at("00:01").do(create_daily_report, config=config)

    sources = config.get_video_sources()
    areas = config.get_areas()
    for src in sources:
        if src['daily_report']:
            schedule.every().day.at(src['daily_report_time']).do(
                send_daily_report_notification, config=config, entity_info=src)
    for area in areas:
        if area['daily_report']:
            schedule.every().day.at(area['daily_report_time']).do(
                send_daily_report_notification, config=config, entity_info=area)

    while True:
        schedule.run_pending()
        time.sleep(10)
Exemple #3
0
def main(config):
    logging.basicConfig(level=logging.INFO)
    if isinstance(config, str):
        config = ConfigEngine(config)

    # Schedule configured periodic tasks
    periodic_tasks_names = [
        x for x in config.get_sections() if x.startswith("PeriodicTask_")
    ]
    for p_task in periodic_tasks_names:
        if not config.get_boolean(p_task, "Enabled"):
            continue
        task_name = config.get_section_dict(p_task).get("Name")
        if task_name == "metrics":
            logger.info("Metrics enabled!")
            schedule.every().day.at("00:01").do(compute_daily_metrics,
                                                config=config)
            schedule.every().hour.at(":01").do(compute_hourly_metrics,
                                               config=config)
            live_interval = int(
                config.get_section_dict(p_task).get("LiveInterval", 10))
            schedule.every(live_interval).minutes.do(
                compute_live_metrics,
                config=config,
                live_interval=live_interval)
        else:
            raise ValueError(f"Not supported periodic task named: {task_name}")

    # Schedule daily/weekly reports for sources and areas
    sources = config.get_video_sources()
    areas = config.get_areas()
    for src in sources:
        if src['daily_report']:
            schedule.every().day.at(src['daily_report_time']).do(
                send_daily_report_notification, config=config, entity_info=src)
    for area in areas:
        if area['daily_report']:
            schedule.every().day.at(area['daily_report_time']).do(
                send_daily_report_notification,
                config=config,
                entity_info=area)
    if config.get_boolean("App", "DailyGlobalReport"):
        schedule.every().day.at(
            config.get_section_dict("App")["GlobalReportTime"]).do(
                send_daily_global_report,
                config=config,
                sources=sources,
                areas=areas)
    if config.get_boolean("App", "WeeklyGlobalReport"):
        schedule.every(7).days.at(
            config.get_section_dict("App")["GlobalReportTime"]).do(
                send_weekly_global_report,
                config=config,
                sources=sources,
                areas=areas)

    while True:
        schedule.run_pending()
        time.sleep(10)
def test_get_config():
    config = ConfigEngine(config_sample_path)
    app_instance = ProcessorAPI(config)
    api = app_instance.app
    client = TestClient(api)

    response_get = client.get("/config")

    assert response_get.status_code == 200
    assert response_get.json() == config_sample_json
def get_config_file_json_strings(config_sample_path, decamelize=False):
    config_sample = ConfigEngine(config_sample_path)
    sections = config_sample.get_sections()
    config_sample_json = {}

    for section in sections:
        config_sample_json[section] = config_sample.get_section_dict(section)

    if decamelize:
        """
        Do not forget that "Source_1" becomes "source__1". 
        """
        config_sample_json = humps.decamelize(config_sample_json)

    return config_sample_json
def config_rollback():
    original_path = "/repo/api/tests/data/config-x86-openvino.ini"
    config_sample_path_to_modify = "/repo/api/tests/data/config-x86-openvino_TEMPORARY.ini"
    shutil.copyfile(original_path, config_sample_path_to_modify)

    config = ConfigEngine(config_sample_path_to_modify)
    Settings(config=config)

    # Import ProcessorAPI after Settings has been initialized with a config.
    from api.processor_api import ProcessorAPI

    app_instance = ProcessorAPI()
    api = app_instance.app
    client = TestClient(api)
    yield client, config_sample_path_to_modify

    os.remove(config_sample_path_to_modify)
Exemple #7
0
def config_rollback_base(option="JUST_CAMERAS"):
    original_path = ""
    if option == "EMPTY":
        """
        Empty template with no camera or area.
        """
        original_path = "/repo/api/tests/data/config-x86-openvino_EMPTY.ini"
    elif option == "JUST_CAMERAS":
        """
        Here there are charged only 2 cameras:
            camera_example (ID: 49)
            camera_example_2 (ID: 50)
        """
        original_path = "/repo/api/tests/data/config-x86-openvino_JUST_CAMERAS.ini"
    elif option == "METRICS":
        """
        Here there are charged 4 cameras and two areas:
            camera_example (ID: 49), Area 5
            camera_example_2 (ID: 50), Area 5
            camera_example_3 (ID: 51), Area 6
            camera_example_4 (ID: 52), Area 6
        """
        original_path = "/repo/api/tests/data/config-x86-openvino_METRICS.ini"
    config_sample_path_to_modify = "/repo/api/tests/data/config-x86-openvino_TEMPORARY.ini"
    shutil.copyfile(original_path, config_sample_path_to_modify)

    config = ConfigEngine(config_sample_path_to_modify)
    Settings(config=config)

    # Import ProcessorAPI after Settings has been initialized with a config.
    from api.processor_api import ProcessorAPI

    app_instance = ProcessorAPI()
    api = app_instance.app
    client = TestClient(api)
    return client, config_sample_path_to_modify
Exemple #8
0
 def __init__(self, args):
     self.config = ConfigEngine(args.config)
     self.engine = CvEngine(self.config)
     self.ui = UI(self.config, self.engine)
     self.engine.set_ui(self.ui)
     self.ui.start()
def main(config):
    logging.basicConfig(level=logging.INFO)
    if isinstance(config, str):
        config = ConfigEngine(config)
    Settings(config=config)
    start_api(config)
from fastapi.testclient import TestClient
from libs.config_engine import ConfigEngine
from api.models.base import Config
from api.processor_api import ProcessorAPI
import pytest
import humps
import copy

config_sample_path='/repo/api/models/data/config-sample.ini'
config = ConfigEngine(config_sample_path)
app_instance = ProcessorAPI(config)
api = app_instance.app
client = TestClient(api)


# read sample config file
config_sample = ConfigEngine(config_sample_path)
sections = config_sample.get_sections()
config_sample_json = {}

for section in sections:
    config_sample_json[section] = config_sample.get_section_dict(section)

config_sample_json = humps.decamelize(config_sample_json)

#@pytest.mark.order1
def test_set_config():
    response = client.put(
        "/config",
        json=config_sample_json,
    )
Exemple #11
0
def main(config):
    logging.basicConfig(level=logging.INFO)
    if isinstance(config, str):
        config = ConfigEngine(config)

    start_core(config)