From fbd974fce7b375af7c8533b45136702e2cd28e5e Mon Sep 17 00:00:00 2001 From: "c.winger" Date: Tue, 14 May 2024 14:31:27 +0200 Subject: [PATCH 1/2] fix network loading and reduce warnings/logging, closes #370 --- .streamlit/config.toml | 2 +- ptxboa/__init__.py | 6 ++++++ ptxboa/api.py | 5 ++++- ptxboa/api_optimize.py | 12 ++++++------ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.streamlit/config.toml b/.streamlit/config.toml index bb33bffb..5da85d58 100644 --- a/.streamlit/config.toml +++ b/.streamlit/config.toml @@ -6,7 +6,7 @@ font="sans serif" [logger] - level="INFO" + level="WARNING" [browser] gatherUsageStats = false diff --git a/ptxboa/__init__.py b/ptxboa/__init__.py index 70c0fe95..dd395f09 100644 --- a/ptxboa/__init__.py +++ b/ptxboa/__init__.py @@ -2,8 +2,14 @@ """Common Paths and settings.""" import logging import os +import warnings from pathlib import Path +# disable warnings for loading networks + +warnings.filterwarnings("ignore", category=DeprecationWarning) + + IS_TEST = "PYTEST_CURRENT_TEST" in os.environ # TODO unused KEY_SEPARATOR = "," diff --git a/ptxboa/api.py b/ptxboa/api.py index 0b4e58be..ce32cfaf 100644 --- a/ptxboa/api.py +++ b/ptxboa/api.py @@ -286,7 +286,10 @@ def get_flh_opt_network( user_data=user_data, optimize_flh=True, ) - hashsum = metadata["flh_opt_hash"]["hash_md5"] + hashsum = metadata.get("flh_opt_hash", {}).get("hash_md5") + if not hashsum: + return None + data_handler = DataHandler( scenario, user_data, data_dir=self.data_dir, cache_dir=self.cache_dir ) diff --git a/ptxboa/api_optimize.py b/ptxboa/api_optimize.py index 93efc120..709ad0dc 100644 --- a/ptxboa/api_optimize.py +++ b/ptxboa/api_optimize.py @@ -75,7 +75,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): else: # move file to target os.rename(self.filepath_tmp, self.filepath) - logger.info(f"saved file {self.filepath}") + logger.debug(f"saved file {self.filepath}") class ProfilesHashes(metaclass=SingletonMeta): @@ -92,7 +92,7 @@ def __init__(self, profiles_path): def _read_metadata(self, filename): """Read metadata json file.""" filepath = f"{self.profiles_path}/{filename}" - logger.info(f"READ {filepath}") + logger.debug(f"READ {filepath}") with open(filepath, encoding="utf-8") as file: data = json.load(file) return data @@ -362,18 +362,18 @@ def get_data(self, data: CalculateDataType) -> CalculateDataType: # load existing results opt_output_data = self._load(hash_filepath) + self._merge_data(data, opt_output_data) + # also add flh_opt_hash if it exists so we can # retrieve the network later if use_cache: - opt_output_data["flh_opt_hash"] = { + data["flh_opt_hash"] = { "hash_md5": hash_sum, "filepath": hash_filepath, } else: - opt_output_data["flh_opt_hash"] = { + data["flh_opt_hash"] = { "hash_md5": hash_sum, } - self._merge_data(data, opt_output_data) - return data From d26e19c4583d4a8c91a57e2bbcbd35735a3c0ab3 Mon Sep 17 00:00:00 2001 From: "c.winger" Date: Tue, 14 May 2024 14:40:13 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Bump=20version:=200.4.1=20=E2=86=92=200.4.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- .github/workflows/publish.yaml | 2 +- Dockerfile | 2 +- README.md | 2 +- ptxboa_streamlit.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index a6062381..2951201e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.4.1 +current_version = 0.4.2 commit = True tag = True diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5624754f..2f96512d 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -23,4 +23,4 @@ jobs: uses: docker/build-push-action@v5 with: push: true - tags: wingechr/ptx-boa:0.4.1 + tags: wingechr/ptx-boa:0.4.2 diff --git a/Dockerfile b/Dockerfile index d38701f7..015ac6bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.10-slim -LABEL version="0.4.1" +LABEL version="0.4.2" RUN apt-get update RUN apt-get install -y git diff --git a/README.md b/README.md index 2e1f3219..1f1e848e 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ pytest # connect to server ssh ptxboa # pull latest image from dockerhub -VERSION=0.4.1 +VERSION=0.4.2 docker pull wingechr/ptx-boa:$VERSION # stop and delete the currently running container "app" docker stop app diff --git a/ptxboa_streamlit.py b/ptxboa_streamlit.py index e1b0ace7..12f79883 100644 --- a/ptxboa_streamlit.py +++ b/ptxboa_streamlit.py @@ -6,7 +6,7 @@ >>> streamlit run ptxboa_streamlit.py """ -__version__ = "0.4.1" +__version__ = "0.4.2" # TODO how do I use the treamlit logger? import logging