"""BUG-2296 (占星师 2026-11-23 信息密度交接 §2–3, 产品负责人 2026-11-24「接着做」): this site's wiring for the astrologer's ``yoga_expression_paths`` module, which is copied verbatim from upstream 58f37ee5b. Her module reads the full reading's modules. This file only adapts this site's shapes to hers, without changing any value: * ``functional_benefic_malefic``: this site names the profile ``functional_profile`` and lists ``blocked_planets``; hers reads ``profile`` and a per-planet ``planet_status``. * ``dasha.current_dasha``: this site keeps the antardasha in ``timeline[*].antardasha_timeline``; hers reads ``current_dasha.antardasha``. The current pratyantardasha is passed only when the PD is usable under this site's rule (BUG-2157 / BUG-2260), so the paths never date a link by a PD the report does not use. * Annual: her ``attach_expression_paths`` reads the governed named rows at ``annual_tajika_pack.tajika_yogas``; this site keeps them at ``annual_tajika_pack.tajika_named_yogas``. The paths are computed once, when the report packet is built (the full reading is in hand there), and stored on the packet; the yoga interpretation pack picks them up when the report is rendered. """ from __future__ import annotations import copy from typing import Any STORE_KEY = "yoga_expression_paths" def _dict(value: Any) -> dict: return value if isinstance(value, dict) else {} def _functional(module: Any) -> Any: if not isinstance(module, dict): return module out = dict(module) out.setdefault("profile", module.get("functional_profile")) status = dict(_dict(module.get("planet_status"))) for planet in module.get("blocked_planets") or []: status.setdefault(planet, "blocked") out["planet_status"] = status return out def _dasha(module: Any, pd_usable: bool) -> Any: if not isinstance(module, dict): return module out = dict(module) current = dict(_dict(module.get("current_dasha"))) if "antardasha" not in current: md = next((row for row in module.get("timeline") or [] if isinstance(row, dict) and row.get("is_current") is True), None) ad = next((row for row in _dict(md).get("antardasha_timeline") or [] if isinstance(row, dict) and row.get("is_current") is True), None) if isinstance(ad, dict): antardasha = {key: value for key, value in ad.items() if key != "pratyantar_dasha_timeline"} if pd_usable: antardasha["pratyantar_dasha_timeline"] = [row for row in ad.get("pratyantar_dasha_timeline") or [] if isinstance(row, dict) and row.get("is_current") is True] current["antardasha"] = antardasha elif not pd_usable and isinstance(current.get("antardasha"), dict): current["antardasha"] = {key: value for key, value in current["antardasha"].items() if key != "pratyantar_dasha_timeline"} out["current_dasha"] = current return out def expression_modules(full_reading: dict, pd_usable: bool) -> dict: modules = copy.copy(_dict(_dict(full_reading).get("modules"))) if "functional_benefic_malefic" in modules: modules["functional_benefic_malefic"] = _functional(modules["functional_benefic_malefic"]) if "dasha" in modules: modules["dasha"] = _dasha(modules["dasha"], pd_usable) return modules def compute_expression_paths(full_reading: dict, packet: dict) -> dict: """The astrologer's expression paths for this chart, with the annual rows; a blocked record on failure.""" try: from scripts.yoga_expression_paths import attach_expression_paths from scripts.report_render.indirect_activation import pd_precision except ModuleNotFoundError: # pragma: no cover - scripts/ on sys.path from yoga_expression_paths import attach_expression_paths from report_render.indirect_activation import pd_precision try: pd_usable = bool(pd_precision(packet)[0]) except Exception: # noqa: BLE001 - an unchecked PD stays out pd_usable = False annual = _dict(_dict(_dict(packet.get("worksheets")).get("timing_and_predictive_systems")).get("annual_tajika_pack")) shim = { "raw_full_reading": {"modules": expression_modules(full_reading, pd_usable)}, "worksheets": { "advanced_systems": {"yoga_interpretation_pack": {"pages": []}}, "timing_and_predictive_systems": {"annual_tajika_pack": { "tajika_yogas": annual.get("tajika_named_yogas") or annual.get("tajika_yogas") or {}, "solar_return": annual.get("solar_return") or {}, }}, }, } try: attach_expression_paths(shim) paths = shim["worksheets"]["advanced_systems"]["yoga_interpretation_pack"]["expression_paths"] except Exception as error: # noqa: BLE001 - the report renders without the section return {"status": "blocked", "reason": type(error).__name__, "rows": []} if isinstance(paths, dict): paths.setdefault("status", "computed") paths["pd_used"] = pd_usable return paths def attach_engine_expression_paths(full_reading: dict, packet: dict) -> None: """Store the paths on the report packet (both places the packet keeps advanced systems).""" paths = compute_expression_paths(full_reading, packet) for holder in (packet.setdefault("worksheets", {}).setdefault("advanced_systems", {}), packet.setdefault("advanced_systems", {})): if isinstance(holder, dict): holder[STORE_KEY] = paths def stored_expression_paths(packet: dict) -> dict | None: for holder in (_dict(_dict(packet.get("worksheets")).get("advanced_systems")), _dict(packet.get("advanced_systems"))): paths = holder.get(STORE_KEY) if isinstance(paths, dict) and isinstance(paths.get("rows"), list): return paths return None