diff --git a/modules/events/f1_qualifying_event.py b/modules/events/f1_qualifying_event.py index 9b54e21..c3238fc 100644 --- a/modules/events/f1_qualifying_event.py +++ b/modules/events/f1_qualifying_event.py @@ -82,6 +82,7 @@ def event_sequence(self): 2. Run each qualifying session in sequence (Q1, Q2, Q3...) 3. Track advancing drivers between sessions 4. Terminate after final session + 5. Print final results table """ # Create list of tuples: [(session_length, cars_advancing), ...] session_info = list(zip(self.session_minutes, self.session_advancing_cars)) @@ -97,6 +98,37 @@ def event_sequence(self): length, num_drivers_remain, session_number, advancing_drivers ) + # Print final results to logs + self.print_final_results() + + def print_final_results(self): + """ + Prints the final qualifying results table to the logs. + """ + self.logger.info("=" * 80) + self.logger.info("F1 QUALIFYING - FINAL RESULTS") + self.logger.info("=" * 80) + + with self.leaderboard_lock: + if self.leaderboard_df.empty: + self.logger.info("No results available.") + return + + # Create a copy to work with + results_df = self.leaderboard_df.copy() + + # Add position column + results_df.insert(0, "Pos", range(1, len(results_df) + 1)) + + # Format the DataFrame as a string table + results_table = results_df.to_string(index=True) + + # Log each line of the table + for line in results_table.split("\n"): + self.logger.info(line) + + self.logger.info("=" * 80) + def wait_before_next_session(self, seconds, session_number): self.checkered_flag_out = False wait_start_time = self.sdk["SessionTime"] diff --git a/modules/events/overlay_consumer_event.py b/modules/events/overlay_consumer_event.py index 2717a76..c159dc6 100644 --- a/modules/events/overlay_consumer_event.py +++ b/modules/events/overlay_consumer_event.py @@ -253,13 +253,22 @@ def _build_f1_state(self) -> dict | None: drivers = [] for pos, (car_num, row) in enumerate(df.iterrows()): - # Best lap time across all sessions (smallest positive value). + # During an active session, show the current session time. + # Otherwise, show the best time across all sessions (smallest positive value). best_time = None - for col in q_cols: - val = row.get(col) + if is_active_session and current_q_num is not None: + # Show current session time during active sessions + current_q_col = f"Q{current_q_num}" + val = row.get(current_q_col) if isinstance(val, (int, float)) and not isnan(val) and val > 0: - if best_time is None or val < best_time: - best_time = val + best_time = val + else: + # Show overall best time between sessions + for col in q_cols: + val = row.get(col) + if isinstance(val, (int, float)) and not isnan(val) and val > 0: + if best_time is None or val < best_time: + best_time = val # Per-session individual lap times for the standings overlay. session_times: dict[str, str] = {}