Files
Jyotisha/scripts/remedies.py
T
ClaudeandClaude Opus 5.5 9d7a17a1a5 fix: chat card, annual D2 and remedies follow the astrologer's second-batch rulings (BUG-1964)
Shadbala reads 达到 / 未达到最低线 (her item 9; owner agreed) and the card carries
min_required for the 判断依据 line; required_strength_ratio beside ishta_bala_pct;
remedies no longer trigger from Shadbala (unaccepted_threshold). Education uses D24,
not D5 (item 7). Vighati keeps its position only (item 1); the 64th Navamsa from the
Moon and Pranapada take part as auxiliary layers with her fields (items 2, 3). The
annual natal two-Hora D2 gives Hora membership instead of the lagna lord's house,
and its birth-time stability check compares that membership (item 8).

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

274 lines
11 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 -*-
"""
Remedies(补救措施)系统 v1.0
基于BPHS(Brihat Parashara Hora Shastra)经典补救体系
五大类补救:
1. Ratna (宝石) — 行星弱点修饰
2. Mantra (咒语) — 声音振动疗愈
3. Dana (捐赠) — 因果净化
4. Vrata (斋戒) — 身体净化
5. Yantra (护符) — 几何能量图案
输入:行星力量分析结果(Shadbala/Dignity/Dasha)
输出:针对性的补救建议
"""
from typing import Dict, List, Optional
PLANET_GEMS = {
'Sun': {'gem': '红宝石 (Ruby/Manikya)', 'metal': '金 (Gold)', 'finger': '无名指', 'day': '周日'},
'Moon': {'gem': '珍珠 (Pearl/Moti)', 'metal': '银 (Silver)', 'finger': '小指', 'day': '周一'},
'Mars': {'gem': '红珊瑚 (Red Coral/Moonga)', 'metal': '铜 (Copper)', 'finger': '无名指', 'day': '周二'},
'Mercury': {'gem': '祖母绿 (Emerald/Panna)', 'metal': '金 (Gold)', 'finger': '小指', 'day': '周三'},
'Jupiter': {'gem': '黄宝石 (Yellow Sapphire/Pukhraj)', 'metal': '金 (Gold)', 'finger': '食指', 'day': '周四'},
'Venus': {'gem': '钻石 (Diamond/Heera)', 'metal': '银/白金 (Silver/Platinum)', 'finger': '中指', 'day': '周五'},
'Saturn': {'gem': '蓝宝石 (Blue Sapphire/Neelam)', 'metal': '铁 (Iron)', 'finger': '中指', 'day': '周六'},
'Rahu': {'gem': '天河石 (Hessonite/Gomed)', 'metal': '混合金属 (Mixed)', 'finger': '中指', 'day': '周六'},
'Ketu': {'gem': '猫眼石 (Cat\'s Eye/Lahsuniya)', 'metal': '混合金属 (Mixed)', 'finger': '无名指', 'day': '周二'},
}
PLANET_MANTRAS = {
'Sun': 'Om Suryaya Namaha',
'Moon': 'Om Chandraya Namaha',
'Mars': 'Om Mangalaya Namaha',
'Mercury': 'Om Budhaya Namaha',
'Jupiter': 'Om Brihaspataye Namaha',
'Venus': 'Om Shukraya Namaha',
'Saturn': 'Om Shanaishcharaya Namaha',
'Rahu': 'Om Rahave Namaha',
'Ketu': 'Om Ketave Namaha',
}
PLANET_DONATIONS = {
'Sun': ['小麦(Wheat)', '红糖(Jaggery)', '红布', '铜器'],
'Moon': ['大米(Rice)', '牛奶', '银器', '白糖'],
'Mars': ['红扁豆(Masoor Dal)', '红布', '铜器', '珊瑚碎片'],
'Mercury': ['绿豆(Moong Dal)', '青色布', '文具', '书本'],
'Jupiter': ['鹰嘴豆(Chana Dal)', '黄布', '姜黄', '香蕉'],
'Venus': ['白米', '白布', '酥油(Ghee)', '银器'],
'Saturn': ['黑芝麻(Black Sesame)', '黑布', '铁器', '油灯'],
'Rahu': ['黑芥末(Black Mustard)', '蓝布', '铁器', '蓝宝石替代品'],
'Ketu': ['芝麻(Sesame)', '多色布', '灯笼', '猫眼石替代品'],
}
PLANET_FAST_DAYS = {
'Sun': '周日 (Sunday)', 'Moon': '周一 (Monday)',
'Mars': '周二 (Tuesday)', 'Mercury': '周三 (Wednesday)',
'Jupiter': '周四 (Thursday)', 'Venus': '周五 (Friday)',
'Saturn': '周六 (Saturday)', 'Rahu': '周六 (Saturday)',
'Ketu': '周二 (Tuesday)',
}
PLANET_COLORS = {
'Sun': '红/金/橙', 'Moon': '白/银/乳白', 'Mars': '红/珊瑚色',
'Mercury': '绿/浅绿', 'Jupiter': '黄/金色',
'Venus': '白/粉/彩虹', 'Saturn': '黑/深蓝/紫',
'Rahu': '深蓝/烟灰', 'Ketu': '斑点/多色',
}
STRENGTH_THRESHOLDS = {
'weak': 0.5, # Rupa < 0.5 → 极度需要补救
'moderate': 0.75, # 0.5-0.75 → 轻���补救
}
def recommend_remedies(shadbala_results: Dict, planet_dignities: Dict = None,
active_dasha_lord: str = None, doshas: List[str] = None) -> Dict:
"""
基于行星力量分析推荐补救措施。
Args:
shadbala_results: Shadbala结果 {planet: {'total_rupas': float, 'strength_level': str, ...}}
planet_dignities: 行星尊严 {planet: dignity_level}
active_dasha_lord: 当前大运主星
doshas: 检测到的Dosha列表 ['Mangal Dosha', 'Kaal Sarp Dosha', ...]
Returns:
分类的补救建议
"""
doshas = doshas or []
recommendations = {
'gems': [],
'mantras': [],
'donations': [],
'fasting': [],
'lifestyle': [],
'dosha_remedies': [],
}
# 分析需要补救的行星
weak_planets = []
moderate_planets = []
evidence_chain = []
# 原值: 合计低于 0.5 / 0.75 Rupa 的行星进 weak / moderate,触发宝石、咒语、捐赠、斋戒建议。
# 新值: Shadbala 不再触发任何补救;只在 evidence_chain 记一条 unaccepted_threshold。
# 原因: BUG-1964,占星师 2026-11-17 第二批第 9 项:0.5 / 0.75 Rupa 阈值没有来源,
# 不能因为样例没有触发就算已通过。阈值常量保留,供以后有来源时复核。
if shadbala_results:
evidence_chain.append({
'source': 'shadbala',
'status': 'unaccepted_threshold',
'thresholds': dict(STRENGTH_THRESHOLDS),
'reason': 'Shadbala 补救阈值没有来源,未获占星师准入,不据此给补救建议',
})
# 1. 宝石建议(仅对极弱行星)
for planet in weak_planets:
if planet in PLANET_GEMS:
g = PLANET_GEMS[planet]
recommendations['gems'].append({
'planet': planet,
'gem': g['gem'],
'metal': g['metal'],
'finger': g['finger'],
'day': g['day'],
'severity': 'high',
'note': f'{planet}极度虚弱,建议佩戴{g["gem"]}镶嵌于{g["metal"]},戴在{g["finger"]}上。首次佩戴应在{g["day"]}日出后。'
})
for planet in moderate_planets:
if planet in PLANET_GEMS:
g = PLANET_GEMS[planet]
recommendations['gems'].append({
'planet': planet,
'gem': g['gem'],
'metal': g['metal'],
'severity': 'medium',
'note': f'{planet}偏弱,可考虑佩戴{g["gem"]}作为辅助。'
})
# 2. 咒语建议
for planet in weak_planets + moderate_planets:
if planet in PLANET_MANTRAS:
recs = 108 if planet in weak_planets else 27
recommendations['mantras'].append({
'planet': planet,
'mantra': PLANET_MANTRAS[planet],
'repetitions': recs,
'note': f'每日念诵 {PLANET_MANTRAS[planet]} × {recs}遍',
})
# 3. 大运主星特别建议
if active_dasha_lord and active_dasha_lord in PLANET_MANTRAS:
recommendations['mantras'].append({
'planet': active_dasha_lord,
'mantra': PLANET_MANTRAS[active_dasha_lord],
'repetitions': 108,
'note': f'当前大运为{active_dasha_lord}期间,建议强化念诵 {PLANET_MANTRAS[active_dasha_lord]}',
'priority': 'dasha_lord',
})
evidence_chain.append({
'source': 'dasha',
'planet': active_dasha_lord,
'severity': 'context',
'reason': f'当前大运主星为{active_dasha_lord},补救优先级上调',
})
# 4. 捐赠建议
for planet in weak_planets[:3]: # Top 3 weakest
if planet in PLANET_DONATIONS:
items = ', '.join(PLANET_DONATIONS[planet][:2])
recommendations['donations'].append({
'planet': planet,
'items': PLANET_DONATIONS[planet],
'note': f'捐赠{planet}相关物品:{items}等。在{PLANET_FAST_DAYS.get(planet, "适当日子")}捐赠效果最佳。',
})
# 5. 斋戒建议
for planet in weak_planets[:2]:
recommendations['fasting'].append({
'planet': planet,
'day': PLANET_FAST_DAYS.get(planet, ''),
'note': f'在{PLANET_FAST_DAYS.get(planet)}进行{planet}斋戒,从日出到日落。',
})
# 6. Dosha专项补救
dosha_remedies_map = {
'Mangal Dosha': {
'actions': ['Kumbha Vivah (与无花果/香蕉树先"结婚"后再与人结婚)', 'Mangal Chandika Path', '周二火星斋戒'],
'gem': '红珊瑚 (Red Coral)',
},
'Kaal Sarp Dosha': {
'actions': ['Rahu-Ketu Shanti Puja', '那伽潘查米节祭拜蛇神', '参观12个Jyotirlinga'],
'gem': '天河石+猫眼石组合',
},
'Nadi Dosha': {
'actions': ['Nadi Shanti Puja', 'Mahamrityunjaya Mantra', '捐赠谷物'],
'gem': None,
},
'Pitra Dosha': {
'actions': ['Amavasya祖先祭拜', '捐赠黑芝麻和铁器', '供养婆罗门'],
'gem': None,
},
}
for dosha_name in doshas:
if dosha_name in dosha_remedies_map:
dr = dosha_remedies_map[dosha_name]
recommendations['dosha_remedies'].append({
'dosha': dosha_name,
'actions': dr['actions'],
'gem': dr.get('gem'),
'note': f'{dosha_name}检测到。建议进行: {"; ".join(dr["actions"][:2])}',
})
evidence_chain.append({
'source': 'dosha',
'dosha': dosha_name,
'severity': 'context',
'reason': f'{dosha_name}命中,生成专项补救建议',
})
# 7. 生活建议
colors = []
for planet in weak_planets[:3]:
if planet in PLANET_COLORS:
colors.append(PLANET_COLORS[planet])
if colors:
recommendations['lifestyle'].append({
'type': '色彩疗愈',
'note': f'多使用{", ".join(colors)}色系的衣物和装饰物',
})
if 'Saturn' in weak_planets:
recommendations['lifestyle'].append({
'type': '土星平和',
'note': '周六拜访Shani寺庙,提供芥末油灯。避免穿黑色。',
})
# 建议摘要
total_recs = sum(len(v) for v in recommendations.values())
summary = f'共{total_recs}条补救建议 — 重点关注: {", ".join(weak_planets[:3]) if weak_planets else "无极度虚弱行星"}'
next_action = (
'先执行咒语、捐赠、生活调整等低风险补救;宝石、斋戒和仪式类建议需结合体质、预算与专业意见二次确认。'
if total_recs else
'当前未发现必须补救的弱项,保持观察并等待Dasha/Transit触发再复核。'
)
return {
'method': 'BPHS补救系统 v1.0',
'weak_planets': weak_planets,
'moderate_planets': moderate_planets,
'recommendations': recommendations,
'evidence_chain': evidence_chain,
'next_action': next_action,
'summary': summary,
}
def quick_remedy(planet: str, severity: str = 'weak') -> Dict:
"""快速获取单行星补救建议"""
result = {}
if planet in PLANET_GEMS:
g = PLANET_GEMS[planet]
result['gem'] = f'{g["gem"]} 镶{g["metal"]} 戴{g["finger"]} ({g["day"]})'
if planet in PLANET_MANTRAS:
result['mantra'] = f'{PLANET_MANTRAS[planet]} × {"108" if severity == "weak" else "27"}'
if planet in PLANET_FAST_DAYS:
result['fast'] = f'{PLANET_FAST_DAYS[planet]} 斋戒'
if planet in PLANET_DONATIONS:
result['donate'] = ', '.join(PLANET_DONATIONS[planet][:2])
return result