From 3a4e0d90fc55b821793b51f619f555177d418380 Mon Sep 17 00:00:00 2001 From: zlt Date: Thu, 3 Sep 2026 11:46:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=A4=E5=B8=82=E6=88=90?= =?UTF-8?q?=E4=BA=A4=E9=A2=9D=E5=8D=95=E4=BD=8D=EF=BC=9A=E6=8C=87=E6=95=B0?= =?UTF-8?q?=E6=97=A5=E7=BA=BF=E7=9A=84=E6=88=90=E4=BA=A4=E9=A2=9D=E6=98=AF?= =?UTF-8?q?=E5=8D=83=E5=85=83=E4=B8=8D=E6=98=AF=E5=85=83=EF=BC=8C=E6=8D=A2?= =?UTF-8?q?=E7=AE=97=E6=88=90=E4=BA=BF=E5=85=83=E8=A6=81=E9=99=A4=E4=BB=A5?= =?UTF-8?q?=E5=8D=81=E4=B8=87=EF=BC=9B=E6=B8=B2=E6=9F=93=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=8D=A2=E7=AE=97=E5=A5=BD=E7=9A=84=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E6=96=AD=E8=A8=80=E5=86=99=E8=BF=9B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测核对:09-02 两市合计 1,321,831,143,真实成交额约 1.32 万亿元。改前显示 13 亿,差一千倍。融资余额那张表的单位是元,沿用原换算。 Co-Authored-By: Claude Opus 5 --- plan.py | 9 +++++++-- sources.py | 7 ++++++- test_market_context.py | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plan.py b/plan.py index 224e3e1..abb68c7 100644 --- a/plan.py +++ b/plan.py @@ -446,8 +446,13 @@ def _fmt_logic(lines, width: int = 60) -> str: return f"{first}(共 {len(lines)} 条)" if len(lines) > 1 else first +def _fmt_yi(v) -> str: + """已经是"亿元"的数直接显示。两市成交额由取数层换算好(原表单位是千元),不在这里换算。""" + return "—" if v is None else f"{v:,.0f} 亿" + + def _fmt_amount(v) -> str: - """成交额按元换算成亿显示;原表单位若不是元,读数需要按 market.turnover.unit 说明校正。""" + """以元为单位的金额换算成亿显示。融资余额用它(那张表的单位是元)。""" if v is None: return "—" return f"{v / 1e8:,.0f} 亿" if abs(v) >= 1e8 else f"{v:,.0f}" @@ -459,7 +464,7 @@ def _fmt_market(m: dict) -> str: parts = [] if t: ratio = t.get("ratio_vs_prev5") - parts.append(f"两市成交额 {_fmt_amount(t.get('amount'))}" + parts.append(f"两市成交额 {_fmt_yi(t.get('amount_yi'))}" + (f"(前五日均值的 {ratio:.2f} 倍)" if ratio else "") + (f",数据日 {t['data_date']}" if t.get("data_date") and t.get("data_date") != m.get("date") else "")) else: diff --git a/sources.py b/sources.py index a81da4b..edb0d6f 100644 --- a/sources.py +++ b/sources.py @@ -382,7 +382,12 @@ def _turnover(rows: list[dict], ds: str) -> dict | None: avg5 = (sum(prev) / len(prev)) if prev else None return {"data_date": day0, "amount": amt0, "prev5_avg": avg5, "ratio_vs_prev5": (amt0 / avg5) if avg5 else None, "prev5_days": len(prev), - "unit": "zs_day_data 原表单位,未换算", + # 2026-09-03 实测核对:09-02 两市 amount 合计 1,321,831,143,而当日真实成交额约 + # 1.32 万亿元,所以这一列的单位是千元,不是元。换算成亿元要除以十万(乘一千再除一亿)。 + # 渲染与下游一律用 amount_yi,原始值保留在 amount 里备查。 + "unit": "千元", + "amount_yi": amt0 / 1e5, + "prev5_avg_yi": (avg5 / 1e5) if avg5 else None, "source": "zs_day_data 上证 000001.SH 与深成 399001.SZ 当日 amount 之和"} diff --git a/test_market_context.py b/test_market_context.py index 3a59dde..82bf9b0 100644 --- a/test_market_context.py +++ b/test_market_context.py @@ -117,6 +117,11 @@ def test_market_context(): t("前五日均值跳过两市不齐全的日子", tv["prev5_days"] == 5 and abs(tv["prev5_avg"] - 14520.0) < 1e-6) t("比值 = 当日 / 前五日均值", abs(tv["ratio_vs_prev5"] - 15200.0 / 14520.0) < 1e-9) t("晚于数据日的行不参与", tv["amount"] < 99999) + # 指数日线的 amount 单位是千元(2026-09-03 实测:09-02 两市合计 1,321,831,143,真实成交额约 + # 1.32 万亿元)。换算成亿元要除以十万。渲染只用 amount_yi,写错单位会让读数差一千倍。 + t("成交额单位标千元、按千元换算成亿元", + tv["unit"] == "千元" and abs(tv["amount_yi"] - 15200.0 / 1e5) < 1e-12 + and abs(tv["prev5_avg_yi"] - 14520.0 / 1e5) < 1e-12) b = m["breadth"] # 六个有效值排序:-4.0、-1.5、0.0、3.0、9.95、10.02,中位数 = (0.0 + 3.0) / 2 = 1.5 t("广度:上涨 3 / 下跌 2 / 平盘 1,涨停近似 2,中位数 1.5(空值剔除)",