Files
Jyotisha/scripts/kp_monthly_vimshottari.py
T
ClaudeandClaude Opus 5.5 295d23bf57 fix(dasha): float sub-period split on every non-frozen AD/PD path (BUG-1719)
reference_transparency_contract: birth-moment MDs + birth_moment.antardashas
instead of the date-anchored frozen service + integer-day build_antardasha.
KP monthly: elapsed years from the full-precision MD start (total_seconds).
birth_moment.split_period: generic float split, last end pinned to parent.
Frozen dasha_analyzer / domain_calculation_service untouched; rectification
scoring keeps the integer split pending a product decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 23:35:38 +08:00

74 lines
3.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""Monthly five-level Vimshottari snapshots for the KP monthly report."""
from __future__ import annotations
from datetime import datetime
try: # pragma: no cover - import path differs under CLI vs pytest
from dasha_calculator_enhanced import calculate_five_level_dasha
from chart_dasha.birth_moment import compute_vimshottari_timeline # issue #137: same start as the report
from chart_dasha.birth_moment import mahadashas as birth_moment_mahadashas
except ImportError: # pragma: no cover
from scripts.dasha_calculator_enhanced import calculate_five_level_dasha
from scripts.chart_dasha.birth_moment import compute_vimshottari_timeline
from scripts.chart_dasha.birth_moment import mahadashas as birth_moment_mahadashas
def _current_period(timeline: dict, anchor_dt: datetime) -> dict:
"""The mahadasha running at ``anchor_dt``.
The birth-moment timeline (issue #137) returns ``periods`` only, without the
``current_dasha`` the old service returned; without this every month fell
back to the birth-balance lord with zero elapsed years.
"""
anchor = anchor_dt.strftime("%Y-%m-%d")
for row in timeline.get("periods") or []:
if isinstance(row, dict) and str(row.get("start") or "") <= anchor < str(row.get("end") or ""):
return row
return {}
def build_monthly_vimshottari_snapshot(
*, birth_dt: datetime, moon_lon: float, anchor_dt: datetime
) -> dict:
timeline = compute_vimshottari_timeline(
birth_dt=birth_dt,
moon_lon=moon_lon,
current_date=anchor_dt,
)
current = timeline.get("current_dasha") or _current_period(timeline, anchor_dt)
# BUG-1719: 原值 elapsed = (anchor - 日期粒度的大运起点).days / 365.25(起点丢出生时刻、
# 跨度取整数天,五级里 Sookshma / Prana 在边界附近会换主星);新值用出生时刻起算的
# 完整精度大运起点与 total_seconds。
precise_rows, *_ = birth_moment_mahadashas(birth_dt, moon_lon, through=anchor_dt)
precise = next((row for row in precise_rows if row["start"] <= anchor_dt < row["end"]), None)
if precise is not None:
elapsed_years = max((anchor_dt - precise["start"]).total_seconds() / 86400.0 / 365.25, 0.0)
md_lord = precise["lord"]
else:
start_text = current.get("start")
if start_text:
current_start = datetime.strptime(start_text, "%Y-%m-%d")
elapsed_years = max((anchor_dt - current_start).total_seconds() / 86400.0 / 365.25, 0.0)
else:
elapsed_years = 0.0
md_lord = current.get("lord") or timeline.get("birth_balance", {}).get("lord")
levels = calculate_five_level_dasha(md_lord, elapsed_years)
return {
"anchor_date": anchor_dt.strftime("%Y-%m-%d"),
"timeline": {
"current_dasha": current,
"birth_balance": timeline.get("birth_balance"),
},
"levels": {
"mahadasha": levels.get("mahadasha"),
"antardasha": levels.get("bhukti"),
"pratyantardasha": levels.get("pratyantar"),
"sookshma": levels.get("sookshma"),
"prana": levels.get("prana"),
},
"status": "parameter_sensitive",
"must_not_claim": ["exact_event_timing", "specific_event_prediction"],
}