|
| 1 | +import pandas as pd |
1 | 2 | from openquake.commonlib.datastore import read |
2 | 3 |
|
3 | 4 | from reia.config.settings import get_settings |
@@ -25,16 +26,15 @@ def __init__(self, |
25 | 26 | self.api_client = api_client |
26 | 27 | self.dstore_path = dstore_path |
27 | 28 |
|
28 | | - def save_calculation_results( |
29 | | - self, |
30 | | - calculationbranch: CalculationBranch) -> None: |
31 | | - """Save OpenQuake calculation results to database. |
| 29 | + def extract_calculation_results(self, |
| 30 | + calculationbranch: CalculationBranch |
| 31 | + ) -> tuple[pd.DataFrame, pd.DataFrame]: |
| 32 | + """Extract OpenQuake calculation results from datastore. |
32 | 33 |
|
33 | 34 | Args: |
34 | 35 | calculationbranch: The calculation branch object |
35 | | -
|
36 | | - Raises: |
37 | | - Exception: If result retrieval or saving fails |
| 36 | + Returns: |
| 37 | + Tuple of DataFrames: risk values and aggregation mappings |
38 | 38 | """ |
39 | 39 | # Get calculation data using OQCalculationAPI |
40 | 40 | self.logger.info("Retrieving results for calculation " |
@@ -72,6 +72,22 @@ def save_calculation_results( |
72 | 72 | raw_risk_values, calculationbranch, risk_type, |
73 | 73 | aggregation_tag_by_name) |
74 | 74 |
|
| 75 | + return (risk_values, df_agg_val) |
| 76 | + |
| 77 | + def save_calculation_results( |
| 78 | + self, |
| 79 | + calculationbranch: CalculationBranch) -> None: |
| 80 | + """Save OpenQuake calculation results to database. |
| 81 | +
|
| 82 | + Args: |
| 83 | + calculationbranch: The calculation branch object |
| 84 | +
|
| 85 | + Raises: |
| 86 | + Exception: If result retrieval or saving fails |
| 87 | + """ |
| 88 | + risk_values, df_agg_val = self.extract_calculation_results( |
| 89 | + calculationbranch) |
| 90 | + |
75 | 91 | # Save to database |
76 | 92 | self.logger.debug( |
77 | 93 | f"Saving {len(risk_values)} risk values and " |
|
0 commit comments