From b87aa23e280b4c07706116436de88c4a50223d1c Mon Sep 17 00:00:00 2001 From: max_metz Date: Fri, 13 Oct 2023 12:23:27 +0200 Subject: [PATCH] shipcall evaluation now also supports a shipcall_id argument, so only a single Shipcall is evaluated. Updating requirements.txt after installing the virtual environment for the first time on a Windows laptop. Updating the berth-stub according to the recent berth changes (owner id & authority id). --- change_log_metz.md | 2 +- environment.yml | 3 --- .../brecal_utils/database/update_database.py | 14 +++++++++++--- src/lib_brecal_utils/brecal_utils/stubs/berth.py | 6 +++++- src/server/requirements.txt | 13 +++++++++++-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/change_log_metz.md b/change_log_metz.md index 60a2dee..8f3f8f6 100644 --- a/change_log_metz.md +++ b/change_log_metz.md @@ -2,7 +2,7 @@ # 20231013: Adding the shipcall evaluation (traffic state). Provided a one-line function to connect, evaluate and update the shipcalls in a database The sql database can now be properly updated by SQL calls (using mysql.connector and pydapper) -Preparing a pull request, where all necessary changes are provided. +Created a pull request, where all necessary changes are provided. # TODO: there must be a call function in the application, which asks for an update of the evaluation state & message. Discussing with Daniel Schick. diff --git a/environment.yml b/environment.yml index 6f4c81a..91dc964 100644 --- a/environment.yml +++ b/environment.yml @@ -14,9 +14,6 @@ dependencies: - ipython>=8.14.0=pyh41d4057_0 - jupyterlab>=4.0.5=pyhd8ed1ab_0 - mamba>=1.4.9=py311h3072747_0 - - conda-forge::matplotlib-base>=3.7.2=py311h54ef318_0 - - conda-forge::matplotlib>=3.7.2=py311h38be061_0 - - matplotlib-inline>=0.1.6=pyhd8ed1ab_0 - conda-forge::pytest>=7.4.0=pyhd8ed1ab_0 - conda-forge::pytest-cov>=4.1.0=pyhd8ed1ab_0 - python>=3.11.4=hab00c5b_0_cpython diff --git a/src/lib_brecal_utils/brecal_utils/database/update_database.py b/src/lib_brecal_utils/brecal_utils/database/update_database.py index 0ed293d..fe3e9ef 100644 --- a/src/lib_brecal_utils/brecal_utils/database/update_database.py +++ b/src/lib_brecal_utils/brecal_utils/database/update_database.py @@ -60,7 +60,7 @@ def update_all_shipcalls_in_mysql_database(sql_connection, sql_handler:SQLHandle update_shipcall_in_mysql_database(sql_connection, shipcall=shipcall, relevant_keys = ["evaluation", "evaluation_message"]) return -def run_validation_rules(mysql_connector_instance, debug=False)->pd.DataFrame: +def run_validation_rules(mysql_connector_instance, shipcall_id:int=None, debug=False)->pd.DataFrame: """ options: mysql_connector_instance: an instance created by the mysql.connector.connect() call. It is advised to use Python's context manager to close the connection after finished. @@ -74,6 +74,10 @@ def run_validation_rules(mysql_connector_instance, debug=False)->pd.DataFrame: vr = ValidationRules(sql_handler) shipcall_df = sql_handler.df_dict.get("shipcall") + + if shipcall_id is not None: + shipcall_df = shipcall_df.loc[[shipcall_id]] + # placeholder: filter shipcalls. For example, exclude historic entries. shipcall_df = vr.evaluate_shipcalls(shipcall_df) @@ -84,12 +88,16 @@ def run_validation_rules(mysql_connector_instance, debug=False)->pd.DataFrame: update_all_shipcalls_in_mysql_database(sql_connection=mysql_connector_instance, sql_handler=sql_handler, shipcall_df=shipcall_df) return shipcall_df -def update_shipcall_evaluation_state(mysql_connection_data)->pd.DataFrame: +def update_shipcall_evaluation_state(mysql_connection_data:dict, shipcall_id:int=None)->pd.DataFrame: """ single line function to connect to a mysql database (using the {mysql_connection_data}), evaluate each shipcall (bei traffic state) and finally, update those in the database. + + options: + mysql_connection_data: connection data to the mysql database (e.g., port, host, password) + shipcall_id: int. ID of the shipcall to be updated. Defaults to 'None'. When providing 'None', all shipcalls are updated. """ with mysql.connector.connect(**mysql_connection_data) as mysql_connector_instance: - shipcall_df = run_validation_rules(mysql_connector_instance=mysql_connector_instance, debug=False) + shipcall_df = run_validation_rules(mysql_connector_instance=mysql_connector_instance, shipcall_id=shipcall_id, debug=False) return shipcall_df diff --git a/src/lib_brecal_utils/brecal_utils/stubs/berth.py b/src/lib_brecal_utils/brecal_utils/stubs/berth.py index a335c18..8de9c36 100644 --- a/src/lib_brecal_utils/brecal_utils/stubs/berth.py +++ b/src/lib_brecal_utils/brecal_utils/stubs/berth.py @@ -7,8 +7,10 @@ def get_berth_simple(): # Note: #TODO: name, participant_id & lock state are arbitrary name = "Avangard Dalben" - participant_id = 1 # e.g., Avangard + participant_id = 1# e.g., Avangard lock = False + owner_id = 1 # e.g., Avangard + authority_id = 1 # e.g., Avangard created = datetime.datetime.now() modified = created+datetime.timedelta(seconds=10) @@ -19,6 +21,8 @@ def get_berth_simple(): name, participant_id, lock, + owner_id, + authority_id, created, modified, deleted, diff --git a/src/server/requirements.txt b/src/server/requirements.txt index 2f648ee..37b155a 100644 --- a/src/server/requirements.txt +++ b/src/server/requirements.txt @@ -3,15 +3,24 @@ Flask==1.1.2 itsdangerous==1.1.0 Jinja2==2.11.2 MarkupSafe==1.1.1 -marshmallow==3.9.1 +marshmallow>=3.9.1 webargs==6.1.1 Werkzeug==1.0.1 pydapper[mysql-connector-python] marshmallow-dataclass bcrypt -jwt +pyjwt flask-jwt-extended numpy pandas +tqdm +schedule + +pytest +pytest-cov +coverage + +../server/. +../lib_brecal_utils/.