#!/usr/bin/env python3 """Theme-level KP monthly support aggregation.""" from __future__ import annotations # BUG-2333: the astrologer's 17a135457ec16b621f86dd57ba3926612ce1b9b8 — the actual domain chain (cusp sub lord, period # lords, the transiting period lords' star / sub lords; all four significator levels) and her neutral wording. The # report path keeps its earlier wording (``report_wording=True``, the default of the report packet; see # kp_monthly_report_packet.py); the product's 「大运」 for her 「主运」 is kept in both. try: from kp_system import get_kp_lords except ImportError: from scripts.kp_system import get_kp_lords _DOMAIN_HOUSES = { "career": (2, 6, 10, 11), "wealth": (2, 5, 9, 11), "relationship": (2, 7, 11), } _DOMAIN_LABELS = { "career": "事业", "wealth": "财务", "relationship": "关系", } _HOUSE_LABELS = { 2: "收入与资源", 5: "机会与投入", 6: "职责与压力", 7: "合作与伴侣", 9: "运气与扩张", 10: "事业与位置", 11: "回报与支持", } _REPORT_DOMAIN_TEMPLATES = { "career": "这段时间更适合把重心放在职责变化、位置调整和回报兑现的节奏里观察。", "wealth": "这段时间更适合把注意力放在现金流、机会选择和回报兑现的节奏里观察。", "relationship": "这段时间更适合把重心放在合作默契、关系回应和现实支持的变化里观察。", } _DOMAIN_TEMPLATES = { "career": "这些关联涉及职责、位置和收入,不单凭宫位关联区分升职或离职。", "wealth": "这些关联涉及资源和收支,不单凭宫位关联判断盈利或亏损。", "relationship": "这些关联涉及伴侣和合作,相识、形成关系与结婚需要分别分析。", } _PLANET_CN = { "Sun": "太阳", "Moon": "月亮", "Mars": "火星", "Mercury": "水星", "Jupiter": "木星", "Venus": "金星", "Saturn": "土星", "Rahu": "罗睺", "Ketu": "计都", } _REPORT_NODE_CN = {"Rahu": "北交点", "Ketu": "南交点"} _SIGN_CN = { "Aries": "白羊座", "Taurus": "金牛座", "Gemini": "双子座", "Cancer": "巨蟹座", "Leo": "狮子座", "Virgo": "处女座", "Libra": "天秤座", "Scorpio": "天蝎座", "Sagittarius": "射手座", "Capricorn": "摩羯座", "Aquarius": "水瓶座", "Pisces": "双鱼座", } def _collect_active_houses(houses: dict, house_numbers: tuple[int, ...], *, report_wording: bool = False) -> list[int]: active: list[int] = [] levels = ("A",) if report_wording else ("A", "B", "C", "D") for house in house_numbers: # The report keeps its earlier string-key lookup (cmd_kp keys houses by int: no house was ever active there); # her 17a13545 reads both. row = houses.get(str(house)) if report_wording else houses.get(str(house), houses.get(house, {})) row = row if isinstance(row, dict) else {} significators = row.get("significators") if isinstance(row.get("significators"), dict) else {} if any(significators.get(level) not in (None, "", [], (), set()) for level in levels): active.append(house) return active def _house_signal_text(active_houses: list[int], fallback_houses: tuple[int, ...], report_wording: bool = False) -> str: if not active_houses: return "相关宫位线索暂时偏弱" if report_wording else "相关宫位资料尚不完整" labels = [f"{house}宫{_HOUSE_LABELS.get(house, '')}" for house in active_houses] return "、".join(labels) def _planet_label(planet: str, report_wording: bool) -> str: return (_REPORT_NODE_CN.get(planet) if report_wording else None) or _PLANET_CN.get(planet, planet) def _summary_text(domain: str, active_houses: list[int], fallback_houses: tuple[int, ...], md_lord: str, saturn_sign: str, report_wording: bool = False) -> str: label = _DOMAIN_LABELS.get(domain, domain) focus = _house_signal_text(active_houses, fallback_houses, report_wording) templates = _REPORT_DOMAIN_TEMPLATES if report_wording else _DOMAIN_TEMPLATES template = templates.get(domain, "这段时间更适合先看结构支持,再看外部触发。") md_label = _planet_label(md_lord, report_wording) saturn_label = _SIGN_CN.get(saturn_sign, saturn_sign) if active_houses: return ( f"{label}线本月先看 {focus} 的{'本命承诺' if report_wording else '本命关联'};" f"当前大运星为{md_label},土星行运落在{saturn_label},{template}" ) fallback_text = "、".join( f"{house}宫{_HOUSE_LABELS.get(house, '')}" for house in fallback_houses ) lead = ("这组标准宫位阅读,再等待更强触发出现;" if report_wording else "这组主题宫位核对;当前资料不足以判定支持强弱;") return ( f"{label}线本月更适合先按 {fallback_text} {lead}" f"当前大运星为{md_label},土星行运落在{saturn_label},{template}" ) def _brief_summary_text(domain: str, active_houses: list[int], fallback_houses: tuple[int, ...], md_lord: str, report_wording: bool = False) -> str: label = _DOMAIN_LABELS.get(domain, domain) md_label = _planet_label(md_lord, report_wording) focus_houses = active_houses or list(fallback_houses[:2]) focus_text = "、".join(f"{house}宫" for house in focus_houses) return f"本命焦点:{focus_text};月运主轴:{label}线跟随{md_label}大运推进。" def _planet_house_evidence(natal: dict, planet: str | None, domain_houses: tuple) -> dict: row = (natal.get('planets') or {}).get(planet, {}) sig = row.get('significators') or {} missing = [level for level in ('A', 'B', 'C', 'D') if level not in sig or sig[level] is None] houses = set() for value in sig.values(): values = value if isinstance(value, (list, tuple)) else [value] houses.update(h for h in values if type(h) is int and 1 <= h <= 12) return {'planet': planet, 'significators': sig, 'status': 'partial' if missing and houses else 'unavailable' if missing else 'available', 'missing_levels': missing, 'domain_houses': sorted(houses.intersection(domain_houses)), 'other_houses': sorted(houses.difference(domain_houses))} def _build_domain_chain(natal: dict, levels: dict, transits: dict, domain: str, houses: tuple) -> dict: primary = {'career': 10, 'wealth': 2, 'relationship': 7}[domain] cusp = (natal.get('houses') or {}).get(str(primary), (natal.get('houses') or {}).get(primary, {})) sub = (cusp.get('kp_lords') or {}).get('sub_lord') period_rows, transit_rows = [], [] for level in ('mahadasha', 'antardasha', 'pratyantardasha'): lord = (levels.get(level) or {}).get('lord') period_rows.append({'level': level, **_planet_house_evidence(natal, lord, houses)}) transit = (transits.get('planets') or {}).get(lord, {}) longitude = transit.get('longitude') if longitude is None: transit_rows.append({'level': level, 'planet': lord, 'status': 'unavailable'}) continue try: chain = get_kp_lords(longitude) except (ValueError, TypeError): transit_rows.append({'level': level, 'planet': lord, 'status': 'unavailable'}) continue transit_rows.append({'level': level, 'planet': lord, 'status': 'available', 'longitude': longitude, 'kp_lords': chain, 'star_lord_evidence': _planet_house_evidence(natal, chain.get('nakshatra_lord'), houses), 'sub_lord_evidence': _planet_house_evidence(natal, chain.get('sub_lord'), houses)}) return {'event_scope': 'broad_domain_not_a_specific_event', 'primary_house': primary, 'cuspal_sub_lord': _planet_house_evidence(natal, sub, houses), 'period_lords': period_rows, 'transiting_period_lords': transit_rows, 'sampling': 'month_start_noon_only', 'event_promised': None, 'outcome_direction': 'not_adjudicated', 'counterevidence_status': 'event_specific_rules_not_applied', 'birth_time_stability': 'not_evaluated', 'boundary': 'Auditable domain associations, not independent votes, event probability, full-month coverage or a promised outcome. Other houses are retained without treating every non-domain house as adverse.'} def build_kp_monthly_theme_support( *, natal_kp: dict, monthly_levels: dict, monthly_transits: dict, report_wording: bool = False ) -> dict: houses = natal_kp.get("houses") if isinstance(natal_kp.get("houses"), dict) else {} ruling = natal_kp.get("ruling_planets") if isinstance(natal_kp.get("ruling_planets"), dict) else {} md_lord = ((monthly_levels.get("mahadasha") or {}) if isinstance(monthly_levels, dict) else {}).get("lord") or "-" saturn_sign = ((((monthly_transits.get("planets") or {}) if isinstance(monthly_transits, dict) else {}).get("Saturn") or {}) if isinstance((monthly_transits.get("planets") or {}).get("Saturn"), dict) else {}).get("sign") or "-" out = {} for domain, house_numbers in _DOMAIN_HOUSES.items(): active_houses = _collect_active_houses(houses, house_numbers, report_wording=report_wording) out[domain] = { "houses": list(house_numbers), "active_houses": active_houses, "promise_code": " / ".join(str(h) for h in active_houses) if active_houses else "-", "summary": _summary_text(domain, active_houses, house_numbers, md_lord, saturn_sign, report_wording), "brief_summary": _brief_summary_text(domain, active_houses, house_numbers, md_lord, report_wording), "ruling_planet_snapshot": ruling.get("day_lord") or "-", "status": "parameter_sensitive", "must_not_claim": ["exact_event_timing", "specific_event_prediction"], } if report_wording: continue chain = _build_domain_chain(natal_kp, monthly_levels, monthly_transits, domain, house_numbers) matched_levels = [row['level'] for row in chain['period_lords'] if row['domain_houses']] level_names = {'mahadasha': '大运', 'antardasha': '小运', 'pratyantardasha': '细运'} association_text = ('、'.join(level_names[level] for level in matched_levels) + '主星与该领域宫位有关联。' if matched_levels else '当前资料未显示周期主星与该领域宫位的明确关联。') out[domain].update({ "evidence_chain": chain, "association_summary": association_text, "promise_code_semantics": "legacy field: natal house associations only, not event promise", }) out[domain]['summary'] += association_text + '这里比较的是月初线索,不能代表整月或确定某件事会发生。' out[domain]['brief_summary'] = association_text return out