feat(dasha): Yogini 小运按比例单列,大运输出不变

完整解读仍只看大运。小运从该大运自己的 Yogini 起按年数比例排,出生前的段丢掉。

Co-Authored-By: Grok (agent loop)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jesse-ux
2026-10-22 03:33:19 +08:00
co-authored by Grok (agent loop) Cursor
parent 28dd8df333
commit 6eeb98c774
2 changed files with 128 additions and 1 deletions
+53
View File
@@ -61,10 +61,63 @@ def calculate_yogini_dasha(birth_info: dict) -> dict:
moon_longitude: sidereal degrees, required
as_of / today: observation instant; report callers should pass it
dasha_year_days: fixed-day year, default 365.25
Major rows stay free of sub-periods. Callers that need antardashas use
``yogini_antardashas`` on a copy.
"""
return _calculate_moon_balanced_yogini(birth_info)
def _as_datetime(value):
if isinstance(value, datetime):
return value
return datetime.fromisoformat(str(value))
def yogini_antardashas(major_row: dict, *, birth_dt, year_days: float) -> list:
"""Proportional antardashas inside one Yogini mahadasha.
Eight sub-periods start at this mahadasha's own Yogini and follow Goel
Table I. Each length is ``full_years * sub_years / 36``. They are laid out
from ``unclipped_start_date``. Sub-periods that end at or before birth are
dropped. The one that crosses birth keeps ``unclipped_start_date`` and
starts at birth. The last sub-period ends on the mahadasha ``end_date``.
"""
birth = _as_datetime(birth_dt)
year_length = float(year_days)
if year_length <= 0:
raise ValueError('dasha_year_days must be positive')
start_idx = next(
index for index, item in enumerate(YOGINI_SEQUENCE) if item['name'] == major_row['yogini']
)
full_years = float(major_row['full_years'])
cursor = _as_datetime(major_row['unclipped_start_date'])
major_end = _as_datetime(major_row['end_date'])
rows = []
for offset in range(len(YOGINI_SEQUENCE)):
item = YOGINI_SEQUENCE[(start_idx + offset) % len(YOGINI_SEQUENCE)]
span_days = full_years * item['years'] / TOTAL_CYCLE * year_length
end = major_end if offset == len(YOGINI_SEQUENCE) - 1 else cursor + timedelta(days=span_days)
if end <= birth:
cursor = end
continue
visible_start = birth if cursor < birth else cursor
row = {
'level': 'antardasha',
'planet': item['planet'],
'yogini': item['name'],
'lord': item['planet'],
'years': (end - visible_start).total_seconds() / (86400 * year_length),
'start_date': visible_start.isoformat(timespec='seconds'),
'end_date': end.isoformat(timespec='seconds'),
}
if cursor < birth:
row['unclipped_start_date'] = cursor.isoformat(timespec='seconds')
rows.append(row)
cursor = end
return rows
def _calculate_moon_balanced_yogini(birth_info):
"""Goel Table I order, angular birth balance, explicit fixed-day year."""
birth_dt = birth_info.get("birth_datetime")