From 4ee7e9fc359987db191369ef2ba3bd6ea576d2f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:39:31 +0800 Subject: [PATCH] fix(western): zodiacal releasing level 2 in months, cut at the parent end, loosing of the bond (BUG-2341) Level-2 periods were scaled from the parent and all twelve were laid out, so a 12-year Sagittarius period held 214 years of sub-periods. Now per Valens: 360-day release years, level 2 in months starting from the parent sign, cut at the parent end, jump to the opposite sign once the twelve are used; Capricorn 27 years. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq --- docs/BUG_HISTORY.md | 15 ++++--- scripts/western_timing_engine.py | 69 ++++++++++++++++++++--------- tests/test_zodiacal_release_2341.py | 36 +++++++++++++++ 3 files changed, 93 insertions(+), 27 deletions(-) create mode 100644 tests/test_zodiacal_release_2341.py diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index e2fc487eb..4e108efe5 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -31862,15 +31862,16 @@ ## BUG-2341 | 黄道释放第二层子周期长度不对(一个 12 年的大周期里出现 30 年的子周期) -- 状态:investigating(只记录,未修;BUG-2340 范围外,决定 5)。 +- 状态:fixed-pending-verify(负责人 2026-11-25「fix 214year」)。 - 首次发现 / 最近更新:2026-11-24(西洋盘页面审计)/ 2026-11-25。 -- 现象:`western_timing_engine.calculate_zodiacal_release` 对奥巴马(精神点在射手)给出第一层射手 12 年(1961-08-04 至 1973-08-03),其第二层子周期为射手 12 年、摩羯 30 年、水瓶 30 年、双鱼 12 年……12 个子周期合计 214 年,最后一个结束在 2175-08-04,远超所属的 12 年大周期。 -- 触发条件:任何盘,`levels=2`,调用方点名 `zodiacal_release_date` 时(咨询默认的西洋 timing 不带它;古典模块 `classical_astrology.py:811` 与完整报告的 `unified_western_reading.py:176` 会调用),页面不显示。 -- 已确认的事实:`_build_release_periods` 第二层长度按「父周期年数 × 子星座年数 ÷ 12」计算,且 12 个子周期全部排完,不在父周期结束时截断,也没有「解结」。传统做法里第二层以月计(子星座小年数作为月数),排到父周期结束为止。根因与修法需要占星师确认算法后再定,本轮不改。 -- 影响面:完整报告的西洋对照、古典模块、点名黄道释放的 timing 调用(状态 `partial`);星盘页、咨询默认层不用。 +- 现象:`western_timing_engine.calculate_zodiacal_release` 对奥巴马(精神点在射手)给出第一层射手 12 年,其第二层 12 个子周期合计 214 年,最后一个结束在 2175 年,远超所属的 12 年大周期。 +- 触发条件:任何盘,`levels=2`(古典模块 `classical_astrology.py` 的释放裁定、完整报告 `unified_western_reading.py` 的参考层);星盘页、问答默认层不用。 +- 根因:`_build_release_periods` 第二层按「父周期年数 × 子星座年数 ÷ 12」算,12 个子周期全部排完、不在父周期结束处截断、没有解结;摩羯和水瓶都按土星 30 年(传统摩羯 27 年);年按 365.24 天(传统按 360 天的释放年)。 +- 修复(按 Vettius Valens《Anthology》卷四的通行做法):第一层按年、第二层按月(子星座小年数作月数),释放年 360 天、月 30 天;第二层从父星座起排,排到父周期结束为止、最后一段截断(`cut_at_parent_end`);同一父周期内 12 个星座用完时跳到父星座的对宫继续(解结,`loosing_of_the_bond`);摩羯 27 年、水瓶 30 年。第二层每行另带 `months`,`years` 为实际长度。 +- 验证:新增 `tests/test_zodiacal_release_2341.py`(子周期首尾与父周期一致且首尾相接;射手 12 年里依次射手 12 月、摩羯 27 月、水瓶 30 月……巨蟹被截断;摩羯 27 年里第 13 段跳到巨蟹并标解结);`tests/test_western_timing_engine.py` 与读到古典模块 / 统一西洋读法的测试通过;quick gate 通过。`tests/test_narayana_rath_book_tables.py::test_rath_profile_is_the_product_default…` 在改动前的基线上同样失败(与本项无关)。 +- 防复发:上面的测试。 - 关联记录:BUG-2340。 -- 修复版本:无。 - +- 修复版本:分支 `claude/zr-2341`。 ## BUG-2343 | 按天的回答同一个好日子、坏日子说了四遍 - 状态:fixed-pending-verify(本地提交,未推送;待负责人在 staging 看过)。 diff --git a/scripts/western_timing_engine.py b/scripts/western_timing_engine.py index 23071e4d4..f61abae59 100644 --- a/scripts/western_timing_engine.py +++ b/scripts/western_timing_engine.py @@ -580,18 +580,61 @@ def _lot_longitude(*, ascendant: float, sun: float, moon: float, is_day_chart: b return _longitude(raw) +# BUG-2341: zodiacal releasing after Vettius Valens (Anthology IV): each sign's period is its ruler's minor years +# (Capricorn 27, Aquarius 30 — the two Saturn signs differ), level 1 in years, level 2 in months; a release year is +# 360 days and a month 30 days. Level 2 starts from the level-1 sign, runs only until the parent period ends (the +# last sub-period is cut there) and, when all twelve signs are used up inside one parent period, jumps to the sign +# opposite the parent's sign ("loosing of the bond") and carries on in order from there. +_RELEASE_SIGN_YEARS_OVERRIDE = {"Capricorn": 27} +_RELEASE_YEAR_DAYS = 360 +_RELEASE_MONTH_DAYS = 30 + + def _period_years_for_sign(sign: str) -> int: - return _PLANETARY_YEARS[_RULERS[sign]] + return _RELEASE_SIGN_YEARS_OVERRIDE.get(sign, _PLANETARY_YEARS[_RULERS[sign]]) + + +def _release_level2(parent_sign_index: int, parent_start: datetime, parent_end: datetime) -> list[dict[str, Any]]: + subperiods: list[dict[str, Any]] = [] + sub_start = parent_start + sign_index = parent_sign_index + used = 0 + loosed = False + while sub_start < parent_end: + if used == 12 and not loosed: + sign_index = (parent_sign_index + 6) % 12 + loosed = True + sub_sign = _SIGNS[sign_index % 12] + months = _period_years_for_sign(sub_sign) + sub_end = min(sub_start + timedelta(days=months * _RELEASE_MONTH_DAYS), parent_end) + row: dict[str, Any] = { + "level": 2, + "sign": sub_sign, + "months": months, + "years": round((sub_end - sub_start).days / _RELEASE_YEAR_DAYS, 6), + "start_date": sub_start.date().isoformat(), + "end_date": (sub_end - timedelta(days=1)).date().isoformat(), + } + if sub_end == parent_end and sub_end - sub_start < timedelta(days=months * _RELEASE_MONTH_DAYS): + row["cut_at_parent_end"] = True + if loosed: + row["loosing_of_the_bond"] = True + subperiods.append(row) + sub_start = sub_end + sign_index += 1 + used += 1 + return subperiods def _build_release_periods(start_sign_index: int, start_date: datetime, levels: int) -> list[dict[str, Any]]: periods: list[dict[str, Any]] = [] current_start = start_date for offset in range(12): - sign = _SIGNS[(start_sign_index + offset) % 12] + sign_index = (start_sign_index + offset) % 12 + sign = _SIGNS[sign_index] years = _period_years_for_sign(sign) - current_end = current_start + timedelta(days=round(years * 365.242189)) - period = { + current_end = current_start + timedelta(days=years * _RELEASE_YEAR_DAYS) + period: dict[str, Any] = { "level": 1, "sign": sign, "years": years, @@ -599,21 +642,7 @@ def _build_release_periods(start_sign_index: int, start_date: datetime, levels: "end_date": (current_end - timedelta(days=1)).date().isoformat(), } if levels >= 2: - subperiods = [] - sub_start = current_start - for sub_offset in range(12): - sub_sign = _SIGNS[(start_sign_index + offset + sub_offset) % 12] - sub_years = years * _period_years_for_sign(sub_sign) / 12.0 - sub_end = sub_start + timedelta(days=round(sub_years * 365.242189)) - subperiods.append({ - "level": 2, - "sign": sub_sign, - "years": round(sub_years, 6), - "start_date": sub_start.date().isoformat(), - "end_date": (sub_end - timedelta(days=1)).date().isoformat(), - }) - sub_start = sub_end - period["subperiods"] = subperiods + period["subperiods"] = _release_level2(sign_index, current_start, current_end) periods.append(period) current_start = current_end return periods @@ -662,7 +691,7 @@ def calculate_zodiacal_release(*, target_date: str, lot: str = "spirit", levels: "levels": levels, "periods": periods, "active_period": active_period, - "boundary": "L1/L2 sign-period release scaffold from the Lot of Spirit/Fortune only; loosing-of-the-bond, peak periods, angularity weighting, and interpretation remain separate audited layers.", + "boundary": "L1/L2 zodiacal releasing from the Lot of Spirit/Fortune (Valens: 360-day years, level 2 in months, cut at the parent end, loosing of the bond); peak periods, angularity weighting and interpretation remain separate layers.", } diff --git a/tests/test_zodiacal_release_2341.py b/tests/test_zodiacal_release_2341.py new file mode 100644 index 000000000..5449c85ea --- /dev/null +++ b/tests/test_zodiacal_release_2341.py @@ -0,0 +1,36 @@ +"""BUG-2341: zodiacal releasing level 2 in months, cut at the parent end, loosing of the bond (Valens).""" +from datetime import date + +from scripts.western_timing_engine import calculate_zodiacal_release + +OBAMA = dict(year=1961, month=8, day=4, hour=19, minute=24, latitude=21.3069, longitude=-157.8583, timezone=-10) + + +def _periods(): + return calculate_zodiacal_release(target_date="2026-11-25", lot="spirit", levels=2, **OBAMA)["periods"] + + +def test_level2_stays_inside_its_parent_and_fills_it(): + for parent in _periods(): + subs = parent["subperiods"] + assert subs[0]["start_date"] == parent["start_date"] + assert subs[-1]["end_date"] == parent["end_date"] + for a, b in zip(subs, subs[1:]): + assert date.fromisoformat(b["start_date"]).toordinal() == date.fromisoformat(a["end_date"]).toordinal() + 1 + + +def test_level2_counts_months_and_capricorn_is_27(): + first = _periods()[0] + assert first["sign"] == "Sagittarius" and first["years"] == 12 + assert [s["sign"] for s in first["subperiods"]][:3] == ["Sagittarius", "Capricorn", "Aquarius"] + assert [s["months"] for s in first["subperiods"]][:3] == [12, 27, 30] + assert first["subperiods"][-1].get("cut_at_parent_end") is True + + +def test_loosing_of_the_bond_jumps_to_the_opposite_sign(): + capricorn = next(p for p in _periods() if p["sign"] == "Capricorn") + assert capricorn["years"] == 27 + subs = capricorn["subperiods"] + assert [s["sign"] for s in subs[:12]][-1] == "Sagittarius" + assert subs[12]["sign"] == "Cancer" and subs[12]["loosing_of_the_bond"] is True + assert not any(s.get("loosing_of_the_bond") for s in subs[:12])