From cbb526afdc5b85988191b9ad3e81fe4f0c4b7c8a Mon Sep 17 00:00:00 2001 From: zlt Date: Wed, 9 Sep 2026 10:31:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E6=9E=90=E7=9B=AE=E6=A0=87=E5=90=8D?= =?UTF-8?q?=E5=8D=95=EF=BC=9A=E4=B8=BB=E6=A6=9C=E5=89=8D=E4=B8=80=E7=99=BE?= =?UTF-8?q?=E5=8A=A0=E8=A7=82=E5=AF=9F=E6=A1=A3=E5=89=8D=E4=BA=8C=E5=8D=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5.1 --- review_targets.py | 10 +++++----- test_review_targets.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/review_targets.py b/review_targets.py index 8a12e32..9664ea9 100644 --- a/review_targets.py +++ b/review_targets.py @@ -12,6 +12,8 @@ import config import db TABLE = os.environ.get("REVIEW_TARGETS_TABLE", "t_akg_review_targets") +TOP_MAIN = int(os.environ.get("REVIEW_TARGETS_MAIN", "100")) # 主榜前一百只 +TOP_OBS = int(os.environ.get("REVIEW_TARGETS_OBS", "20")) # 观察档前二十只 COLUMNS = ("plan_date", "ts_code", "source", "rank", "name") _CREATE = """ CREATE TABLE IF NOT EXISTS {t} ( @@ -62,11 +64,9 @@ def save(ds: str, rows: list, conn_factory=None) -> None: def persist(ds: str, snap: dict, write=None) -> dict: - """目标是计划里展示给人的那一份候选单(主榜前几十只加观察档),不是全部主榜;快照里叫 main_shown / observe_shown, - 老快照没有这两个键就退回 main / observe。""" - main = snap.get("main_shown") if snap.get("main_shown") is not None else (snap.get("main") or []) - obs = snap.get("observe_shown") if snap.get("observe_shown") is not None else (snap.get("observe") or []) - rows = build_rows(ds, main, obs) + """目标是主榜前 TOP_MAIN 只加观察档前 TOP_OBS 只(快照里的 main / observe 已按名次排),约一百二十家, + 与方案说的"一两百家"一致;07:10 计划默认只展示 20 加 10,那份太窄。""" + rows = build_rows(ds, (snap.get("main") or [])[:TOP_MAIN], (snap.get("observe") or [])[:TOP_OBS]) (write or save)(ds, rows) n_main = sum(1 for r in rows if r["source"] == "main") print(f" 评析目标名单 {ds}:主榜 {n_main},观察 {len(rows) - n_main},写入 {TABLE}") diff --git a/test_review_targets.py b/test_review_targets.py index f11d62f..72d3d2c 100644 --- a/test_review_targets.py +++ b/test_review_targets.py @@ -17,9 +17,9 @@ def main(): out = rt.persist("2026-09-08", snap, write=lambda ds, rs: got.setdefault(ds, rs)) t("写入可注入且读数正确", out["rows"] == 3 and out["main"] == 2 and len(got["2026-09-08"]) == 3) t("认不出的代码丢弃", all(len(r["ts_code"]) == 9 for r in rows)) - shown = {"main": [{"code": "SH600519"}] * 3, "observe": [], "main_shown": [{"code": "SZ300750"}], "observe_shown": [{"code": "SZ000001"}]} - out2 = rt.persist("2026-09-09", shown, write=lambda ds, rs: got.setdefault(ds, rs)) - t("优先取展示给人的那份候选单", out2["rows"] == 2 and got["2026-09-09"][0]["ts_code"] == "300750.SZ") + big = {"main": [{"code": f"SH60{i:04d}"} for i in range(150)], "observe": [{"code": f"SZ30{i:04d}"} for i in range(40)]} + out2 = rt.persist("2026-09-09", big, write=lambda ds, rs: got.setdefault(ds, rs)) + t("主榜取前一百、观察档取前二十", out2["rows"] == rt.TOP_MAIN + rt.TOP_OBS and out2["main"] == rt.TOP_MAIN) print("ALL OK — 评析目标名单")