Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
142 lines
7.0 KiB
Python
142 lines
7.0 KiB
Python
"""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
|
||
import re
|
||
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
|
||
_translate_annual_values(paths)
|
||
return paths
|
||
|
||
|
||
# BUG-2291 follow-up: her annual rows translate only the affliction values she lists; this site's annual
|
||
# producer also returns these two, which printed raw (「限制条件:retrograde」「dusthana_宫」).
|
||
_AFFLICTION_ZH = {"retrograde": "逆行", "dusthana_house": "落在六、八、十二宫"}
|
||
_AFFLICTION_EN = {"retrograde": "retrograde", "dusthana_house": "in house 6, 8 or 12"}
|
||
|
||
|
||
def _translate_annual_values(paths: dict) -> None:
|
||
for row in paths.get("rows") or []:
|
||
if not isinstance(row, dict) or row.get("kind") != "annual_process":
|
||
continue
|
||
for fact in row.get("facts") or []:
|
||
if not isinstance(fact, dict):
|
||
continue
|
||
for raw, word in _AFFLICTION_ZH.items():
|
||
if isinstance(fact.get("zh"), str):
|
||
fact["zh"] = re.sub(rf"限制条件:{raw}(?![A-Za-z_])", f"限制条件:{word}", fact["zh"])
|
||
for raw, word in _AFFLICTION_EN.items():
|
||
if isinstance(fact.get("en"), str):
|
||
fact["en"] = re.sub(rf"Limiting condition: {raw}(?![A-Za-z_])", f"Limiting condition: {word}", fact["en"])
|
||
|
||
|
||
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
|