Example #1
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 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.")
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
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,
    )
    assert response.status_code == 200
    assert response.json() == config_sample_json

#@pytest.mark.order2
def test_set_invalid_video_path():
    wrong_json = copy.deepcopy(config_sample_json)