From 8876c0131de4317aa212c4f8cc4246aa127819fe Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 11 Oct 2025 16:14:47 +0800 Subject: [PATCH] refactor pool view with status filter and improve factor clearing --- app/ui/views/factor_calculation.py | 4 +++- app/ui/views/pool.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/ui/views/factor_calculation.py b/app/ui/views/factor_calculation.py index 3807605..3c89239 100644 --- a/app/ui/views/factor_calculation.py +++ b/app/ui/views/factor_calculation.py @@ -247,7 +247,9 @@ def render_factor_calculation() -> None: LOGGER.exception("清空因子表失败", extra={**LOG_EXTRA, "error": str(exc)}) st.error(f"清空因子表失败:{exc}") finally: - st.session_state['factor_clear_confirm'] = False + # 使用st.rerun()代替直接修改session_state + # 清空因子表后重置页面状态 + st.rerun() # 5. 开始计算按钮 if st.button("开始计算因子", disabled=not selected_factors): diff --git a/app/ui/views/pool.py b/app/ui/views/pool.py index 675f7ba..12a3134 100644 --- a/app/ui/views/pool.py +++ b/app/ui/views/pool.py @@ -46,9 +46,18 @@ def render_pool_overview() -> None: else: st.info("暂无组合快照,请在执行回测或实盘同步后写入 portfolio_snapshots。") + st.write("候选投资池:") try: latest_date = get_latest_trade_date() - candidates = list_investment_pool(trade_date=latest_date) + + # 添加状态过滤功能 + status_options = ["全部", "watch", "candidate", "exit", "buy_s", "buy_m", "buy_l"] + status_filter = st.selectbox("选择状态", options=status_options, index=0) + + if status_filter != "全部": + candidates = list_investment_pool(trade_date=latest_date, status=[status_filter]) + else: + candidates = list_investment_pool(trade_date=latest_date) except Exception: # noqa: BLE001 LOGGER.exception("加载候选池失败", extra=LOG_EXTRA) candidates = [] @@ -67,7 +76,6 @@ def render_pool_overview() -> None: for item in candidates ] ) - st.write("候选投资池:") st.dataframe(candidate_df, width='stretch', hide_index=True) else: st.caption("候选投资池暂无数据。")