增加更多的历史记录,修正部份API数据获取错误,增加备用API (#5)
* 增加更多的历史记录,修正部份数据获取错误 * 增加更多的历史记录,修正部份API数据获取错误,增加备用API --------- Co-authored-by: bathfire <>
This commit is contained in:
+29
-14
@@ -30,7 +30,7 @@ def display_main_force_selector():
|
||||
st.markdown("## 🎯 主力选股 - 智能筛选优质标的")
|
||||
with col_history:
|
||||
st.write("") # 占位
|
||||
if st.button("📚 批量分析历史", use_container_width=True):
|
||||
if st.button("📚 批量分析历史", width='content'):
|
||||
st.session_state.main_force_view_history = True
|
||||
st.rerun()
|
||||
|
||||
@@ -102,8 +102,8 @@ def display_main_force_selector():
|
||||
with col1:
|
||||
max_change = st.number_input(
|
||||
"最大涨跌幅(%)",
|
||||
min_value=10.0,
|
||||
max_value=100.0,
|
||||
min_value=5.0,
|
||||
max_value=200.0,
|
||||
value=30.0,
|
||||
step=5.0,
|
||||
help="过滤掉涨幅过高的股票,避免追高"
|
||||
@@ -121,7 +121,7 @@ def display_main_force_selector():
|
||||
with col3:
|
||||
max_cap = st.number_input(
|
||||
"最大市值(亿)",
|
||||
min_value=100.0,
|
||||
min_value=50.0,
|
||||
max_value=50000.0,
|
||||
value=5000.0,
|
||||
step=100.0
|
||||
@@ -137,7 +137,7 @@ def display_main_force_selector():
|
||||
st.markdown("---")
|
||||
|
||||
# 开始分析按钮
|
||||
if st.button("🚀 开始主力选股", type="primary", use_container_width=True):
|
||||
if st.button("🚀 开始主力选股", type="primary", width='content'):
|
||||
|
||||
with st.spinner("正在获取数据并分析,这可能需要几分钟..."):
|
||||
|
||||
@@ -148,7 +148,10 @@ def display_main_force_selector():
|
||||
result = analyzer.run_full_analysis(
|
||||
start_date=start_date,
|
||||
days_ago=days_ago,
|
||||
final_n=final_n
|
||||
final_n=final_n,
|
||||
max_range_change=max_change,
|
||||
min_market_cap=min_cap,
|
||||
max_market_cap=max_cap
|
||||
)
|
||||
|
||||
# 保存结果到session_state
|
||||
@@ -277,7 +280,7 @@ def display_analysis_results(result: dict, analyzer):
|
||||
|
||||
# 显示DataFrame
|
||||
display_df = analyzer.raw_stocks[final_cols].copy()
|
||||
st.dataframe(display_df, use_container_width=True, height=400)
|
||||
st.dataframe(display_df, width='content', height=400)
|
||||
|
||||
# 显示统计
|
||||
st.caption(f"共 {len(display_df)} 只候选股票,显示 {len(final_cols)} 个字段")
|
||||
@@ -309,7 +312,7 @@ def display_analysis_results(result: dict, analyzer):
|
||||
|
||||
with col_batch3:
|
||||
st.write("") # 占位
|
||||
if st.button("🚀 开始批量分析", type="primary", use_container_width=True):
|
||||
if st.button("🚀 开始批量分析", type="primary", width='content'):
|
||||
# 准备数据:按主力资金净流入排序
|
||||
df_sorted = analyzer.raw_stocks.copy()
|
||||
|
||||
@@ -497,7 +500,7 @@ def run_main_force_batch_analysis():
|
||||
# 返回按钮
|
||||
col_back, col_clear = st.columns(2)
|
||||
with col_back:
|
||||
if st.button("🔙 返回主力选股", use_container_width=True):
|
||||
if st.button("🔙 返回主力选股", width='content'):
|
||||
# 清除所有批量分析相关状态
|
||||
if 'main_force_batch_trigger' in st.session_state:
|
||||
del st.session_state.main_force_batch_trigger
|
||||
@@ -508,7 +511,7 @@ def run_main_force_batch_analysis():
|
||||
st.rerun()
|
||||
|
||||
with col_clear:
|
||||
if st.button("🔄 重新分析", use_container_width=True):
|
||||
if st.button("🔄 重新分析", width='content'):
|
||||
# 清除结果,保留触发标志和代码
|
||||
if 'main_force_batch_results' in st.session_state:
|
||||
del st.session_state.main_force_batch_results
|
||||
@@ -569,11 +572,11 @@ def run_main_force_batch_analysis():
|
||||
|
||||
start_analysis = False
|
||||
with col_confirm:
|
||||
if st.button("🚀 确认开始分析", type="primary", use_container_width=True):
|
||||
if st.button("🚀 确认开始分析", type="primary", width='content'):
|
||||
start_analysis = True
|
||||
|
||||
with col_cancel:
|
||||
if st.button("❌ 取消", type="secondary", use_container_width=True):
|
||||
if st.button("❌ 取消", type="secondary", width='content'):
|
||||
# 清除所有批量分析相关状态
|
||||
if 'main_force_batch_trigger' in st.session_state:
|
||||
del st.session_state.main_force_batch_trigger
|
||||
@@ -858,7 +861,19 @@ def display_main_force_batch_results(batch_results):
|
||||
})
|
||||
|
||||
df_display = pd.DataFrame(display_data)
|
||||
st.dataframe(df_display, use_container_width=True, height=400)
|
||||
|
||||
# 类型统一,避免Arrow序列化错误
|
||||
numeric_cols = ['信心度', '止盈位', '止损位', '目标价']
|
||||
for col in numeric_cols:
|
||||
if col in df_display.columns:
|
||||
df_display[col] = pd.to_numeric(df_display[col], errors='coerce')
|
||||
|
||||
text_cols = ['股票代码', '股票名称', '评级', '进场区间']
|
||||
for col in text_cols:
|
||||
if col in df_display.columns:
|
||||
df_display[col] = df_display[col].astype(str)
|
||||
|
||||
st.dataframe(df_display, width='content', height=400)
|
||||
|
||||
# 详细分析结果(可展开)
|
||||
st.markdown("---")
|
||||
@@ -977,5 +992,5 @@ def display_main_force_batch_results(batch_results):
|
||||
})
|
||||
|
||||
df_failed = pd.DataFrame(failed_data)
|
||||
st.dataframe(df_failed, use_container_width=True)
|
||||
st.dataframe(df_failed, width='content')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user