Files
Jyotisha/scripts/report_render/yoga_appendix_fields.py
T
ClaudeandClaude Opus 5.5 8eee1536c1
Independent Staging Quality Gate / validate-python (push) Successful in 7m23s
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m8s
Independent Staging Quality Gate / publish (push) Successful in 19m27s
fix(report): Raja rows formed with a 6/8/12 lordship show the engine's mixed-effect note (BUG-2394)
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
2026-11-26 04:49:05 +08:00

117 lines
5.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""BUG-2377 (占星师 2026-11-25 M01 / M02 / M05; M08's unresolved rules stay backstage, BUG-2384): per-yoga fields for the appendix yoga table.
The detector already returns, per row, what kind of statement it is, whether the rule's conditions are all met,
which inputs were missing, and where the condition and the meaning come from. The appendix table showed only
name, category and planet. These helpers turn those fields into reader words.
Sources follow the owner's rules: only in appendix data chapters (2026-11-24), book title only — no page, PDF
page, line number or table number (BUG-2129), no software library names (BUG-2115).
"""
from __future__ import annotations
import re
from typing import Any
KIND_WORDS = {
"named_yoga_candidate": ("具名格局", "Named yoga"),
"structural_observation": ("结构观察", "Structural observation"),
}
FORMATION_WORDS = {
"conditions_met": ("规则条件都满足", "All rule conditions met"),
"incomplete_conditions": ("部分条件满足", "Some conditions met"),
"method_requires_review": ("不计为成立(判法不止一种)", "Not counted as formed (more than one way to judge it)"),
}
_MISSING_WORDS = {
"source_admitted_composite_strength_profile": ("综合强弱的判法", "a way to judge overall strength"),
"source_admitted_favourable_position_profile": ("「有利位置」的判法", "a way to judge a favourable position"),
"neechamsa_scope_and_referents_source_choice": ("落陷分区的判断范围", "the scope of the debilitated division"),
"benefic_amsa_source_scope": ("吉星分区的判断范围", "the scope of a benefic division"),
"saturn_d3_dispositor": ("土星在 D3 的定位星", "Saturn's dispositor in D3"),
}
_MISSING_DEFAULT = ("规则用到的另一项输入", "another input the rule uses")
_PLANETS_ZH = {"Sun": "太阳", "Moon": "月亮", "Mars": "火星", "Mercury": "水星", "Jupiter": "木星", "Venus": "金星",
"Saturn": "土星", "Rahu": "罗睺", "Ketu": "计都"}
# Book titles a source string may name, in reader words. Anything else is a local rule with no named source.
_BOOKS = (
(re.compile(r"Three Hundred Important Combinations|^BVR-|^Raman\d|^B\.V\. Raman|^Raman,"), ("B.V. Raman《三百个重要组合》", "B.V. Raman, Three Hundred Important Combinations")),
(re.compile(r"Light on Life"), ("《Light on Life》", "Light on Life")),
(re.compile(r"PVR Integrated Approach|Integrated Approach"), ("P.V.R. Narasimha Rao《Vedic Astrology: An Integrated Approach》", "P.V.R. Narasimha Rao, Vedic Astrology: An Integrated Approach")),
(re.compile(r"^BPHS$"), ("《BPHS》", "BPHS")),
(re.compile(r"Phaladeepika|Phaladipika"), ("《Phaladeepika》", "Phaladeepika")),
(re.compile(r"^经典$"), ("经典文献", "classical texts")),
)
_NO_SOURCE = ("本地结构规则,没有具名出处", "local structural rule; no named source")
_NOT_LISTED = ("—", "—")
def _pick(pair: tuple[str, str], language: str) -> str:
return pair[0] if language == "zh" else pair[1]
def kind_text(row: dict, language: str) -> str:
return _pick(KIND_WORDS.get(str(row.get("claim_kind")), _NOT_LISTED), language)
def formation_note(row: Any, language: str) -> str:
"""BUG-2394: the engine's plain modifier note on a formed row (BUG-2392, e.g. a Raja lord that also rules 6/8/12)."""
if not isinstance(row, dict):
return ""
note = row.get("formation_note_zh" if language == "zh" else "formation_note_en")
return note.strip() if isinstance(note, str) else ""
def with_formation_note(text: str, row: Any, language: str) -> str:
note = formation_note(row, language)
if not note or note in text:
return text
if language == "zh":
return f"{text.rstrip('。')}。{note}"
return f"{text.rstrip('.')}. {note}"
def formation_text(row: dict, language: str) -> str:
assessment = row.get("formation_assessment") if isinstance(row.get("formation_assessment"), dict) else {}
if assessment.get("status") == "formed_under_source":
return with_formation_note("按具名定义成立" if language == "zh" else "Formed under the named definition", row, language)
return _pick(FORMATION_WORDS.get(str(row.get("formation_status")), _NOT_LISTED), language)
def missing_text(row: dict, language: str) -> str:
items = [item for item in row.get("missing_inputs") or [] if isinstance(item, str) and item]
if not items:
return "—"
words = []
for item in items:
owner, _, key = item.rpartition(".")
text = _pick(_MISSING_WORDS.get(key, _MISSING_DEFAULT), language)
if owner in _PLANETS_ZH:
text = f"{_PLANETS_ZH[owner]}:{text}" if language == "zh" else f"{owner}: {text}"
if text not in words:
words.append(text)
return (";" if language == "zh" else "; ").join(words)
def source_text(value: Any, language: str) -> str:
"""The book a source string names, without pages or line numbers; a local rule says so."""
if not isinstance(value, str) or not value.strip():
return "—"
text = value.strip()
for pattern, pair in _BOOKS:
if pattern.search(text):
return _pick(pair, language)
return _pick(_NO_SOURCE, language)
def condition_source(row: dict, language: str) -> str:
return source_text(row.get("source_reference") or row.get("source"), language)
def meaning_source(row: dict, language: str) -> str:
if row.get("meaning_source_reference"):
return source_text(row.get("meaning_source_reference"), language)
# The rule entry carries its own meaning: same place as the condition.
if row.get("traditional_effects") or row.get("effects"):
return "同条件出处" if language == "zh" else "same as condition source"
return "—"