diff --git a/plan.py b/plan.py index b64a455..a8acf75 100644 --- a/plan.py +++ b/plan.py @@ -104,7 +104,7 @@ def _val(series: pd.Series, k: str): def _assemble_cards(ds: str, codes: list, ev: dict, upside: pd.Series, - mkt_days: set) -> tuple[dict, list]: + mkt_days: set, risk: set | None = None) -> tuple[dict, list]: """候选卡装配(2026-09-02 方案第 2.2 节第三项):对档位表里的全部票(主榜与观察档, 裁剪之前)读三路证据、逐票判决。规则在 card.py,取数在 sources.py,这里只做对齐。 @@ -117,10 +117,11 @@ def _assemble_cards(ds: str, codes: list, ev: dict, upside: pd.Series, moved = sources.moved_members(ds) daily = sources.stock_daily(ds) night = sources.night_conclusions(codes, ds) - try: - risk = factors._risk_set() or set() # noqa: SLF001 —— 同仓自用 - except Exception: # noqa: BLE001 —— 风险名单拿不到时不当 ST 处理,与 gate 的宽容一致 - risk = set() + if risk is None: # collect 会传入读过一次的名单;单独调用时自己读 + try: + risk = factors._risk_set() or set() # noqa: SLF001 —— 同仓自用 + except Exception: # noqa: BLE001 —— 风险名单拿不到时不当 ST 处理,与 gate 的宽容一致 + risk = set() stale = bool(mkt_days) and any(x != ds for x in mkt_days) cards: dict = {} @@ -217,8 +218,13 @@ def collect(date: str | None = None, top: int = 20, obs_top: int = 10, main = score[score >= _MAIN_MIN].sort_values(ascending=False) obs = score[score < _MAIN_MIN].sort_values(ascending=False) generated_at = dt.datetime.now().isoformat(timespec="seconds") + try: # 风险名单只读一次:候选卡与升降档原因共用 + import factors + risk = factors._risk_set() or set() # noqa: SLF001 —— 同仓自用 + except Exception: # noqa: BLE001 + risk = set() cards, segments_pointed = _assemble_cards( - ds, list(main.index) + list(obs.index), ev, upside, mkt_days) + ds, list(main.index) + list(obs.index), ev, upside, mkt_days, risk=risk) def _pick(ranked: pd.Series, n: int): """分数从高到低取 n 条;每个传导主题最多 theme_cap 条(0=不设限)—— @@ -299,11 +305,10 @@ def collect(date: str | None = None, top: int = 20, obs_top: int = 10, # 赛道闸与风险闸的成员集合(07-31 修:赛道闸开启后,"不在赛道"曾被 # 误标成"风险闸/档位调整"、"赛道锚生效"曾被误标成"新进传导链")。 # 两个集合都尊重各自开关:闸没开时对应原因自然不会出现。 - tset, risk = None, set() + tset = None try: import factors tset = factors._track_set() # noqa: SLF001 —— 同仓自用 - risk = factors._risk_set() # noqa: SLF001 except Exception: # noqa: BLE001 —— 拿不到就退化为通用文案 pass