From 00ff1af71d6dfe1385d2606fdbbc9505153e97aa Mon Sep 17 00:00:00 2001 From: Nicola Tarocco Date: Tue, 12 Dec 2023 19:04:21 +0100 Subject: [PATCH] fix enums for data service --- caimira/apps/calculator/__main__.py | 13 ++++++- caimira/apps/calculator/report_generator.py | 5 ++- caimira/monte_carlo/data.py | 26 ++++++++++--- caimira/store/data_registry.py | 42 ++++++++++----------- 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/caimira/apps/calculator/__main__.py b/caimira/apps/calculator/__main__.py index ab147c7d..6bf16d30 100644 --- a/caimira/apps/calculator/__main__.py +++ b/caimira/apps/calculator/__main__.py @@ -35,12 +35,23 @@ def configure_parser(parser) -> argparse.ArgumentParser: return parser +def _init_logging(debug=False): + # Set the logging level for urllib3 and requests to WARNING + logging.getLogger("urllib3").setLevel(logging.WARNING) + logging.getLogger("requests").setLevel(logging.WARNING) + + # set app root log level + logger = logging.getLogger() + root_log_level = logging.DEBUG if debug else logging.WARNING + logger.setLevel(root_log_level) + + def main(): parser = configure_parser(argparse.ArgumentParser()) args = parser.parse_args() debug = args.no_debug - logging.getLogger().setLevel(logging.DEBUG if debug else logging.WARNING) + _init_logging(debug) theme_dir = args.theme if theme_dir is not None: diff --git a/caimira/apps/calculator/report_generator.py b/caimira/apps/calculator/report_generator.py index 4a4bac12..f4ab702d 100644 --- a/caimira/apps/calculator/report_generator.py +++ b/caimira/apps/calculator/report_generator.py @@ -220,7 +220,7 @@ def manufacture_conditional_probability_data( infection_probability: models._VectorisedFloat ): data_registry: DataRegistry = exposure_model.data_registry - + min_vl = data_registry.conditional_prob_inf_given_viral_load['min_vl'] max_vl = data_registry.conditional_prob_inf_given_viral_load['max_vl'] step = (max_vl - min_vl)/100 @@ -502,11 +502,12 @@ def prepare_context( now = datetime.utcnow().astimezone() time = now.strftime("%Y-%m-%d %H:%M:%S UTC") + data_registry_version = f"v{model.data_registry.version}" if model.data_registry.version else None context = { 'model': model, 'form': form, 'creation_date': time, - 'data_registry_version': model.data_registry.version, + 'data_registry_version': data_registry_version, } scenario_sample_times = interesting_times(model) diff --git a/caimira/monte_carlo/data.py b/caimira/monte_carlo/data.py index 1a403084..eaf1496e 100644 --- a/caimira/monte_carlo/data.py +++ b/caimira/monte_carlo/data.py @@ -15,24 +15,40 @@ def evaluate_vl(value, data_registry: DataRegistry): - if value == ViralLoads.COVID_OVERALL: + # FIXME: temp fix until data service values is updated + # remove old Ref value + if "covid_overal_vl_data" in value: + value = ViralLoads.COVID_OVERALL.value + elif "symptomatic_vl_frequencies" in value: + value = ViralLoads.SYMPTOMATIC_FREQUENCIES.value + + if value == ViralLoads.COVID_OVERALL.value: return covid_overal_vl_data(data_registry) - elif value == ViralLoads.COVID_OVERALL: + elif value == ViralLoads.SYMPTOMATIC_FREQUENCIES.value: return symptomatic_vl_frequencies else: raise ValueError(f"Invalid ViralLoads value {value}") def evaluate_infectd(value, data_registry: DataRegistry): - if value == InfectiousDoses.DISTRIBUTION: + # FIXME: temp fix until data service values is updated + # remove old Ref value + if "infectious_dose_distribution" in value: + value = InfectiousDoses.DISTRIBUTION.value + + if value == InfectiousDoses.DISTRIBUTION.value: return infectious_dose_distribution(data_registry) else: raise ValueError(f"Invalid InfectiousDoses value {value}") def evaluate_vtrr(value, data_registry: DataRegistry): - """.""" - if value == ViableToRNARatios.DISTRIBUTION: + # FIXME: temp fix until data service values is updated + # remove old Ref value + if "viable_to_RNA_ratio_distribution" in value: + value = ViableToRNARatios.DISTRIBUTION.value + + if value == ViableToRNARatios.DISTRIBUTION.value: return viable_to_RNA_ratio_distribution(data_registry) else: raise ValueError(f"Invalid ViableToRNARatios value {value}") diff --git a/caimira/store/data_registry.py b/caimira/store/data_registry.py index e0c0cfb8..ab9d74ab 100644 --- a/caimira/store/data_registry.py +++ b/caimira/store/data_registry.py @@ -210,51 +210,51 @@ class DataRegistry: } virus_distributions = { "SARS_CoV_2": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 1, "infectiousness_days": 14, }, "SARS_CoV_2_ALPHA": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 0.78, "infectiousness_days": 14, }, "SARS_CoV_2_BETA": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 0.8, "infectiousness_days": 14, }, "SARS_CoV_2_GAMMA": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 0.72, "infectiousness_days": 14, }, "SARS_CoV_2_DELTA": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 0.51, "infectiousness_days": 14, }, "SARS_CoV_2_OMICRON": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 0.2, "infectiousness_days": 14, }, "SARS_CoV_2_Other": { - "viral_load_in_sputum": ViralLoads.COVID_OVERALL, - "infectious_dose": InfectiousDoses.DISTRIBUTION, - "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION, + "viral_load_in_sputum": ViralLoads.COVID_OVERALL.value, + "infectious_dose": InfectiousDoses.DISTRIBUTION.value, + "viable_to_RNA_ratio": ViableToRNARatios.DISTRIBUTION.value, "transmissibility_factor": 0.1, "infectiousness_days": 14, },