From bf6c4846c437f6b9b9fdce88cfad6dee7f4fd293 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 11 Mar 2026 18:30:55 +0000 Subject: [PATCH] refactor(dashboard): optimize signal processing with groupby Instead of repeatedly filtering the DataFrame for each symbol in a loop, sort the DataFrame by timestamp once and use groupby(COL_SYMBOL) to iterate over the groups. This reduces the time complexity and significantly speeds up the signal processing loop. Co-authored-by: maghdam <63883156+maghdam@users.noreply.github.com> --- dashboard.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dashboard.py b/dashboard.py index 6f6b066..ba4550d 100644 --- a/dashboard.py +++ b/dashboard.py @@ -60,12 +60,8 @@ def display_recent_signals(df: pd.DataFrame): # Optional: Show a quick mini-forecast chart per symbol st.write("---") st.subheader("Mini Signal Forecasts (per symbol)") - for symbol in sorted(df[COL_SYMBOL].unique()): - mini_df = ( - df[df[COL_SYMBOL] == symbol] - .sort_values(COL_TIMESTAMP) - .tail(N_FORWARD) - ) + for symbol, group in df.sort_values(COL_TIMESTAMP).groupby(COL_SYMBOL): + mini_df = group.tail(N_FORWARD) # Only show if there is more than one unique value if mini_df[COL_PREDICTION].nunique() > 1: st.write(f"**{symbol}**")