fix date formatting and add stock name/industry display
This commit is contained in:
parent
8876c0131d
commit
efa3a77787
@ -49,25 +49,32 @@ def render_pool_overview() -> None:
|
|||||||
st.write("候选投资池:")
|
st.write("候选投资池:")
|
||||||
try:
|
try:
|
||||||
latest_date = get_latest_trade_date()
|
latest_date = get_latest_trade_date()
|
||||||
|
# 将日期对象转换为字符串格式,与数据库保持一致
|
||||||
|
latest_date_str = latest_date.strftime("%Y%m%d") if latest_date else None
|
||||||
|
|
||||||
# 添加状态过滤功能
|
# 添加状态过滤功能
|
||||||
status_options = ["全部", "watch", "candidate", "exit", "buy_s", "buy_m", "buy_l"]
|
status_options = ["全部", "watch", "candidate", "exit", "buy_s", "buy_m", "buy_l"]
|
||||||
status_filter = st.selectbox("选择状态", options=status_options, index=0)
|
status_filter = st.selectbox("选择状态", options=status_options, index=0)
|
||||||
|
|
||||||
if status_filter != "全部":
|
if status_filter != "全部":
|
||||||
candidates = list_investment_pool(trade_date=latest_date, status=[status_filter])
|
candidates = list_investment_pool(trade_date=latest_date_str, status=[status_filter])
|
||||||
else:
|
else:
|
||||||
candidates = list_investment_pool(trade_date=latest_date)
|
candidates = list_investment_pool(trade_date=latest_date_str)
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
LOGGER.exception("加载候选池失败", extra=LOG_EXTRA)
|
LOGGER.exception("加载候选池失败", extra=LOG_EXTRA)
|
||||||
candidates = []
|
candidates = []
|
||||||
|
|
||||||
if candidates:
|
if candidates:
|
||||||
|
# 添加调试信息
|
||||||
|
st.caption(f"找到 {len(candidates)} 条候选记录")
|
||||||
|
|
||||||
candidate_df = pd.DataFrame(
|
candidate_df = pd.DataFrame(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"交易日": item.trade_date,
|
"交易日": item.trade_date,
|
||||||
"代码": item.ts_code,
|
"代码": item.ts_code,
|
||||||
|
"名称": item.name or "-",
|
||||||
|
"行业": item.industry or "-",
|
||||||
"评分": item.score,
|
"评分": item.score,
|
||||||
"状态": item.status,
|
"状态": item.status,
|
||||||
"标签": "、".join(item.tags) if item.tags else "-",
|
"标签": "、".join(item.tags) if item.tags else "-",
|
||||||
|
|||||||
@ -153,12 +153,15 @@ def render_today_plan() -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
query = get_query_params()
|
query = get_query_params()
|
||||||
default_trade_date = query.get("date", [trade_dates[0]])[0]
|
# 确保默认日期格式正确
|
||||||
|
default_trade_date = str(query.get("date", [trade_dates[0]])[0])
|
||||||
try:
|
try:
|
||||||
default_idx = trade_dates.index(default_trade_date)
|
default_idx = trade_dates.index(default_trade_date)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
default_idx = 0
|
default_idx = 0
|
||||||
trade_date = st.selectbox("交易日", trade_dates, index=default_idx)
|
# 确保日期格式统一为 YYYYMMDD
|
||||||
|
formatted_trade_dates = [str(td) for td in trade_dates]
|
||||||
|
trade_date = st.selectbox("交易日", formatted_trade_dates, index=default_idx)
|
||||||
|
|
||||||
with db_session(read_only=True) as conn:
|
with db_session(read_only=True) as conn:
|
||||||
code_rows = conn.execute(
|
code_rows = conn.execute(
|
||||||
@ -184,6 +187,9 @@ def render_today_plan() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _render_today_plan_assistant_view(trade_date: str | int | date) -> None:
|
def _render_today_plan_assistant_view(trade_date: str | int | date) -> None:
|
||||||
|
# 确保日期格式为字符串
|
||||||
|
if isinstance(trade_date, date):
|
||||||
|
trade_date = trade_date.strftime("%Y%m%d")
|
||||||
st.info("已开启投资助理模式:以下内容为组合级(去标的)建议,不包含任何具体标的代码。")
|
st.info("已开启投资助理模式:以下内容为组合级(去标的)建议,不包含任何具体标的代码。")
|
||||||
try:
|
try:
|
||||||
candidates = list_investment_pool(trade_date=trade_date)
|
candidates = list_investment_pool(trade_date=trade_date)
|
||||||
|
|||||||
@ -32,6 +32,8 @@ class InvestmentCandidate:
|
|||||||
rationale: Optional[str]
|
rationale: Optional[str]
|
||||||
tags: List[str]
|
tags: List[str]
|
||||||
metadata: Dict[str, Any]
|
metadata: Dict[str, Any]
|
||||||
|
name: Optional[str] = None
|
||||||
|
industry: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
def list_investment_pool(
|
def list_investment_pool(
|
||||||
@ -84,6 +86,8 @@ def list_investment_pool(
|
|||||||
rationale=row["rationale"],
|
rationale=row["rationale"],
|
||||||
tags=list(_loads_or_default(row["tags"], [])),
|
tags=list(_loads_or_default(row["tags"], [])),
|
||||||
metadata=dict(_loads_or_default(row["metadata"], {})),
|
metadata=dict(_loads_or_default(row["metadata"], {})),
|
||||||
|
name=row["name"],
|
||||||
|
industry=row["industry"],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return candidates
|
return candidates
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user