Owner 2026-11-21: after BUG-2115 the full-data report still printed source lines and book references (Goel 出处 line, the PVR 2014 article in the conditional-dasha note, PVR / Light on Life / BPHS verse in the calculation notes, Tithi lord table source, rashi-dasha 出处 lines, Narayana p.43 label and p.50 / Table 13 direction notes, functional profile source row, Ashtakavarga book calibration). Method names stay; the book, page, chapter and ruling round go. Engine labels for the consultation card are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
228 lines
10 KiB
Python
228 lines
10 KiB
Python
#!/usr/bin/env python3
|
||
"""Markdown chapter for the seven report-only rashi dashas."""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Mapping
|
||
|
||
try:
|
||
from rashi_dashas_native import calculate_rashi_dashas
|
||
from report_render.reader_keys import reader_key
|
||
except ImportError: # pragma: no cover - package import
|
||
from scripts.rashi_dashas_native import calculate_rashi_dashas
|
||
from scripts.report_render.reader_keys import reader_key
|
||
|
||
_SIGN_CN = {
|
||
"Aries": "白羊座",
|
||
"Taurus": "金牛座",
|
||
"Gemini": "双子座",
|
||
"Cancer": "巨蟹座",
|
||
"Leo": "狮子座",
|
||
"Virgo": "处女座",
|
||
"Libra": "天秤座",
|
||
"Scorpio": "天蝎座",
|
||
"Sagittarius": "射手座",
|
||
"Capricorn": "摩羯座",
|
||
"Aquarius": "水瓶座",
|
||
"Pisces": "双鱼座",
|
||
}
|
||
# Chinese headings avoid the token Dasha. The report cleaner turns that token
|
||
# into 大运 and then deletes the linebreak before the next Chinese sentence.
|
||
_ORDER = (
|
||
("sthira", "Sthira", "Sthira Dasha"),
|
||
("niryaana_shoola", "Niryaana Shoola", "Niryaana Shoola Dasha"),
|
||
("drig", "Drig", "Drig Dasha"),
|
||
("navamsha", "Navamsha", "Navamsha Dasha"),
|
||
("shoola", "Shoola", "Shoola Dasha"),
|
||
("chara", "Chara", "Chara Dasha"),
|
||
("lagna_kendradi", "Lagna Kendradi", "Lagna Kendradi Rashi Dasha"),
|
||
)
|
||
_CLASSICAL = ("Sun", "Moon", "Mars", "Mercury", "Jupiter", "Venus", "Saturn")
|
||
|
||
|
||
def _language(packet: Mapping) -> str:
|
||
raw = packet.get("report_language") or packet.get("language") or "zh"
|
||
return "en" if str(raw).lower().startswith("en") else "zh"
|
||
|
||
|
||
def _longitude(row: Mapping) -> float | None:
|
||
# Ascendant "degree" is the degree inside the sign. Full longitude is degree_raw / lon.
|
||
for key in ("degree_raw", "lon", "longitude"):
|
||
value = row.get(key)
|
||
if isinstance(value, (int, float)):
|
||
return float(value)
|
||
sign = row.get("sign")
|
||
degree = row.get("degree_in_sign")
|
||
if sign in _SIGN_CN and isinstance(degree, (int, float)):
|
||
signs = list(_SIGN_CN)
|
||
return signs.index(str(sign)) * 30.0 + float(degree)
|
||
return None
|
||
|
||
|
||
def _birth_date(packet: Mapping) -> str | None:
|
||
birth = packet.get("birth_info")
|
||
if not isinstance(birth, Mapping):
|
||
return None
|
||
if birth.get("date"):
|
||
return str(birth.get("date"))
|
||
year, month, day = birth.get("year"), birth.get("month"), birth.get("day")
|
||
if all(isinstance(part, int) for part in (year, month, day)):
|
||
return f"{int(year):04d}-{int(month):02d}-{int(day):02d}"
|
||
return None
|
||
|
||
|
||
def chart_inputs(packet: Mapping) -> dict | None:
|
||
core = packet.get("core_chart")
|
||
if not isinstance(core, Mapping):
|
||
return None
|
||
asc = core.get("ascendant")
|
||
planets = core.get("planets")
|
||
if not isinstance(asc, Mapping) or not isinstance(planets, Mapping):
|
||
return None
|
||
asc_lon = _longitude(asc)
|
||
birth = _birth_date(packet)
|
||
if asc_lon is None or not birth:
|
||
return None
|
||
longitudes = {}
|
||
for name in list(_CLASSICAL) + ["Rahu", "Ketu"]:
|
||
row = planets.get(name)
|
||
if isinstance(row, Mapping):
|
||
value = _longitude(row)
|
||
if value is not None:
|
||
longitudes[name] = value
|
||
if any(name not in longitudes for name in _CLASSICAL):
|
||
return None
|
||
return {"birth": birth, "ascendant_longitude": asc_lon, "planet_lons": longitudes}
|
||
|
||
|
||
def _sign_label(sign: str, language: str) -> str:
|
||
if language == "zh":
|
||
return _SIGN_CN.get(sign, sign)
|
||
return sign
|
||
|
||
|
||
def _method_line(section: Mapping, language: str) -> str:
|
||
if section.get("status") != "listed":
|
||
return str(section.get("reason_en") if language == "en" else section.get("reason_zh") or "")
|
||
# BUG-2095: the method by name (author / book), not its profile id (`goel_method_1_v1`).
|
||
profile = reader_key(section.get("profile_id") or "", language)
|
||
if language == "en":
|
||
# BUG-2129 (负责人 2026-11-21): the method's name only; no book, chapter or page.
|
||
return f"Method used on this site: {profile}; not checked one-by-one against external software."
|
||
return f"本站选用的方法:{profile};未与外部软件逐一核对。"
|
||
|
||
|
||
_PLANET_CN = {"Sun": "太阳", "Moon": "月亮", "Mars": "火星", "Mercury": "水星", "Jupiter": "木星", "Venus": "金星", "Saturn": "土星"}
|
||
|
||
|
||
def _sthira_note(section: Mapping, language: str) -> str:
|
||
"""BUG-1677: Brahma by Goel's full method; the short method is shown for comparison."""
|
||
planet = str(section.get("brahma_planet") or "")
|
||
sign = str((section.get("periods") or [{}])[0].get("sign") or "")
|
||
comparison = section.get("brahma_comparison") if isinstance(section.get("brahma_comparison"), Mapping) else None
|
||
fallback = str(section.get("profile_id") or "").endswith("_fallback")
|
||
if language == "en":
|
||
text = (f"Brahma by the K.N. Rao short method: {planet}; Goel's full method gave no unique Brahma. " if fallback
|
||
else f"Brahma by Goel's full method: {planet}; Sthira starts from {sign}. ")
|
||
if comparison:
|
||
same = comparison.get("brahma_planet") == planet
|
||
text += ("The K.N. Rao short method gives the same Brahma." if same else
|
||
f"Alternative: the K.N. Rao short method gives {comparison.get('brahma_planet')}, starting from {comparison.get('start_sign')}; "
|
||
"it is kept as a separate comparison and is not used for this table.")
|
||
if not fallback:
|
||
text += " Open point: how the full method compares the lords is pending verification."
|
||
return text.strip()
|
||
cn = lambda name: _PLANET_CN.get(str(name), str(name))
|
||
text = (f"Goel 完整方法没有选出唯一的 Brahma,本表按 K.N. Rao 短法:Brahma 为{cn(planet)}。" if fallback
|
||
else f"Brahma 按 Goel 完整方法定为{cn(planet)},Sthira 从{_SIGN_CN.get(sign, sign)}起。")
|
||
if comparison:
|
||
same = comparison.get("brahma_planet") == planet
|
||
text += ("K.N. Rao 短法结果相同。" if same else
|
||
f"对照:K.N. Rao 短法定为{cn(comparison.get('brahma_planet'))},从{_SIGN_CN.get(str(comparison.get('start_sign')), comparison.get('start_sign'))}起;"
|
||
"短法单独保留作对照,本表不用。")
|
||
if not fallback:
|
||
text += "待核:完整方法如何比较三颗宫主仍待核对。"
|
||
return text
|
||
|
||
|
||
def render_rashi_dasha_chapter(packet: Mapping) -> str:
|
||
"""Return the chapter, or an empty string when the packet has no longitudes."""
|
||
inputs = chart_inputs(packet)
|
||
if inputs is None:
|
||
return ""
|
||
language = _language(packet)
|
||
sections = calculate_rashi_dashas(inputs["birth"], inputs["ascendant_longitude"], inputs["planet_lons"])
|
||
if language == "en":
|
||
lines = [
|
||
"## Sign dashas calculated on this site",
|
||
"",
|
||
"These tables list signs and dates only.",
|
||
"",
|
||
]
|
||
sign_header = "| Index | Sign | Start | End | Years |"
|
||
child_header = "| Index | Maha | Antara | Start | End |"
|
||
else:
|
||
lines = [
|
||
"## 星座大运(本站计算)",
|
||
"",
|
||
"以下只列出星座和日期。",
|
||
"",
|
||
]
|
||
sign_header = "| 序号 | 星座 | 起始 | 结束 | 年数 |"
|
||
child_header = "| 序号 | 大运 | 小运 | 起始 | 结束 |"
|
||
for key, title_zh, title_en in _ORDER:
|
||
section = sections[key]
|
||
title = title_en if language == "en" else title_zh
|
||
lines.extend([f"### {title}", "", _method_line(section, language), ""])
|
||
if key == "sthira" and section.get("status") == "listed":
|
||
lines.extend([_sthira_note(section, language), ""])
|
||
if key == "drig" and section.get("year_rule") == "narayana_rath_sign_period":
|
||
lines.extend([
|
||
"Sign order by aspects from the 9th, 10th and 11th houses; each sign's years follow this site's Narayana "
|
||
"rules, including the dual-lord choice and exaltation / debilitation adjustments."
|
||
if language == "en"
|
||
else "星座顺序按第 9、10、11 宫及其相照星座排列;每个星座的年数与本站 Narayana 大运同一套规则,"
|
||
"包括双主星择强与入旺、落陷调整。",
|
||
"",
|
||
])
|
||
if key == "niryaana_shoola" and section.get("status") == "listed":
|
||
lines.extend([
|
||
"There is no separate sub-period rule. Sub-periods follow the upstream export (forward from the major sign, twelve equal parts) and are for comparison only."
|
||
if language == "en"
|
||
else "没有单列的小运规则。小运按上游导出的口径列出(从大运星座起顺排十二宫、均分),只作对照。",
|
||
"",
|
||
])
|
||
if key == "lagna_kendradi" and section.get("status") == "listed":
|
||
lines.extend([
|
||
"Upstream candidate profile; not checked against a book example. Only major periods are listed."
|
||
if language == "en"
|
||
else "按上游的候选口径计算,未经书例核对;只列大运。",
|
||
"",
|
||
])
|
||
if key == "chara" and section.get("status") == "listed":
|
||
lines.extend([
|
||
"This section is the K.N. Rao Chara table. It is not the Narayana table."
|
||
if language == "en"
|
||
else "这一节是 K.N. Rao 的 Chara 表,不是 Narayana 表。",
|
||
"",
|
||
])
|
||
periods = section.get("periods") or []
|
||
if not periods:
|
||
continue
|
||
lines.extend([sign_header, "|------|------|------|------|------|"])
|
||
child_rows = []
|
||
for index, period in enumerate(periods, start=1):
|
||
label = _sign_label(str(period.get("sign")), language)
|
||
lines.append(
|
||
f"| {index} | {label} | {period.get('start')} | {period.get('end')} | {period.get('years')} |"
|
||
)
|
||
for child in period.get("antardasha") or []:
|
||
child_rows.append((label, _sign_label(str(child.get("sign")), language), child.get("start"), child.get("end")))
|
||
lines.append("")
|
||
if child_rows:
|
||
lines.extend([child_header, "|------|------|------|------|------|"])
|
||
for index, (parent, child, start, end) in enumerate(child_rows, start=1):
|
||
lines.append(f"| {index} | {parent} | {child} | {start} | {end} |")
|
||
lines.append("")
|
||
return "\n".join(lines).rstrip() + "\n"
|