#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Yogas / Doshas / Special Lagnas 计算模块 v6.0.14 支持: - Raj Yogas: 王者瑜伽(主星互涉形成权力格局) - Dhana Yogas: 财富瑜伽(2/11宫主与吉星组合) - Pancha Mahapurusha Yogas: 五王瑜伽(吉星在角宫入庙) - Neecha Bhanga Raj Yoga: 落陷解除王者瑜伽 - Mangal Dosha (Kuja Dosha): 火星煞(火星在1/2/4/7/8/12宫) - Kaal Sarp Dosha: 时间蛇煞(所有行星在Rahu-Ketu轴线一侧) - Pitra Dosha: 父辈煞(Sun与Rahu合相/受克) - Sade Sati: 土星七年(土星过Moon前后各1星座) - Arudha Lagna (AL): 镜像上升,取自 jaimini.calc_arudha_padas(单一来源) - Upapada Lagna (UL): 第12宫 Arudha,取自 jaimini.calc_arudha_padas(单一来源) """ from typing import Dict, List, Tuple, Optional SIGNS = ['Aries','Taurus','Gemini','Cancer','Leo','Virgo', 'Libra','Scorpio','Sagittarius','Capricorn','Aquarius','Pisces'] SIGN_LORDS = {'Aries':'Mars','Taurus':'Venus','Gemini':'Mercury','Cancer':'Moon', 'Leo':'Sun','Virgo':'Mercury','Libra':'Venus','Scorpio':'Mars', 'Sagittarius':'Jupiter','Capricorn':'Saturn','Aquarius':'Saturn','Pisces':'Jupiter'} # 吉星/凶星分类 NATURAL_BENEFICS = {'Jupiter', 'Venus', 'Mercury', 'Moon'} NATURAL_MALEFICS = {'Saturn', 'Mars', 'Sun', 'Rahu', 'Ketu'} # Chinese twins of the raj / dhana combination strings. ``combination`` keeps its # old text; the Chinese report reads ``combination_zh`` (BUG-1418). _PLANET_ZH = { 'Sun': '太阳', 'Moon': '月亮', 'Mars': '火星', 'Mercury': '水星', 'Jupiter': '木星', 'Venus': '金星', 'Saturn': '土星', 'Rahu': '罗睺', 'Ketu': '计都', } def _cn(planet) -> str: return _PLANET_ZH.get(str(planet), str(planet)) def _houses_cn(houses) -> str: if isinstance(houses, (list, tuple)): return '、'.join(str(house) for house in houses) return str(houses) def calc_raj_yogas(planets_data: Dict, houses: Dict) -> Dict: """ 计算 Raj Yogas(王者瑜伽)——权力、地位、社会影响力格局 v7.0 经典 Raj Yoga 形成条件: 1. 角宫主(1/4/7/10宫主)与三方宫主(5/9宫主)同宫(conjunction) 2. 角宫主与三方宫主互看(mutual aspect) 3. 角宫主与三方宫主互容(parivartana) 4. 同一星同时掌管角宫和三方宫(dual lordship) 5. Viparita Raja Yoga:凶宫主(6/8/12宫主)落入另一个凶宫 参考:dashaflow yoga.py (MIT) 返回:检测到的 Raj Yogas 列表 """ results = {'yogas': [], 'summary': ''} SIGNS_LIST = ['Aries','Taurus','Gemini','Cancer','Leo','Virgo', 'Libra','Scorpio','Sagittarius','Capricorn','Aquarius','Pisces'] # 提取宫主星信息 def _lord_of_house(house_num): """获取某宫的宫主星""" lkey = f'H{house_num}_Lord' if lkey in houses: return houses[lkey] # 从行星数据推断 asc_sign = houses.get('asc_sign', '') if asc_sign and asc_sign in SIGN_LORDS: asc_idx = SIGNS_LIST.index(asc_sign) if asc_sign in SIGNS_LIST else 0 sign_idx = (asc_idx + house_num - 1) % 12 return SIGN_LORDS[SIGNS_LIST[sign_idx]] return None def _get_planet_sign_idx(pname): """获取行星所在星座索引""" pdata = planets_data.get(pname, {}) if isinstance(pdata, dict) and 'sign' in pdata: sign = pdata['sign'] if sign in SIGNS_LIST: return SIGNS_LIST.index(sign) # 从经度推断 if isinstance(pdata, dict) and 'longitude' in pdata: return int(pdata['longitude'] / 30) % 12 return None def _get_planet_house(pname): """获取行星所在宫位""" pdata = planets_data.get(pname, {}) if isinstance(pdata, dict) and 'house' in pdata: return pdata['house'] return None # 检查每对宫主星的组合 kendras = [1, 4, 7, 10] # 角宫 trikonas = [1, 5, 9] # 三方宫(含1宫) dusthanas = [6, 8, 12] # 凶宫 # ── 条件4: 双重宫主星(同一星掌管角宫+三方宫)── kendra_lords = {} trikona_lords = {} for h in kendras: lord = _lord_of_house(h) if lord: kendra_lords.setdefault(lord, []).append(h) for h in trikonas: lord = _lord_of_house(h) if lord: trikona_lords.setdefault(lord, []).append(h) # Upstream e628118d: a dual lord rules two different houses. The lagna lord # alone (H1 is both kendra and trikona) is not one. dual_lords = {lord for lord in set(kendra_lords) & set(trikona_lords) if len(set(kendra_lords[lord]) | set(trikona_lords[lord])) > 1} for lord in dual_lords: k_houses = kendra_lords[lord] t_houses = trikona_lords[lord] lord_house = _get_planet_house(lord) if lord_house and lord_house in kendras + trikonas: yoga = { 'type': 'Raj Yoga', 'subtype': 'dual_lordship', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': [lord], 'combination': f'{lord}(H{k_houses}主+H{t_houses}主)', 'combination_zh': f'{_cn(lord)}同时是第{_houses_cn(k_houses)}宫主(角宫)与第{_houses_cn(t_houses)}宫主(三方宫)', 'formation_house': lord_house, 'strength': 'strong' if lord_house in kendras else 'moderate', 'interpretation': f'Raj Yoga——{lord}同时掌管角宫{k_houses}和三方宫{t_houses},且在{lord_house}宫,双重权力格局', } results['yogas'].append(yoga) # ── 条件1+2+3: 角宫主 × 三方宫主 的组合检测 ── pure_kendra_lords = set(kendra_lords.keys()) - dual_lords pure_trikona_lords = set(trikona_lords.keys()) - dual_lords for kl in sorted(pure_kendra_lords): for tl in sorted(pure_trikona_lords): if kl == tl: continue kl_sign = _get_planet_sign_idx(kl) tl_sign = _get_planet_sign_idx(tl) if kl_sign is None or tl_sign is None: continue # 条件1: 同宫(conjunction) if kl_sign == tl_sign: house_from_asc = (kl_sign - (SIGNS_LIST.index(houses.get('asc_sign', 'Aries')) if houses.get('asc_sign') in SIGNS_LIST else 0)) % 12 + 1 yoga = { 'type': 'Raj Yoga', 'subtype': 'conjunction', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': [kl, tl], 'combination': f'{kl}(角宫主) + {tl}(三方宫主)', 'combination_zh': f'角宫主{_cn(kl)}与三方宫主{_cn(tl)}同宫', 'formation_house': house_from_asc, 'strength': 'strong' if house_from_asc in kendras else 'moderate', 'interpretation': f'Raj Yoga——{kl}(角宫主)与{tl}(三方宫主)同宫在{SIGNS_LIST[kl_sign]},权力格局', } results['yogas'].append(yoga) # 条件2: 互看(mutual aspect: 7宫关系) elif abs(kl_sign - tl_sign) == 6 or abs(kl_sign - tl_sign) == 6 + 12: yoga = { 'type': 'Raj Yoga', 'subtype': 'mutual_aspect', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': [kl, tl], 'combination': f'{kl}(角宫主) ↔ {tl}(三方宫主)', 'combination_zh': f'角宫主{_cn(kl)}与三方宫主{_cn(tl)}对宫互视', 'interpretation': f'Raj Yoga——{kl}(角宫主)与{tl}(三方宫主)互看(对宫相位),权力格局', } results['yogas'].append(yoga) # 条件3: 互容(parivartana) else: # 检查kl是否在tl掌管的星座,且tl是否在kl掌管的星座 kl_lord_signs = [] # kl掌管的星座 tl_lord_signs = [] # tl掌管的星座 for s_idx, s_name in enumerate(SIGNS_LIST): if SIGN_LORDS[s_name] == kl: kl_lord_signs.append(s_idx) if SIGN_LORDS[s_name] == tl: tl_lord_signs.append(s_idx) if tl_sign in kl_lord_signs and kl_sign in tl_lord_signs: yoga = { 'type': 'Raj Yoga', 'subtype': 'parivartana', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': [kl, tl], 'combination': f'{kl}(角宫主) ⇄ {tl}(三方宫主)', 'combination_zh': f'角宫主{_cn(kl)}与三方宫主{_cn(tl)}互换星座', 'interpretation': f'Raj Yoga——{kl}(角宫主)与{tl}(三方宫主)互容交换,权力格局强化', } results['yogas'].append(yoga) # ── 条件5: Viparita Raja Yoga ── # 6/8/12宫主落入另一个凶宫(凶中凶=逆转大吉) dusthana_lords = {} for h in dusthanas: lord = _lord_of_house(h) if lord: dusthana_lords[h] = lord for h, lord in dusthana_lords.items(): lord_house = _get_planet_house(lord) if lord_house and lord_house in dusthanas and lord_house != h: yoga = { 'type': 'Viparita Raja Yoga', 'subtype': 'dusthana_in_dusthana', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': [lord], 'combination': f'H{h}_Lord({lord}) in H{lord_house}', 'combination_zh': f'{h}宫主{_cn(lord)}落第{lord_house}宫', 'interpretation': f'Viparita Raja Yoga——{h}宫主{lord}落入{lord_house}宫(凶中凶),先苦后甜逆转格局', } results['yogas'].append(yoga) results['summary'] = f"Raj Yoga检测:共{len(results['yogas'])}个格局" return results def calc_dhana_yogas(planets_data: Dict, houses: Dict) -> Dict: """ 计算 Dhana Yogas(财富瑜伽)——财富积累格局 v7.0 经典 Dhana Yoga 形成条件(参考dashaflow yoga.py MIT): 1. 2宫主+11宫主同在角宫/三方宫 2. 5宫主+9宫主同宫或互看 3. 2宫主+9宫主(财富+幸运)同宫/互看 4. 11宫主+9宫主(收益+幸运)同宫/互看 5. 2/11宫主与吉星(Jupiter/Venus)同宫 返回:检测到的 Dhana Yogas 列表 """ results = {'yogas': [], 'summary': ''} SIGNS_LIST = ['Aries','Taurus','Gemini','Cancer','Leo','Virgo', 'Libra','Scorpio','Sagittarius','Capricorn','Aquarius','Pisces'] KENDRA = {1, 4, 7, 10} TRIKONA = {1, 5, 9} GOOD_HOUSES = KENDRA | TRIKONA | {2, 11} BENEFICS = {'Jupiter', 'Venus'} def _lord_of_house(house_num): lkey = f'H{house_num}_Lord' if lkey in houses: return houses[lkey] asc_sign = houses.get('asc_sign', '') if asc_sign and asc_sign in SIGN_LORDS: asc_idx = SIGNS_LIST.index(asc_sign) if asc_sign in SIGNS_LIST else 0 sign_idx = (asc_idx + house_num - 1) % 12 return SIGN_LORDS[SIGNS_LIST[sign_idx]] return None def _get_planet_house(pname): pdata = planets_data.get(pname, {}) if isinstance(pdata, dict) and 'house' in pdata: return pdata['house'] return None def _get_planet_sign(pname): pdata = planets_data.get(pname, {}) if isinstance(pdata, dict) and 'sign' in pdata: return pdata['sign'] return None def _same_sign(p1, p2): s1 = _get_planet_sign(p1) s2 = _get_planet_sign(p2) return s1 and s2 and s1 == s2 # ── 条件1: 2宫主+11宫主同在角宫/三方宫 ── lord_2 = _lord_of_house(2) lord_11 = _lord_of_house(11) if lord_2 and lord_11: h2 = _get_planet_house(lord_2) h11 = _get_planet_house(lord_11) if h2 and h11 and h2 in GOOD_HOUSES and h11 in GOOD_HOUSES: results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': '2nd_11th_lords_strong', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': list(dict.fromkeys([lord_2, lord_11])), 'combination': f'H2_Lord({lord_2}) in H{h2} + H11_Lord({lord_11}) in H{h11}', 'combination_zh': f'2宫主{_cn(lord_2)}落第{h2}宫,11宫主{_cn(lord_11)}落第{h11}宫', 'strength': 'strong' if h2 in KENDRA and h11 in KENDRA else 'moderate', 'interpretation': f'Dhana Yoga——2宫主{lord_2}(H{h2})与11宫主{lord_11}(H{h11})均落强宫,财富积累格局', }) # ── 条件2: 5宫主+9宫主同宫/互看 ── lord_5 = _lord_of_house(5) lord_9 = _lord_of_house(9) if lord_5 and lord_9: if _same_sign(lord_5, lord_9): s = _get_planet_sign(lord_5) results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': '5th_9th_conjunction', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': list(dict.fromkeys([lord_5, lord_9])), 'combination': f'H5_Lord({lord_5}) + H9_Lord({lord_9})', 'combination_zh': f'5宫主{_cn(lord_5)}与9宫主{_cn(lord_9)}同宫', 'strength': 'strong', 'interpretation': f'Dhana Yoga——5宫主{lord_5}与9宫主{lord_9}同宫在{s},财富+幸运格局', }) else: h5 = _get_planet_house(lord_5) h9 = _get_planet_house(lord_9) if h5 and h9: # 互看: 7宫关系 if abs(h5 - h9) == 6: results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': '5th_9th_mutual_aspect', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': list(dict.fromkeys([lord_5, lord_9])), 'combination': f'H5_Lord({lord_5}) ↔ H9_Lord({lord_9})', 'combination_zh': f'5宫主{_cn(lord_5)}与9宫主{_cn(lord_9)}对宫互视', 'strength': 'moderate', 'interpretation': f'Dhana Yoga——5宫主{lord_5}(H{h5})与9宫主{lord_9}(H{h9})互看,财富格局', }) # 同在角宫/三方宫 elif h5 in GOOD_HOUSES and h9 in GOOD_HOUSES: results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': '5th_9th_strong_houses', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': list(dict.fromkeys([lord_5, lord_9])), 'combination': f'H5_Lord({lord_5}) in H{h5} + H9_Lord({lord_9}) in H{h9}', 'combination_zh': f'5宫主{_cn(lord_5)}落第{h5}宫,9宫主{_cn(lord_9)}落第{h9}宫', 'strength': 'moderate', 'interpretation': f'Dhana Yoga——5宫主{lord_5}与9宫主{lord_9}均落强宫,财富格局', }) # ── 条件3: 2宫主+9宫主同宫/互看 ── if lord_2 and lord_9: if _same_sign(lord_2, lord_9): s = _get_planet_sign(lord_2) results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': '2nd_9th_conjunction', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': list(dict.fromkeys([lord_2, lord_9])), 'combination': f'H2_Lord({lord_2}) + H9_Lord({lord_9})', 'combination_zh': f'2宫主{_cn(lord_2)}与9宫主{_cn(lord_9)}同宫', 'strength': 'strong', 'interpretation': f'Dhana Yoga——2宫主{lord_2}与9宫主{lord_9}同宫在{s},财富+幸运组合', }) # ── 条件4: 11宫主+9宫主同宫/互看 ── if lord_11 and lord_9: if _same_sign(lord_11, lord_9): s = _get_planet_sign(lord_11) results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': '11th_9th_conjunction', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': list(dict.fromkeys([lord_11, lord_9])), 'combination': f'H11_Lord({lord_11}) + H9_Lord({lord_9})', 'combination_zh': f'11宫主{_cn(lord_11)}与9宫主{_cn(lord_9)}同宫', 'strength': 'strong', 'interpretation': f'Dhana Yoga——11宫主{lord_11}与9宫主{lord_9}同宫在{s},收益+幸运组合', }) # ── 条件5: 2/11宫主与吉星同宫 ── for wealth_lord, w_house in [(lord_2, 2), (lord_11, 11)]: if not wealth_lord: continue for benefic in BENEFICS: if _same_sign(wealth_lord, benefic): s = _get_planet_sign(wealth_lord) results['yogas'].append({ 'type': 'Dhana Yoga', 'subtype': f'{w_house}th_lord_benefic_conjunction', # BUG-2295: participants recorded where the yoga is computed (upstream f41efc51). 'planets': [wealth_lord, benefic], 'combination': f'H{w_house}_Lord({wealth_lord}) + {benefic}', 'combination_zh': f'{w_house}宫主{_cn(wealth_lord)}与{_cn(benefic)}同宫', 'strength': 'moderate', 'interpretation': f'Dhana Yoga——{w_house}宫主{wealth_lord}与吉星{benefic}同宫在{s},财富助力格局', }) results['summary'] = f"Dhana Yoga检测:共{len(results['yogas'])}个格局" return results def calc_pancha_mahapurusha_yoga(planets_data: Dict) -> Dict: """ 计算 Pancha Mahapurusha Yogas(五王瑜伽) 条件:5颗吉星(Mars/Mercury/Jupiter/Venus/Saturn)在角宫(1/4/7/10) 且入庙(在自家星座)或擢升(在擢升星座) 5种瑜伽: - Ruchaka Yoga: Mars在角宫入庙/擢升 - Bhadra Yoga: Mercury在角宫入庙/擢升 - Hamsa Yoga: Jupiter在角宫入庙/擢升 - Malavya Yoga: Venus在角宫入庙/擢升 - Sasa Yoga: Saturn在角宫入庙/擢升 """ results = {'yogas': [], 'summary': ''} # 擢升星座表 exaltation = {'Mars': 'Capricorn', 'Mercury': 'Virgo', 'Jupiter': 'Cancer', 'Venus': 'Pisces', 'Saturn': 'Libra'} # 入庙星座表 own_sign = {'Mars': ['Aries', 'Scorpio'], 'Mercury': ['Gemini', 'Virgo'], 'Jupiter': ['Sagittarius', 'Pisces'], 'Venus': ['Taurus', 'Libra'], 'Saturn': ['Capricorn', 'Aquarius']} for pname in ['Mars', 'Mercury', 'Jupiter', 'Venus', 'Saturn']: pdata = planets_data.get(pname, {}) if not isinstance(pdata, dict) or 'house' not in pdata: continue house = pdata['house'] sign = pdata.get('sign', '') # 检查是否在角宫 if house not in [1, 4, 7, 10]: continue # 检查是否入庙或擢升 is_exalted = (sign == exaltation.get(pname, '')) is_own = (sign in own_sign.get(pname, [])) if is_exalted or is_own: yoga_names = { 'Mars': 'Ruchaka Yoga', 'Mercury': 'Bhadra Yoga', 'Jupiter': 'Hamsa Yoga', 'Venus': 'Malavya Yoga', 'Saturn': 'Sasa Yoga', } yoga = { 'type': yoga_names[pname], 'planet': pname, 'house': house, 'sign': sign, 'status': 'exalted' if is_exalted else 'own_sign', 'strength': 'very strong' if is_exalted else 'strong', 'interpretation': f'{yoga_names[pname]}——{pname}在{house}宫{sign}({"擢升" if is_exalted else "入庙"}),五王瑜伽之一', } results['yogas'].append(yoga) results['summary'] = f"Pancha Mahapurusha Yoga检测:共{len(results['yogas'])}个(最多5个)" return results # BUG-2012(占星师 2026-11-19 上线前答复第 1、2、3、12 条):落陷取消只有一条默认的具名规则 # `light_on_life_p295`,行星状态标签(jyotish_engine._neecha_bhanga_evidence)和主检测器 # (main_yoga_detectors.neecha_bhanga_rows)都读下面这一个函数的结果。写法照她上游 # `YogaEngine._eval_neecha_bhanga`(yinduzhanxing ea2a9d65): # 1. 落陷星座主星在上升或月亮起角宫; # 2. 该星入旺星座的主星在上升或月亮起角宫; # 3. 落陷星座主星照射落陷星; # 4. 会在该落陷星座入旺的行星在上升或月亮起角宫。 # 互换是单列的变体(exchange_variant);D9 入庙 / 入旺、落陷星座主星入旺、会在该星座入旺的行星 # 与落陷星同座,来源待核,记为 unverified_variant。变体只列出,不让默认规则成立。 # 原值:主检测器按 A–F(含互换、D9)任一成立即算成立;标签按另一套四条(含两条待核)独立判断。 # BUG-2027(占星师 2026-11-19 对第 17 问的答复):两类「自我参照」分开记,不一律处理。 # - witness_is_reference:见证星就是参照点本身,即「月亮在月亮起第 1 宫」。这一条对任何星盘都成立, # 不区分星盘;落陷的木星(擢升星主是月亮)和火星(落陷星座主星是月亮)永远命中它。 # - witness_is_debilitated_planet:见证星就是落陷星自己(水星是自己入旺星座处女的主星)。它相对上升 # 或月亮是否在角宫并非恒成立,是实际的位置条件,照常计入,只做标记。 # 产品解释政策 `neecha_bhanga_policy_v1`(不是《Light on Life》原文的要求,原书该段没有写这个例外; # 原始规则版本仍是 light_on_life_p295):只有恒真条件命中时,默认标签仍是「落陷」,不出落陷取消行、 # 不出取消关系、不升级为任何 Raja Yoga 候选;原始命中、来源和标记留在证据里(raw_rule_met、 # tautology_only、literal_only)。恒真条件与其它有效条件同时命中时照列,但不增加支持强度和条数。 # 原值:default_rule_met = bool(conditions),恒真条件单独命中也算成立(81 张公开盘 10 颗落陷木星、 # 15 颗落陷火星全部成立)。 # 新值:default_rule_met 只看非恒真条件;raw_rule_met 保留字面命中。 NEECHA_BHANGA_DEFAULT_PROFILE = 'light_on_life_p295' NEECHA_BHANGA_POLICY = 'neecha_bhanga_policy_v1' NEECHA_BHANGA_LITERAL_ONLY_NOTE_ZH = '仅命中字面自我参照条件(月亮在月亮起第 1 宫),取消未确认' NEECHA_BHANGA_LITERAL_ONLY_NOTE_EN = ('Only the literal self-reference condition (the Moon in the 1st from the Moon) ' 'is hit; the cancellation is not confirmed') NEECHA_BHANGA_EXCHANGE_PROFILE = 'exchange_variant' NEECHA_BHANGA_UNVERIFIED_PROFILE = 'unverified_variant' NEECHA_BHANGA_VARIANT_NOTE_ZH = '默认规则未满足;另一具名规则满足某项条件,存在方法差异' NEECHA_BHANGA_VARIANT_NOTE_EN = 'The default rule is not met; a condition of another named rule holds, so the methods differ' _NB_SIGNS = ['Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo', 'Libra', 'Scorpio', 'Sagittarius', 'Capricorn', 'Aquarius', 'Pisces'] _NB_DEBILITATION = {'Mars': 'Cancer', 'Mercury': 'Pisces', 'Jupiter': 'Capricorn', 'Venus': 'Virgo', 'Saturn': 'Aries', 'Sun': 'Libra', 'Moon': 'Scorpio'} _NB_EXALTATION = {'Sun': 'Aries', 'Moon': 'Taurus', 'Mars': 'Capricorn', 'Mercury': 'Virgo', 'Jupiter': 'Cancer', 'Venus': 'Pisces', 'Saturn': 'Libra'} _NB_KENDRA = (1, 4, 7, 10) _NB_ASPECTS = {'Mars': (4, 7, 8), 'Jupiter': (5, 7, 9), 'Saturn': (3, 7, 10)} # (角色, 上升起角宫的代码, 月亮起角宫的代码)。A–D 是原有代码;G、H 是第 4 类。 _NB_KENDRA_ROLES = (('dispositor', 'A', 'B'), ('exaltation_sign_lord', 'C', 'D'), ('planet_exalted_in_debility_sign', 'G', 'H')) def neecha_bhanga_assessment(planet: str, sign: Optional[str], planets_data: Optional[Dict]) -> Dict: """One Neecha Bhanga verdict for one debilitated planet (see the note above). `planets_data` rows need `sign`; `house` (from the Lagna) and `navamsa_sign` are used when present. A missing position never supplies a witness. """ out = { 'planet': planet, 'debilitated_sign': sign, 'profile': NEECHA_BHANGA_DEFAULT_PROFILE, 'policy': NEECHA_BHANGA_POLICY, 'default_rule_met': False, 'raw_rule_met': False, 'tautology_only': False, 'conditions': [], 'variant_conditions': [], 'status': 'executed', } if not isinstance(planets_data, dict) or not planets_data: out['status'] = 'blocked_missing_planets' return out if sign not in _NB_SIGNS or _NB_DEBILITATION.get(planet) != sign: out['status'] = 'not_debilitated' return out def _row(name): row = planets_data.get(name) return row if isinstance(row, dict) else {} def _sign(name): value = _row(name).get('sign') return value if value in _NB_SIGNS else None def _house(name): value = _row(name).get('house') return value if isinstance(value, int) and not isinstance(value, bool) else None def _from_moon(name): moon, other = _sign('Moon'), _sign(name) if moon is None or other is None: return None return (_NB_SIGNS.index(other) - _NB_SIGNS.index(moon)) % 12 + 1 def _kendra(code, role, name, frame, house): reference = 'Moon' if frame == 'moon' else 'Lagna' # self_reference 是旧字段名,含义与 witness_is_reference 相同,保留给已有读者。 witness = {'code': code, 'condition': f'{role}_kendra_from_{frame}', 'planet': name, 'frame': frame, 'house': house, 'reference': reference, 'relative_house': house, 'self_reference': name == reference, 'witness_is_reference': name == reference, 'witness_is_debilitated_planet': name == planet, 'profile': NEECHA_BHANGA_DEFAULT_PROFILE} if witness['witness_is_reference']: witness['independent_confirmation_allowed'] = False return witness dispositor = SIGN_LORDS.get(sign) exaltation_sign = _NB_EXALTATION.get(planet) exaltation_lord = SIGN_LORDS.get(exaltation_sign) if exaltation_sign else None exalted_here = next((name for name, ex in _NB_EXALTATION.items() if ex == sign), None) others = {'dispositor': dispositor, 'exaltation_sign_lord': exaltation_lord, 'planet_exalted_in_debility_sign': exalted_here} conditions = out['conditions'] for role, lagna_code, moon_code in _NB_KENDRA_ROLES: other = others[role] if not other or other not in planets_data: continue house = _house(other) if house in _NB_KENDRA: conditions.append(_kendra(lagna_code, role, other, 'lagna', house)) relative = _from_moon(other) if relative in _NB_KENDRA: conditions.append(_kendra(moon_code, role, other, 'moon', relative)) dispositor_sign = _sign(dispositor) if dispositor else None if dispositor_sign is not None: distance = (_NB_SIGNS.index(sign) - _NB_SIGNS.index(dispositor_sign)) % 12 + 1 if distance in _NB_ASPECTS.get(dispositor, (7,)): conditions.append({'code': 'I', 'condition': 'dispositor_aspect', 'planet': dispositor, 'aspect_distance': distance, 'self_reference': False, 'witness_is_reference': False, 'witness_is_debilitated_planet': False, 'profile': NEECHA_BHANGA_DEFAULT_PROFILE}) out['raw_rule_met'] = bool(conditions) out['default_rule_met'] = any(not cond.get('witness_is_reference') for cond in conditions) out['tautology_only'] = out['raw_rule_met'] and not out['default_rule_met'] variants = out['variant_conditions'] if dispositor and dispositor != planet and dispositor_sign is not None \ and SIGN_LORDS.get(dispositor_sign) == planet: variants.append({'code': 'E', 'condition': 'dispositor_exchange', 'planet': dispositor, 'self_reference': False, 'profile': NEECHA_BHANGA_EXCHANGE_PROFILE}) navamsa_sign = _row(planet).get('navamsa_sign') if navamsa_sign and (SIGN_LORDS.get(navamsa_sign) == planet or navamsa_sign == exaltation_sign): variants.append({'code': 'F', 'condition': 'navamsa_own_or_exalted', 'planet': planet, 'sign': navamsa_sign, 'self_reference': False, 'profile': NEECHA_BHANGA_UNVERIFIED_PROFILE}) if dispositor and dispositor_sign is not None and _NB_EXALTATION.get(dispositor) == dispositor_sign: variants.append({'code': 'J', 'condition': 'dispositor_exalted', 'planet': dispositor, 'sign': dispositor_sign, 'self_reference': False, 'profile': NEECHA_BHANGA_UNVERIFIED_PROFILE}) if exalted_here and _sign(exalted_here) == sign: variants.append({'code': 'K', 'condition': 'exaltation_lord_conjunct_debilitation_sign', 'planet': exalted_here, 'sign': sign, 'self_reference': False, 'profile': NEECHA_BHANGA_UNVERIFIED_PROFILE}) return out def _nb_reason_zh(cond: Dict, planet: str) -> str: code, other, house = cond.get('code'), cond.get('planet'), cond.get('house') frame = 'Lagna' if cond.get('frame') == 'lagna' else 'Moon' if code in ('A', 'B'): return f'定位星{other}在{frame}第{house}宫(角宫)' if code in ('C', 'D'): return f'擢升星主{other}在{frame}第{house}宫(角宫)' if code in ('G', 'H'): return f'在该星座入旺的{other}在{frame}第{house}宫(角宫)' if code == 'I': return f'定位星{other}照射{planet}' if code == 'E': return f'{planet}与{other}互容(Parivartana)' if code == 'F': return f'{planet}在Navamsa中入庙/擢升({cond.get("sign")})' if code == 'J': return f'定位星{other}入旺({cond.get("sign")})' if code == 'K': return f'在该星座入旺的{other}与{planet}同座' return str(cond) def calc_nicha_bhanga_raj_yoga(planets_data: Dict, houses: Dict) -> Dict: """ 计算 Neecha Bhanga(落陷取消)条件清单 占星师定稿 2026-10-03 乙14(BUG-1205):只列出成立的取消条件,不自动称为 Raja Yoga(王者格局)。函数名与结果键 `nicha_bhanga_raj` 是旧调用面,保留。 BUG-2012(占星师 2026-11-19):`yogas` 只收默认规则 `light_on_life_p295` 成立的落陷星 (条件见 `neecha_bhanga_assessment`);只有变体条件成立的落陷星另列在 `variant_only`, 写明「默认规则未满足;另一具名规则满足某项条件,存在方法差异」,不算成立。 BUG-2027(占星师 2026-11-19 第 17 问):只命中恒真条件(月亮在月亮起第 1 宫)的落陷星不进 `yogas`,另列在 `literal_only`,只作后台证据;`yogas` 里的条目 `self_reference_only` 恒为 False。 每条成立的条件同时写进 `cancellation_reasons`(中文)与 `cancellation_conditions`(结构化:code / planet / frame / house / sign), 供卡片与报告按同一份条件来源渲染。 """ results = {'yogas': [], 'variant_only': [], 'literal_only': [], 'summary': ''} if not isinstance(planets_data, dict): results['summary'] = '落陷取消(Neecha Bhanga)条件检测:共0个' return results for pname, deb_sign in _NB_DEBILITATION.items(): pdata = planets_data.get(pname, {}) if not isinstance(pdata, dict) or pdata.get('sign') != deb_sign: continue # 没落陷 verdict = neecha_bhanga_assessment(pname, deb_sign, planets_data) cancel_conditions = verdict['conditions'] variant_conditions = verdict['variant_conditions'] deb_lord = SIGN_LORDS.get(deb_sign, '') exalt_sign = _NB_EXALTATION.get(pname, '') base = { 'type': 'Neecha Bhanga', 'planet': pname, 'debilitated_sign': deb_sign, 'debility_lord': deb_lord, 'lord_house': (planets_data.get(deb_lord) or {}).get('house') if isinstance(planets_data.get(deb_lord), dict) else None, 'exaltation_sign': exalt_sign, 'exaltation_lord': SIGN_LORDS.get(exalt_sign, ''), 'profile': NEECHA_BHANGA_DEFAULT_PROFILE, 'policy': NEECHA_BHANGA_POLICY, 'default_rule_met': verdict['default_rule_met'], 'raw_rule_met': verdict['raw_rule_met'], 'variant_conditions': variant_conditions, 'variant_reasons': [_nb_reason_zh(cond, pname) for cond in variant_conditions], } if verdict['default_rule_met']: cancel_reasons = [_nb_reason_zh(cond, pname) for cond in cancel_conditions] # 原值:strength 按全部成立条件条数(含月亮自参照)分档。 # 新值:自参照分支照原文保留、仍算「成立」,但不计入强度档(independent_count)。 # 原因:占星师 2026-11-08 第六轮 R3:自参照不能多算一票,不能据此提升排序、强度或置信度。 independent_count = sum(1 for c in cancel_conditions if not c.get('witness_is_reference')) strength = 'very strong' if independent_count >= 3 else 'strong' if independent_count >= 2 else 'moderate' results['yogas'].append({ **base, 'cancellation_reasons': cancel_reasons, 'cancellation_conditions': cancel_conditions, 'cancellation_count': len(cancel_reasons), 'independent_cancellation_count': independent_count, # BUG-2027:只有恒真条件的落陷星不再进这里,所以这一项恒为 False;字段留给已有读者。 'self_reference_only': False, 'self_witness': any(c.get('witness_is_debilitated_planet') for c in cancel_conditions), 'strength': strength, # BUG-2027:对读者列出的成立条件只收实际有效的;恒真条件留在 cancellation_conditions 里作原始证据。 'effective_conditions': [c for c in cancel_conditions if not c.get('witness_is_reference')], 'interpretation': '落陷取消(Neecha Bhanga)——{}在{}落陷,成立条件:{}'.format( pname, deb_sign, '; '.join(_nb_reason_zh(c, pname) for c in cancel_conditions if not c.get('witness_is_reference'))), }) elif verdict['tautology_only']: # 后台证据,不是成立的条目:没有行、没有取消关系,也不作任何 Raja Yoga 候选的依据。 results['literal_only'].append({ **base, 'tautology_only': True, 'literal_conditions': cancel_conditions, 'literal_reasons': [_nb_reason_zh(cond, pname) for cond in cancel_conditions], 'royal_yoga_candidate_allowed': False, 'note': NEECHA_BHANGA_LITERAL_ONLY_NOTE_ZH, 'note_en': NEECHA_BHANGA_LITERAL_ONLY_NOTE_EN, }) elif variant_conditions: results['variant_only'].append({ **base, 'note': NEECHA_BHANGA_VARIANT_NOTE_ZH, 'note_en': NEECHA_BHANGA_VARIANT_NOTE_EN, 'interpretation': f'{pname}在{deb_sign}落陷,{NEECHA_BHANGA_VARIANT_NOTE_ZH}:{"; ".join(base["variant_reasons"])}', }) results['summary'] = f"落陷取消(Neecha Bhanga)条件检测:共{len(results['yogas'])}个" return results def calc_mangal_dosha(planets_data: Dict, mars_house: int) -> Dict: """ 计算 Mangal Dosha / Kuja Dosha(火星煞) 规则:Mars在1/2/4/7/8/12宫 → Mangal Dosha 影响:婚姻延迟/困难,配偶健康 issues 缓和条件: - Mars在自身星座(Aries/Scorpio)→ 部分缓和 - Mars擢升(Capricorn)→ 完全解除 - 第七宫/第七宫主有吉星→ 部分缓和 - 双鱼/巨蟹上升 → 更麻烦(Mars在这些星座更凶) """ # BUG-2154 (占星师 2026-11-22 §3): the dosha table row and the canonical yoga rule # kalatra_dosha_mars_1_4_7_8_12 read one Mars fact; both carry this identity so a consumer # counts it once. Reference point = Lagna, chart = D1 (mars_house is counted from the Lagna). results = {'has_dosha': False, 'severity': 'none', 'remedies': [], 'evidence_identity': 'ev:mars_marriage_screen@D1:lagna', 'canonical_rule_id': 'kalatra_dosha_mars_1_4_7_8_12'} bad_houses = [1, 2, 4, 7, 8, 12] if mars_house not in bad_houses: results['summary'] = '无Mangal Dosha(Mars不在煞宫)' results['summary_en'] = 'No Mangal Dosha (Mars is not in a dosha house)' return results results['has_dosha'] = True mars_data = planets_data.get('Mars', {}) mars_sign = mars_data.get('sign', '') if isinstance(mars_data, dict) else '' # 判断严重程度 if mars_house in [7, 8]: results['severity'] = 'high' # 7/8宫最凶 elif mars_house in [1, 2]: results['severity'] = 'moderate' else: results['severity'] = 'low' # 检查缓和条件 remedies = [] if mars_sign in ['Aries', 'Scorpio']: remedies.append('Mars在自身星座,部分缓和') results['severity'] = 'moderate' if results['severity'] == 'high' else 'low' if mars_sign == 'Capricorn': remedies.append('Mars擢升,完全解除') results['severity'] = 'none' results['has_dosha'] = False results['remedies'] = remedies results['mars_house'] = mars_house results['mars_sign'] = mars_sign results['summary'] = (f"{'无' if not results['has_dosha'] else '有'}Mangal Dosha——" f"Mars在{mars_house}宫{mars_sign},严重程度:{results['severity']}") present = 'No' if not results['has_dosha'] else 'Present' results['summary_en'] = ( f"{present} Mangal Dosha — Mars in house {mars_house}, {mars_sign}; severity: {results['severity']}" ) return results def calc_kaal_sarp_dosha(planets_data: Dict) -> Dict: """ 计算 Kaal Sarp Dosha(时间蛇煞) 规则:所有行星(除Rahu/Ketu外)都在Rahu-Ketu轴线的同一侧 形成"蛇吞"格局,带来阻碍、延迟、心理压力 类型: - 完全Kaal Sarp:所有行星在Rahu-Ketu之间(单一侧) - 部分Kaal Sarp:大部分行星在Rahu-Ketu之间 """ results = {'has_dosha': False, 'type': 'none', 'affected_houses': []} rahu_data = planets_data.get('Rahu', {}) ketu_data = planets_data.get('Ketu', {}) if not isinstance(rahu_data, dict) or 'house' not in rahu_data: results['summary'] = 'Rahu位置未知,无法判断Kaal Sarp Dosha' results['summary_en'] = 'Rahu position unknown; Kaal Sarp Dosha cannot be judged' return results rahu_house = rahu_data['house'] ketu_house = ketu_data.get('house', 0) if isinstance(ketu_data, dict) else 0 # 确定Rahu-Ketu轴线的"之间"范围 # 简化处理:假设Rahu-Ketu在一条直线上(相差6宫) axis_houses = list(range(rahu_house, rahu_house + 6)) axis_houses = [(h - 1) % 12 + 1 for h in axis_houses] # 转为1-12 # 统计在"之间"的行星数量 planets_in_axis = [] planets_outside = [] for pname in ['Sun', 'Moon', 'Mars', 'Mercury', 'Jupiter', 'Venus', 'Saturn']: pdata = planets_data.get(pname, {}) if not isinstance(pdata, dict) or 'house' not in pdata: continue p_house = pdata['house'] if p_house in axis_houses: planets_in_axis.append(pname) else: planets_outside.append(pname) total_planets = len(planets_in_axis) + len(planets_outside) if len(planets_in_axis) == total_planets and total_planets >= 7: results['has_dosha'] = True results['type'] = 'full' results['summary'] = f'完全Kaal Sarp Dosha——所有{total_planets}颗行星在Rahu({rahu_house})—Ketu轴线之间' results['summary_en'] = ( f'Full Kaal Sarp Dosha — all {total_planets} planets lie between the Rahu ({rahu_house})-Ketu axis' ) elif len(planets_in_axis) >= total_planets * 0.7: results['has_dosha'] = True results['type'] = 'partial' results['summary'] = f'部分Kaal Sarp Dosha——{len(planets_in_axis)}/{total_planets}颗行星在轴线之间' results['summary_en'] = ( f'Partial Kaal Sarp Dosha — {len(planets_in_axis)} of {total_planets} planets lie between the axis' ) else: results['has_dosha'] = False results['type'] = 'none' results['summary'] = '无Kaal Sarp Dosha' results['summary_en'] = 'No Kaal Sarp Dosha' results['planets_in_axis'] = planets_in_axis results['planets_outside'] = planets_outside results['rahu_house'] = rahu_house results['ketu_house'] = ketu_house return results def calc_pitra_dosha(planets_data: Dict, sun_house: int) -> Dict: """ 计算 Pitra Dosha(父辈煞) 规则: - Sun与Rahu合相(同宫或相邻宫)→ Pitra Dosha - Sun受土星/火星克 → 可能Pitra Dosha - 第9宫/第9宫主受克 → 父辈煞 影响:父辈业力、祖先未解问题、子女健康/生育问题 """ results = {'has_dosha': False, 'indicators': [], 'indicators_en': []} sun_data = planets_data.get('Sun', {}) rahu_data = planets_data.get('Rahu', {}) if not isinstance(sun_data, dict) or 'house' not in sun_data: results['summary'] = 'Sun位置未知,无法判断Pitra Dosha' results['summary_en'] = 'Sun position unknown; Pitra Dosha cannot be judged' return results sun_house = sun_data['house'] sun_sign = sun_data.get('sign', '') # 检查Sun-Rahu合相 if isinstance(rahu_data, dict) and 'house' in rahu_data: rahu_house = rahu_data['house'] if abs(sun_house - rahu_house) <= 1 or (sun_house == rahu_house): results['has_dosha'] = True results['indicators'].append(f'Sun({sun_house}宫)与Rahu({rahu_house}宫)合相/相邻') results['indicators_en'].append( f'Sun (house {sun_house}) conjunct or adjacent to Rahu (house {rahu_house})' ) # 检查Sun受克(土星/火星在Sun宫或相邻宫) for malefic in ['Saturn', 'Mars']: mdata = planets_data.get(malefic, {}) if isinstance(mdata, dict) and 'house' in mdata: m_house = mdata['house'] if abs(sun_house - m_house) <= 1: results['has_dosha'] = True results['indicators'].append(f'{malefic}({m_house}宫)克Sun({sun_house}宫)') results['indicators_en'].append( f'{malefic} (house {m_house}) afflicts Sun (house {sun_house})' ) results['sun_house'] = sun_house results['sun_sign'] = sun_sign if not results['indicators']: results['summary'] = '无Pitra Dosha明显迹象' results['summary_en'] = 'No clear indication of Pitra Dosha' else: results['summary'] = f'有Pitra Dosha迹象:{"; ".join(results["indicators"][:2])}' results['summary_en'] = 'Indications of Pitra Dosha: ' + '; '.join(results['indicators_en'][:2]) return results def calc_sade_sati(moon_sign: str, current_year: int = 2026, *, transit_saturn_sign: str = None, reference_date: str = None) -> Dict: """ 计算 Sade Sati(土星七年) 规则:土星过Moon所在星座及其前后各1星座,共约7.5年 每个阶段影响不同: - 第一阶段(土星过前一星座):心理压力开始 - 第二阶段(土星过Moon星座):最困难,健康/关系/事业挑战 - 第三阶段(土星过后一星座):压力缓解,但有收获 参数:moon_sign(Moon星座),current_year(当前年份,用于判断是否在进行中) 返回:Sade Sati阶段信息 """ results = {'is_active': False, 'phase': 'none', 'summary': ''} if not moon_sign or moon_sign not in SIGNS: results['summary'] = 'Moon星座未知,无法判断Sade Sati' results['summary_en'] = 'Moon sign unknown; Sade Sati cannot be judged' return results moon_idx = SIGNS.index(moon_sign) # 简化:只判断当前年份Saturn是否在Moon前后1星座 # 实际需要Saturn实时位置,这里只给框架 results['moon_sign'] = moon_sign results['moon_idx'] = moon_idx results['phases'] = { 'rising': SIGNS[(moon_idx - 1) % 12], # 前一星座 'peak': moon_sign, # Moon星座(最困难) 'setting': SIGNS[(moon_idx + 1) % 12], # 后一星座 } # Upstream e628118d: with the dated transit Saturn sign the result is the # current phase, not only the frame (三方对照 2026-11-07:P 没传行运土星, # Jobs 2026-11-07 土星在双鱼 = 月亮星座,却判「不在 Sade Sati」)。 if transit_saturn_sign in SIGNS: try: from sade_sati import calc_sade_sati as calculate_current_phase except ModuleNotFoundError: # pragma: no cover - package import from scripts.sade_sati import calc_sade_sati as calculate_current_phase current = calculate_current_phase(moon_sign, transit_saturn_sign) results.update(is_active=bool(current.get('active')), phase=current.get('phase') or 'none', saturn_sign=transit_saturn_sign, reference_date=reference_date) results['summary'] = (f"Sade Sati:{current.get('phase_name') or current.get('phase')};" f"月亮 {moon_sign},行运土星 {transit_saturn_sign}" + (f"({reference_date})" if reference_date else '')) results['summary_en'] = (f"Sade Sati: {current.get('phase')}; Moon {moon_sign}, " f"transit Saturn {transit_saturn_sign}" + (f" ({reference_date})" if reference_date else '')) return results results['summary'] = (f'Sade Sati阶段框架:上升期={results["phases"]["rising"]},' f'高峰期={results["phases"]["peak"]}(最困难),' f'下降期={results["phases"]["setting"]};' f'需结合Saturn实际位置判断是否在进行中') results['summary_en'] = ( f"Sade Sati phase frame: rising={results['phases']['rising']}, " f"peak={results['phases']['peak']} (most difficult), " f"setting={results['phases']['setting']}; " "judge from Saturn's actual position whether it is underway" ) return results def _arudha_from_jaimini(asc_sign: str, planets_data: Dict) -> Dict: """AL / UL 只有一个来源:jaimini.calc_arudha_padas(BUG-1190,TASK-upstream-sync4-20261002 T6)。 旧的 calc_arudha_lagna / calc_upapada_lagna 把「第几宫」当成白羊起算的星座序号, 且没有 1/7 宫例外,同一张盘与 jaimini 结果不同,已删除。1/7 宫例外的数法沿用 jaimini 现行口径(占星师清单第 5 题未决,本单不改)。 """ empty = { 'arudha_lagna': {'arudha_lagna': None, 'al_house': None, 'source': 'jaimini.calc_arudha_padas'}, 'upapada_lagna': {'upapada': None, 'ul_house': None, 'source': 'jaimini.calc_arudha_padas'}, } if not asc_sign or asc_sign not in SIGNS: return empty try: from jaimini import calc_arudha_padas except ImportError: # package import (scripts.yogas_doshas) from scripts.jaimini import calc_arudha_padas planet_lons = { name: data.get('degree_raw', data.get('degree')) for name, data in (planets_data or {}).items() if isinstance(data, dict) and isinstance(data.get('degree_raw', data.get('degree')), (int, float)) } asc_idx = SIGNS.index(asc_sign) padas = calc_arudha_padas(asc_idx, planet_lons) def _house(pada): return ((pada['sign_idx'] - asc_idx) % 12) + 1 al = padas.get('arudha_lagna') ul = padas.get('upapada') result = empty if al: result['arudha_lagna'] = { 'arudha_lagna': al['sign'], 'al_house': _house(al), 'source': 'jaimini.calc_arudha_padas', 'summary': f"Arudha Lagna (AL) = {al['sign']}(第{_house(al)}宫),取自 jaimini.calc_arudha_padas", } if ul: result['upapada_lagna'] = { 'upapada': ul['sign'], 'ul_house': _house(ul), 'source': 'jaimini.calc_arudha_padas', 'summary': f"Upapada Lagna (UL) = {ul['sign']}(第{_house(ul)}宫),取自 jaimini.calc_arudha_padas", } return result def calc_all_yogas_doshas(planets_data: Dict, houses: Dict, asc_sign: str, asc_lord: str, moon_sign: str, moon_house: int, mars_house: int, sun_house: int, house12_lord: str) -> Dict: """ 批量计算所有 Yogas + Doshas + Special Lagnas(v6.0.14 主入口) 参数: planets_data: 行星数据字典 houses: 宫位信息字典 asc_sign: 上升星座 asc_lord: 上升主星 moon_sign: Moon星座 moon_house: Moon宫位 mars_house: Mars宫位 sun_house: Sun宫位 house12_lord: 12宫主星 返回:完整结果字典 """ results = {} # Yogas results['raj_yogas'] = calc_raj_yogas(planets_data, houses) results['dhana_yogas'] = calc_dhana_yogas(planets_data, houses) # BUG-1207 (甲5): Pancha Mahapurusha has one main detector # (scripts/pancha_mahapurusha.py, via main_yoga_detectors). This older # aggregate checks no affliction at all; its list is kept for reference only # and is not counted as a formed yoga. reference = calc_pancha_mahapurusha_yoga(planets_data) results['pancha_mahapurusha'] = { 'status': 'reference_only', 'main_detector': 'scripts/pancha_mahapurusha.py', 'yogas': [], 'reference_yogas': reference['yogas'], 'summary': 'reference_only:五大人格以 scripts/pancha_mahapurusha.py 主检测器为准', } results['nicha_bhanga_raj'] = calc_nicha_bhanga_raj_yoga(planets_data, houses) # Doshas results['mangal_dosha'] = calc_mangal_dosha(planets_data, mars_house) results['kaal_sarp_dosha'] = calc_kaal_sarp_dosha(planets_data) results['pitra_dosha'] = calc_pitra_dosha(planets_data, sun_house) results['sade_sati'] = calc_sade_sati(moon_sign) # Special Lagnas results.update(_arudha_from_jaimini(asc_sign, planets_data)) # 总结 total_yogas_count = (len(results['raj_yogas']['yogas']) + len(results['dhana_yogas']['yogas']) + len(results['pancha_mahapurusha']['yogas']) + len(results['nicha_bhanga_raj']['yogas'])) has_dosha = any([ results['mangal_dosha']['has_dosha'], results['kaal_sarp_dosha']['has_dosha'], results['pitra_dosha']['has_dosha'], ]) results['summary'] = ( f"Yogas共{total_yogas_count}个;" f"Doshas: Mangal={'有' if results['mangal_dosha']['has_dosha'] else '无'}" f"/Kaal Sarp={'有' if results['kaal_sarp_dosha']['has_dosha'] else '无'}" f"/Pitra={'有' if results['pitra_dosha']['has_dosha'] else '无'}" ) return results