Skip to content

Commit 5587cc6

Browse files
committed
refactor: results service, separate extraction and storage
1 parent 6c0843c commit 5587cc6

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

reia/services/results.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pandas as pd
12
from openquake.commonlib.datastore import read
23

34
from reia.config.settings import get_settings
@@ -25,16 +26,15 @@ def __init__(self,
2526
self.api_client = api_client
2627
self.dstore_path = dstore_path
2728

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.
3233
3334
Args:
3435
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
3838
"""
3939
# Get calculation data using OQCalculationAPI
4040
self.logger.info("Retrieving results for calculation "
@@ -72,6 +72,22 @@ def save_calculation_results(
7272
raw_risk_values, calculationbranch, risk_type,
7373
aggregation_tag_by_name)
7474

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+
7591
# Save to database
7692
self.logger.debug(
7793
f"Saving {len(risk_values)} risk values and "

0 commit comments

Comments
 (0)