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>
This commit is contained in:
+2
-6
@@ -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}**")
|
||||
|
||||
Reference in New Issue
Block a user