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:
co-authored by
maghdam
parent
29fcbf0f9d
commit
bf6c4846c4
+2
-6
@@ -60,12 +60,8 @@ def display_recent_signals(df: pd.DataFrame):
|
|||||||
# Optional: Show a quick mini-forecast chart per symbol
|
# Optional: Show a quick mini-forecast chart per symbol
|
||||||
st.write("---")
|
st.write("---")
|
||||||
st.subheader("Mini Signal Forecasts (per symbol)")
|
st.subheader("Mini Signal Forecasts (per symbol)")
|
||||||
for symbol in sorted(df[COL_SYMBOL].unique()):
|
for symbol, group in df.sort_values(COL_TIMESTAMP).groupby(COL_SYMBOL):
|
||||||
mini_df = (
|
mini_df = group.tail(N_FORWARD)
|
||||||
df[df[COL_SYMBOL] == symbol]
|
|
||||||
.sort_values(COL_TIMESTAMP)
|
|
||||||
.tail(N_FORWARD)
|
|
||||||
)
|
|
||||||
# Only show if there is more than one unique value
|
# Only show if there is more than one unique value
|
||||||
if mini_df[COL_PREDICTION].nunique() > 1:
|
if mini_df[COL_PREDICTION].nunique() > 1:
|
||||||
st.write(f"**{symbol}**")
|
st.write(f"**{symbol}**")
|
||||||
|
|||||||
Reference in New Issue
Block a user