Files
Jyotisha/scripts/cmd_narayana_dasha.py
T
ClaudeandClaude Opus 5.5 0404d0a07c fix(narayana): split into five named source profiles with per-step comparisons (BUG-1741..1743)
Astrologer round-5 ruling 1 (2026-11-08, B3/B4): seed, years, dual lord,
AD direction and start are separate named profiles (Sanjay Rath source
version). Each comparison profile is recomputed with one step swapped; the
step is disputed when the running MD/AD changes, blocked when the source
cannot decide. method_status names exactly those steps with her round-5
sentence; B3/B4 open item removed. Undecided years now block the layer.
The narayana-dasha CLI passes the birth moment. Engine values on the three
public charts are unchanged; Drig and rectification scoring unchanged.

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

150 lines
6.6 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.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Narayana Dasha 子命令
Jyotish Vedic Astrology Skill — v6.0.20
"""
import json
def cmd_narayana_dasha(args, chart_data):
"""
narayana-dasha 子命令:计算并报告 Narayana Dasha(Rishi Dasha)。
用法:
python jyotish_engine.py narayana-dasha --year 1935 --month 6 --day 21 \\
--hour 11 --minute 0 --lat 44.486 --lon 1.842 --tz 1 --age 33
"""
if chart_data is None:
return "\n".join([
"╔══════════════════════════════════════════╗",
"║ Narayana Dasha(Rishi Dasha) ║",
"╚══════════════════════════════════════════╝",
"",
"错误:图表数据未生成(swisseph 可能未安装)。",
"Narayana Dasha 需要完整的行星经度数据。",
])
from narayana_dasha import attach_narayana_method_comparison, narayana_dasha_full_report
planet_lons = {}
for pn, pd in chart_data.get('planets', {}).items():
if isinstance(pd, dict) and 'degree' in pd:
planet_lons[pn] = pd['degree']
asc_idx = chart_data.get('ascendant_index')
if asc_idx is None:
asc_info = chart_data.get('ascendant', {}) if isinstance(chart_data, dict) else {}
asc_idx = asc_info.get('sign_idx', 0)
if asc_idx == 0 and isinstance(asc_info, dict):
# compute_chart_data 输出 ascendant.sign,但不一定输出 sign_idx;兼容旧结构
sign_name = asc_info.get('sign')
signs = ['Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo',
'Libra', 'Scorpio', 'Sagittarius', 'Capricorn', 'Aquarius', 'Pisces']
if sign_name in signs:
asc_idx = signs.index(sign_name)
if isinstance(asc_idx, str):
asc_idx = int(asc_idx)
current_age = float(getattr(args, 'age', 0) or 0)
birth_year = getattr(args, 'year', 0) or 0
result = narayana_dasha_full_report(
lagna_sign_idx=asc_idx,
planet_lons=planet_lons,
current_age=current_age,
birth_year=birth_year,
)
attach_narayana_method_comparison(result, asc_idx, planet_lons, current_age, birth_year)
# BUG-1601 (#166 Q9): Sanjay Rath is the default and prints first; the
# legacy result follows, labelled comparison only.
from narayana_legacy_label import product_narayana
# 原值:不传出生时刻,Rath 行只有年龄、没有日期,起点步骤无法确认。
# 新值:用命令行的出生年月日时分作出生时刻(日期 = 出生时刻 + 年龄 × 365.25 天)。
# 原因:占星师 2026-11-08 第五轮裁定 1(e):起点是出生的实际时刻,不是出生日期。
try:
from datetime import datetime
birth_dt = datetime(int(args.year), int(args.month), int(args.day), int(args.hour), int(args.minute),
int(float(getattr(args, 'second', 0) or 0)))
except (AttributeError, TypeError, ValueError):
birth_dt = None
product = product_narayana(result, asc_idx, planet_lons, current_age=current_age, birth_year=birth_year,
birth_datetime=birth_dt)
rath = {key: value for key, value in product.items() if key != 'legacy'}
result = product['legacy']
# 格式化输出
lines = [
"╔══════════════════════════════════════════╗",
"║ Narayana Dasha(Rishi Dasha) ║",
"╚══════════════════════════════════════════╝",
"",
f"── {rath.get('algorithm_label')} ──",
]
if rath.get('seed_sign'):
lines.append(f" 起运宫: {rath['seed_sign']}(第 {rath.get('strength_level_decided')} 级:{rath.get('strength_level_text')});{rath.get('direction_text')}")
if rath.get('method_note'):
lines.append(f" {rath['method_note']}")
for p in rath.get('mahadasha', [])[:12]:
lines.append(f" {p['sign']:>12s} ({p['lord'] or '未决':>7s}): {p['years']:2d}年 [{p['start_age']:5.1f}→{p['end_age']:5.1f}]")
rcur = rath.get('current_dasha') or {}
if rcur.get('md'):
rmd = rcur['md']
lines.append(f" 当前大运: {rmd['sign']}({rmd['lord']}){rmd['years']}年")
if rcur.get('remaining_years') is not None:
lines.append(f" 剩余: {rcur['remaining_years']:.1f}年")
if rcur.get('ad'):
rad = rcur['ad']
lines.append(f" 当前小运: {rad['sign']}({rad['lord']})")
else:
lines.append(f" {rath.get('blocked_note') or rath.get('reason') or rath.get('status')}")
lines += [
"",
f"── 对照:{result['algorithm_label']} ──",
f"Lagna: {result['lagna_sign']}({result['lagna_sign_idx']})",
f"总周期: {result['total_cycle_years']} 年",
f"算法: {result['algorithm_note']}",
"",
"── 大运序列 ──",
]
for p in result['mahadasha_sequence']:
lines.append(
f" {p['sign']:>12s} ({p['lord']:>7s} in {p['lord_in_sign']:>12s}): "
f"{p['years']:2d}年 [{p['start_age']:5.1f}→{p['end_age']:5.1f}]"
)
curr = result.get('current_dasha', {})
md = curr.get('md')
if md:
lines.append("")
lines.append(f"── 当前大运(age={current_age:.1f})──")
lines.append(f" Mahadasha: {md['sign']}({md['lord']}){md['years']}年")
lines.append(f" 剩余: {curr.get('remaining_years', 0):.1f}年")
ad = curr.get('ad')
if ad:
lines.append(f" Antardasha: {ad['sign']}({ad['lord']}){ad['years']}年")
pd = curr.get('pd')
if pd:
lines.append(f" Pratyantardasha: {pd['sign']}({pd['lord']}){pd['years']}年")
lines.append("")
for line in result.get('interpretation', []):
lines.append(f" {line}")
source = (result.get('method_comparison') or {}).get('source_aware') or {}
if source:
lines.append("")
lines.append("── 来源对照 ──")
if source.get('status') == 'blocked':
lines.append(f" 来源算法:blocked({source.get('reason')})")
else:
seed = source.get('seed_selection') or {}
lines.append(f" 来源起运规则:{seed.get('profile')};起运星座:{seed.get('selected_sign')}")
return "\n".join(lines)