28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
"""评析目标名单:主榜与观察档转点后缀式、去重、名次;写入可注入。"""
|
|
import review_targets as rt
|
|
|
|
|
|
def t(name, cond):
|
|
print((" ok " if cond else " FAIL") + name)
|
|
assert cond, name
|
|
|
|
|
|
def main():
|
|
snap = {"main": [{"code": "SH600519", "name": "贵州茅台"}, {"code": "SZ300750", "name": "宁德时代"}, {"code": "SH600519"}],
|
|
"observe": [{"code": "SZ000001", "name": "平安银行"}, {"code": "bad"}]}
|
|
rows = rt.build_rows("2026-09-08", snap["main"], snap["observe"])
|
|
t("点后缀式且去重", [r["ts_code"] for r in rows] == ["600519.SH", "300750.SZ", "000001.SZ"])
|
|
t("来源与名次", rows[0]["source"] == "main" and rows[0]["rank"] == 1 and rows[2]["source"] == "observe" and rows[2]["rank"] == 1)
|
|
got = {}
|
|
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))
|
|
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 — 评析目标名单")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|