评析目标名单:主榜前一百加观察档前二十

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
zlt 2026-09-09 10:31:49 +08:00
parent 89eb5135e7
commit cbb526afdc
2 changed files with 8 additions and 8 deletions

View File

@ -12,6 +12,8 @@ import config
import db import db
TABLE = os.environ.get("REVIEW_TARGETS_TABLE", "t_akg_review_targets") 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") COLUMNS = ("plan_date", "ts_code", "source", "rank", "name")
_CREATE = """ _CREATE = """
CREATE TABLE IF NOT EXISTS {t} ( 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: def persist(ds: str, snap: dict, write=None) -> dict:
"""目标是计划里展示给人的那一份候选单(主榜前几十只加观察档),不是全部主榜;快照里叫 main_shown / observe_shown """目标是主榜前 TOP_MAIN 只加观察档前 TOP_OBS 只(快照里的 main / observe 已按名次排),约一百二十家,
老快照没有这两个键就退回 main / observe""" 与方案说的"一两百家"一致07:10 计划默认只展示 20 10那份太窄"""
main = snap.get("main_shown") if snap.get("main_shown") is not None else (snap.get("main") or []) rows = build_rows(ds, (snap.get("main") or [])[:TOP_MAIN], (snap.get("observe") or [])[:TOP_OBS])
obs = snap.get("observe_shown") if snap.get("observe_shown") is not None else (snap.get("observe") or [])
rows = build_rows(ds, main, obs)
(write or save)(ds, rows) (write or save)(ds, rows)
n_main = sum(1 for r in rows if r["source"] == "main") n_main = sum(1 for r in rows if r["source"] == "main")
print(f" 评析目标名单 {ds}:主榜 {n_main},观察 {len(rows) - n_main},写入 {TABLE}") print(f" 评析目标名单 {ds}:主榜 {n_main},观察 {len(rows) - n_main},写入 {TABLE}")

View File

@ -17,9 +17,9 @@ def main():
out = rt.persist("2026-09-08", snap, write=lambda ds, rs: got.setdefault(ds, rs)) 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("写入可注入且读数正确", 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)) 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"}]} 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", shown, write=lambda ds, rs: got.setdefault(ds, rs)) out2 = rt.persist("2026-09-09", big, write=lambda ds, rs: got.setdefault(ds, rs))
t("优先取展示给人的那份候选单", out2["rows"] == 2 and got["2026-09-09"][0]["ts_code"] == "300750.SZ") t("主榜取前一百、观察档取前二十", out2["rows"] == rt.TOP_MAIN + rt.TOP_OBS and out2["main"] == rt.TOP_MAIN)
print("ALL OK — 评析目标名单") print("ALL OK — 评析目标名单")