3030END = int (os .getenv ("END" , "10" ))
3131OUTPUT = os .environ .get ("OUTPUT" , None )
3232
33+ process_candidates_str = os .environ .get ("PROCESS_CANDIDATES" , "True" )
34+ PROCESS_CANDIDATES = process_candidates_str .lower () in ['true' , 't' , '1' , 'yes' ]
35+
3336candidate_df : pd .DataFrame = pd .DataFrame ()
3437response_df : pd .DataFrame = pd .DataFrame ()
3538lock = threading .Lock ()
@@ -98,7 +101,8 @@ def post_json_message(filename):
98101
99102 with lock :
100103 add_response (response , response_data )
101- add_candidates (response_data , data ["performance_month" ])
104+ if PROCESS_CANDIDATES :
105+ add_candidates (response_data , data ["performance_month" ])
102106
103107 except Exception as e :
104108 print (f"Error processing { filename } : { e } " )
@@ -117,13 +121,17 @@ def add_candidates(response_data: dict, performance_month: str):
117121
118122def add_response (response : requests .Response , response_data ):
119123 global response_df
120- timing_total = response_data .get ("timing" , {}).get ("total" , None )
124+ timing_total = response_data .get ("timing" , {}).get ("total" , float ("NaN" ))
125+ selected_candidate = response_data .get ("selected_candidate" , None )
126+
121127 response_dict : dict = {
122128 "staff_number" : [response_data .get ("staff_number" , None )],
129+ "causal_pathway" : selected_candidate ["acceptable_by" ] if selected_candidate else [None ],
123130 "status_code" : [response .status_code ],
124131 "elapsed" : [response .elapsed .total_seconds ()],
125132 "timing.total" : [timing_total ],
126133 "ok" : [response .ok ],
134+
127135 }
128136 response_df = pd .concat (
129137 [response_df , pd .DataFrame (response_dict )], ignore_index = True
@@ -144,14 +152,21 @@ def analyse_responses():
144152 .agg (pfp_time = ("mean" ))
145153 .reset_index ()
146154 )
155+
156+ r2 = (
157+ response_df .groupby ("causal_pathway" )["staff_number" ]
158+ .agg (count = ("count" ))
159+ .reset_index ()
160+ )
147161
148162 r = pd .merge (r , r1 , on = "status_code" , how = "left" )
149163
150164 r ["pfp_time" ] = round (r ["pfp_time" ] * 1000 , 1 )
151165 r ["response_time" ] = round (r ["response_time" ] * 1000 , 1 )
152166
153167 print (f"\n { r } \n " )
154-
168+
169+ print (f"\n { r2 } \n " )
155170
156171def analyse_candidates ():
157172 global candidate_df
@@ -163,6 +178,12 @@ def analyse_candidates():
163178 candidate_df .rename (columns = {"acceptable_by" : "causal_pathway" }, inplace = True )
164179 candidate_df ["score" ] = candidate_df ["score" ].astype (float )
165180 candidate_df .rename (columns = {"name" : "message" }, inplace = True )
181+
182+ # pd.set_option("display.max_columns", None)
183+ # pd.set_option("display.expand_frame_repr", False)
184+ # pd.set_option("display.width", 1000)
185+ # pd.set_option("display.max_colwidth", None)
186+
166187
167188 # causal pathways
168189 causal_pathway_report = build_table ("causal_pathway" )
@@ -251,7 +272,8 @@ def main():
251272 executor .map (post_json_message , input_files )
252273
253274 analyse_responses ()
254- analyse_candidates ()
275+ if PROCESS_CANDIDATES :
276+ analyse_candidates ()
255277
256278
257279if __name__ == "__main__" :
0 commit comments