BUG-2392 writes formation_note_zh / formation_note_en on formed Raja rows whose lords also rule 6, 8 or 12. The report now prints that note after the status in the body yoga table, after the formation line on the yoga page, and in the appendix table's formation cell. Also updates a stale assertion from BUG-2367 (the PD-only cell in the house-lord column). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp3RzgZVEpT1PXxkwHj
223 lines
11 KiB
Python
223 lines
11 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.
|
||
Our product differences (BUG-2366 varga house, BUG-2381 Mahapurusha degree, BUG-2382 no body source line) live
|
||
here, so her file stays byte-identical (owner 2026-11-07: differences only in separate product files).
|
||
|
||
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 _fill_varga_houses(varga_full: Any) -> Any:
|
||
"""BUG-2366: varga rows carry sign_idx but no house; the house is counted from that varga's own
|
||
Ascendant (the data tables print it), so her module never writes 「宫位未提供」 for a known house."""
|
||
if not isinstance(varga_full, dict):
|
||
return varga_full
|
||
out = {}
|
||
for key, varga in varga_full.items():
|
||
if not isinstance(varga, dict):
|
||
out[key] = varga
|
||
continue
|
||
asc = _dict(varga.get("Ascendant")).get("sign_idx")
|
||
filled = {}
|
||
for name, item in varga.items():
|
||
if (isinstance(item, dict) and item.get("house") is None and isinstance(item.get("sign_idx"), int)
|
||
and isinstance(asc, int)):
|
||
item = {**item, "house": (item["sign_idx"] - asc) % 12 + 1}
|
||
filled[name] = item
|
||
out[key] = filled
|
||
return out
|
||
|
||
|
||
def expression_modules(full_reading: dict, pd_usable: bool) -> dict:
|
||
modules = copy.copy(_dict(_dict(full_reading).get("modules")))
|
||
if "varga_full" in modules:
|
||
modules["varga_full"] = _fill_varga_houses(modules["varga_full"])
|
||
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)
|
||
_drop_house_not_supplied(paths)
|
||
_mahapurusha_degree(paths, _dict(_dict(shim["raw_full_reading"]["modules"].get("chart")).get("planets")))
|
||
return paths
|
||
|
||
|
||
def _drop_house_not_supplied(paths: dict) -> None:
|
||
"""BUG-2366: a divisional fact whose house is still unknown says the sign only, not 「宫位未提供」."""
|
||
for row in paths.get("rows") or []:
|
||
for fact in (row.get("facts") or []) if isinstance(row, dict) else []:
|
||
if isinstance(fact, dict):
|
||
if isinstance(fact.get("zh"), str):
|
||
fact["zh"] = fact["zh"].replace(",宫位未提供;", ";")
|
||
if isinstance(fact.get("en"), str):
|
||
fact["en"] = fact["en"].replace(", house not supplied;", ";")
|
||
|
||
|
||
def _mahapurusha_degree(paths: dict, positions: dict) -> None:
|
||
"""BUG-2381 (占星师 2026-11-25 M03): the degree and the dignity word stand beside the two conditions."""
|
||
for row in paths.get("rows") or []:
|
||
if not isinstance(row, dict) or row.get("kind") != "mahapurusha_definition" or not row.get("facts"):
|
||
continue
|
||
planet = (row.get("participants") or [None])[0]
|
||
data = _dict(positions.get(planet))
|
||
degree = data.get("degree_in_sign")
|
||
moola = "Moolatrikona" in str(data.get("status") or "")
|
||
first = row["facts"][0]
|
||
if not isinstance(first, dict) or not str(first.get("en", "")).startswith(f"{planet}: "):
|
||
continue
|
||
if isinstance(degree, (int, float)):
|
||
first["en"] = f"{first['en']}; {float(degree):.2f}° in sign"
|
||
first["zh"] = f"{first['zh']};星座内 {float(degree):.2f}°"
|
||
if moola:
|
||
first["en"] = f"{first['en']}; Moolatrikona"
|
||
first["zh"] = f"{first['zh']};Moolatrikona(本垣)"
|
||
|
||
|
||
def render_paths(paths: dict, language: str) -> str:
|
||
"""Her renderer, without the per-path 「来源:」 line: BUG-2382 — no book or page in the report body
|
||
(owner 2026-11-21 BUG-2129, 2026-11-24 density rule 3); each yoga's book is in the appendix yoga
|
||
table, and the stored rows keep ``source`` for the model."""
|
||
try:
|
||
from scripts.yoga_expression_paths import render_expression_paths
|
||
except ModuleNotFoundError: # pragma: no cover - scripts/ on sys.path
|
||
from yoga_expression_paths import render_expression_paths
|
||
lines = render_expression_paths(paths, language).split("\n")
|
||
out: list[str] = []
|
||
skip_blank = False
|
||
for line in lines:
|
||
if line.startswith("来源:") or line.startswith("Source: "):
|
||
skip_blank = True
|
||
continue
|
||
if skip_blank and line == "":
|
||
skip_blank = False
|
||
continue
|
||
skip_blank = False
|
||
out.append(line)
|
||
return "\n".join(out)
|
||
|
||
|
||
# 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
|