1+ import time
2+
13import pandas as pd
24
35from covid_xprize .standard_predictor .xprize_predictor import XPrizePredictor
@@ -15,21 +17,22 @@ def weight_prescriptions_by_cost(pres_df, cost_df):
1517
1618
1719def generate_cases_and_stringency_for_prescriptions (start_date , end_date , prescription_file , costs_file ):
20+ start_time = time .time ()
1821 # Load the prescriptions, handling Date and regions
1922 pres_df = XPrizePredictor .load_original_data (prescription_file )
2023
2124 # Generate predictions for all prescriptions
2225 predictor = XPrizePredictor ()
23- pred_dfs = []
26+ pred_dfs = {}
2427 for idx in pres_df ['PrescriptionIndex' ].unique ():
2528 idx_df = pres_df [pres_df ['PrescriptionIndex' ] == idx ]
2629 idx_df = idx_df .drop (columns = 'PrescriptionIndex' ) # Predictor doesn't need this
2730 # Generate the predictions
2831 pred_df = predictor .predict_from_df (start_date , end_date , idx_df )
2932 print (f"Generated predictions for PrescriptionIndex { idx } " )
3033 pred_df ['PrescriptionIndex' ] = idx
31- pred_dfs . append ( pred_df )
32- pred_df = pd .concat (pred_dfs )
34+ pred_dfs [ idx ] = pred_df
35+ pred_df = pd .concat (list ( pred_dfs . values ()) )
3336
3437 # Aggregate cases by prescription index and geo
3538 agg_pred_df = pred_df .groupby (['CountryName' ,
@@ -65,8 +68,12 @@ def generate_cases_and_stringency_for_prescriptions(start_date, end_date, prescr
6568 'PrescriptionIndex' ,
6669 'PredictedDailyNewCases' ,
6770 'Stringency' ]]
71+ end_time = time .time ()
72+ elapsed_time = end_time - start_time
73+ elapsed_time_tring = time .strftime ("%H:%M:%S" , time .gmtime (elapsed_time ))
74+ print (f"Evaluated { len (pred_dfs )} PrescriptionIndex in { elapsed_time_tring } seconds" )
6875
69- return df
76+ return df , pred_dfs
7077
7178
7279# Compute domination relationship for each pair of prescriptors for each geo
0 commit comments