diff --git a/services/logic/app/engine/tables.py b/services/logic/app/engine/tables.py new file mode 100644 index 0000000..4420956 --- /dev/null +++ b/services/logic/app/engine/tables.py @@ -0,0 +1,368 @@ +"""Tabele pomocnicze horoskopu (LOG-23). + +Zbiór wyliczeń, które astrolog czyta „obok" pozycji: bilans żywiołów i jakości, +faza Księżyca, stopnie krytyczne, dzień i godziny planetarne, syzygia prenatalna +oraz podziały (dwunastniki i nawamsa). + +Dwie rzeczy wymagają prawdziwego liczenia, nie tabelki: + * **godziny planetarne** — są NIERÓWNE: dzień od wschodu do zachodu Słońca dzieli + się na 12 części, noc osobno. Bez faktycznego wschodu/zachodu wynik byłby + zmyślony, więc szukamy ich numerycznie (przejście wysokości Słońca przez −0°50′); + * **syzygia prenatalna** — ostatni nów albo pełnia PRZED urodzeniem; szukamy + wstecz momentu, w którym elongacja Księżyca przechodzi przez 0° lub 180°. + +Moduł jest silnik-agnostyczny: potrzebuje tylko `positions()` i `sidereal()`. +""" +from __future__ import annotations + +import math +from datetime import datetime, timedelta + +from app.engine.formats import SIGNS, in_sign, norm360, sign_index +from app.engine.models import ChartMoment +from app.engine.zodiac import to_equatorial + +# --- żywioły i jakości ------------------------------------------------------ +ELEMENTS = ["Fire", "Earth", "Air", "Water"] +QUALITIES = ["Cardinal", "Fixed", "Mutable"] +ELEMENT_PL = {"Fire": "Ogień", "Earth": "Ziemia", "Air": "Powietrze", "Water": "Woda"} +QUALITY_PL = {"Cardinal": "Kardynalny", "Fixed": "Stały", "Mutable": "Zmienny"} + +CLASSICAL = ["Sun", "Moon", "Mercury", "Venus", "Mars", "Jupiter", "Saturn"] +MODERN = CLASSICAL + ["Uranus", "Neptune", "Pluto"] + +# --- dzień i godziny planetarne -------------------------------------------- +# Kolejność chaldejska: od najwolniejszej do najszybszej planety +CHALDEAN = ["Saturn", "Jupiter", "Mars", "Sun", "Venus", "Mercury", "Moon"] +# Władca dnia wg dnia tygodnia (0 = poniedziałek, jak w datetime.weekday()) +WEEKDAY_RULER = ["Moon", "Mars", "Mercury", "Jupiter", "Venus", "Saturn", "Sun"] + +# wysokość środka tarczy Słońca przy wschodzie/zachodzie (refrakcja + promień tarczy) +SUNRISE_ALTITUDE = -0.833 + + +def element_of(sign: str) -> str: + return ELEMENTS[SIGNS.index(sign) % 4] + + +def quality_of(sign: str) -> str: + return QUALITIES[SIGNS.index(sign) % 3] + + +def tally(positions: list[dict], asc_sign: str | None = None, + modern: bool = True) -> dict: + """Bilans żywiołów i jakości (LOG-23). + + Liczymy w dwóch wariantach naraz, bo szkoły się różnią: 7 planet klasycznych + i 10 z nowożytnymi. Ascendent doliczany osobno — bywa traktowany jak punkt + równorzędny planetom. + """ + wanted = MODERN if modern else CLASSICAL + by_name = {p.get("name"): p for p in positions} + + def count(names: list[str], with_asc: bool) -> dict: + elements = dict.fromkeys(ELEMENTS, 0) + qualities = dict.fromkeys(QUALITIES, 0) + used = [] + for name in names: + p = by_name.get(name) + if not p or not p.get("sign"): + continue + elements[element_of(p["sign"])] += 1 + qualities[quality_of(p["sign"])] += 1 + used.append(name) + if with_asc and asc_sign: + elements[element_of(asc_sign)] += 1 + qualities[quality_of(asc_sign)] += 1 + used.append("Asc") + return {"elements": elements, "qualities": qualities, + "counted": used, "total": len(used)} + + classical = count(CLASSICAL, False) + result = { + "classical_7": classical, + "with_modern_10": count(wanted, False), + "classical_7_plus_asc": count(CLASSICAL, True), + "with_modern_10_plus_asc": count(wanted, True), + } + # brakujące żywioły — klasyczne „no air" itd., podstawa pod scoring (LOG-21) + base = result["with_modern_10_plus_asc"] + result["missing_elements"] = [e for e, n in base["elements"].items() if n == 0] + result["missing_qualities"] = [q for q, n in base["qualities"].items() if n == 0] + result["labels"] = {"elements": ELEMENT_PL, "qualities": QUALITY_PL} + return result + + +# --- faza Księżyca ---------------------------------------------------------- +_PHASES = [ + (0.0, "New Moon", "Nów"), + (45.0, "Waxing Crescent", "Sierp przybywający"), + (90.0, "First Quarter", "Pierwsza kwadra"), + (135.0, "Waxing Gibbous", "Garb przybywający"), + (180.0, "Full Moon", "Pełnia"), + (225.0, "Waning Gibbous", "Garb ubywający"), + (270.0, "Last Quarter", "Ostatnia kwadra"), + (315.0, "Waning Crescent", "Sierp ubywający"), +] + + +def moon_phase(sun_lon: float, moon_lon: float) -> dict: + """Faza Księżyca z elongacji (Księżyc − Słońce).""" + angle = norm360(moon_lon - sun_lon) + idx = int(((angle + 22.5) % 360.0) // 45.0) + _, name, name_pl = _PHASES[idx] + illumination = (1.0 - math.cos(math.radians(angle))) / 2.0 + return { + "angle": round(angle, 4), + "phase": name, + "phase_pl": name_pl, + "illumination": round(illumination, 4), + "waxing": angle < 180.0, + } + + +# --- stopnie krytyczne ------------------------------------------------------ +# klasyczne stopnie krytyczne zależą od jakości znaku +_CRITICAL = {"Cardinal": (0, 13, 26), "Fixed": (8, 21), "Mutable": (4, 17)} +CRITICAL_ORB = 1.0 + + +def critical_degrees(positions: list[dict]) -> list[dict]: + """Obiekty stojące na stopniach krytycznych, 0° albo 29° (anaretycznym).""" + out = [] + for p in positions: + lon = p.get("decimal") + sign = p.get("sign") + if lon is None or not sign: + continue + deg = norm360(lon) - sign_index(lon) * 30.0 + flags = [] + for critical in _CRITICAL[quality_of(sign)]: + if abs(deg - critical) <= CRITICAL_ORB: + flags.append(f"stopień krytyczny {critical}° ({QUALITY_PL[quality_of(sign)].lower()})") + if deg >= 29.0: + flags.append("29° — stopień anaretyczny (koniec znaku)") + elif deg < 1.0: + flags.append("0° — wejście w znak") + if flags: + out.append({"name": p.get("name"), "sign": sign, + "in_sign": p.get("in_sign"), "flags": flags}) + return out + + +# --- podziały: dwunastnik i nawamsa ---------------------------------------- +def dwadasamsa(lon: float) -> float: + """12. część (dwadasamsa): znak dzielony na 12 po 2°30′, licząc od siebie.""" + lon = norm360(lon) + start = sign_index(lon) * 30.0 + return norm360(start + (lon - start) * 12.0) + + +def navamsa(lon: float) -> float: + """9. część (nawamsa): 108 podziałów po 3°20′ liczonych od 0° Barana.""" + lon = norm360(lon) + part = int(lon // (30.0 / 9.0)) + return norm360((part % 12) * 30.0 + (lon % (30.0 / 9.0)) * 9.0) + + +def divisional(positions: list[dict]) -> list[dict]: + """Pozycje w podziałach 12. i 9. — obie tabele naraz.""" + out = [] + for p in positions: + lon = p.get("decimal") + if lon is None: + continue + d12, d9 = dwadasamsa(lon), navamsa(lon) + out.append({ + "name": p.get("name"), + "d12_sign": SIGNS[sign_index(d12)], "d12_in_sign": in_sign(d12), + "d9_sign": SIGNS[sign_index(d9)], "d9_in_sign": in_sign(d9), + }) + return out + + +# --- wschód/zachód Słońca i godziny planetarne ------------------------------ +def sun_altitude(engine, moment: ChartMoment) -> float: + """Wysokość Słońca nad horyzontem [°] dla momentu i miejsca.""" + ramc, eps = engine.sidereal(moment) + sun = engine.positions(moment, ["Sun"])[0] + ra, dec = to_equatorial(sun.longitude, sun.latitude, eps) + hour_angle = math.radians(norm360(ramc - ra)) + phi, d = math.radians(moment.lat), math.radians(dec) + sin_alt = math.sin(d) * math.sin(phi) + math.cos(d) * math.cos(phi) * math.cos(hour_angle) + return math.degrees(math.asin(max(-1.0, min(1.0, sin_alt)))) + + +def _at(moment: ChartMoment, when: datetime) -> ChartMoment: + return ChartMoment(when_utc=when, lat=moment.lat, lon=moment.lon) + + +def _crossings(engine, moment: ChartMoment, start: datetime, end: datetime, + step_minutes: int = 20) -> list[tuple[datetime, str]]: + """Momenty przejścia Słońca przez horyzont w oknie [start, end]. + + Skan zgrubny + bisekcja — ten sam wzorzec co przy stacjach planet (LOG-03). + """ + out: list[tuple[datetime, str]] = [] + step = timedelta(minutes=step_minutes) + t0 = start + f0 = sun_altitude(engine, _at(moment, t0)) - SUNRISE_ALTITUDE + while t0 < end: + t1 = min(t0 + step, end) + f1 = sun_altitude(engine, _at(moment, t1)) - SUNRISE_ALTITUDE + if f0 == 0.0 or (f0 < 0.0) != (f1 < 0.0): + lo, hi, flo = t0, t1, f0 + for _ in range(40): # ~sekundowa dokładność + mid = lo + (hi - lo) / 2 + fmid = sun_altitude(engine, _at(moment, mid)) - SUNRISE_ALTITUDE + if (flo < 0.0) != (fmid < 0.0): + hi = mid + else: + lo, flo = mid, fmid + out.append((lo + (hi - lo) / 2, "sunrise" if f1 > f0 else "sunset")) + t0, f0 = t1, f1 + return out + + +def planetary_hours(engine, moment: ChartMoment) -> dict | None: + """Dzień i godziny planetarne w porządku chaldejskim (LOG-23). + + Godziny są NIERÓWNE: dzień (wschód→zachód) i noc (zachód→wschód) dzielą się + na 12 części każde. Doba planetarna zaczyna się o WSCHODZIE, nie o północy — + dlatego władcę dnia bierzemy z dnia tygodnia tego wschodu, który otworzył + bieżący okres. + + Zwraca None dla dnia polarnego/nocy polarnej, gdzie wschód nie występuje. + """ + now = moment.when_utc + events = _crossings(engine, moment, now - timedelta(hours=30), now + timedelta(hours=30)) + if not events: + return None # brak wschodu/zachodu w oknie + + before = [e for e in events if e[0] <= now] + after = [e for e in events if e[0] > now] + if not before or not after: + return None + + last_time, last_kind = before[-1] + next_time, _ = after[0] + + daytime = last_kind == "sunrise" + period_start, period_end = last_time, next_time + # doba planetarna startuje o wschodzie: w nocy to wschód POPRZEDZAJĄCY zachód + day_start = last_time if daytime else next((t for t, k in reversed(before) + if k == "sunrise"), last_time) + + length = (period_end - period_start) / 12 + index = int((now - period_start) / length) + index = max(0, min(11, index)) + + day_ruler = WEEKDAY_RULER[day_start.weekday()] + hour_number = index if daytime else index + 12 # 0..23 od wschodu + ruler = CHALDEAN[(CHALDEAN.index(day_ruler) + hour_number) % 7] + + hours = [] + for i in range(12): + start = period_start + length * i + hours.append({ + "index": i + 1, + "ruler": CHALDEAN[(CHALDEAN.index(day_ruler) + (i if daytime else i + 12)) % 7], + "start": start.isoformat(timespec="seconds"), + "end": (start + length).isoformat(timespec="seconds"), + "current": i == index, + }) + + return { + "day_ruler": day_ruler, + "hour_ruler": ruler, + "hour_number": hour_number + 1, + "daytime": daytime, + "period": "dzień" if daytime else "noc", + "hour_length_minutes": round(length.total_seconds() / 60.0, 2), + "period_start": period_start.isoformat(timespec="seconds"), + "period_end": period_end.isoformat(timespec="seconds"), + "hours": hours, + } + + +# --- syzygia prenatalna ----------------------------------------------------- +def prenatal_syzygy(engine, moment: ChartMoment, max_days: float = 32.0) -> dict | None: + """Ostatni nów albo pełnia PRZED podanym momentem (LOG-23). + + Szukamy wstecz przejścia elongacji przez 0° (nów) lub 180° (pełnia); bierzemy + to, które wypadło później. Cykl trwa ~29,5 dnia, więc okno 32 dni wystarcza. + """ + def elongation(when: datetime) -> float: + pts = {p.name: p.longitude for p in + engine.positions(_at(moment, when), ["Sun", "Moon"])} + return norm360(pts["Moon"] - pts["Sun"]) + + def signed(when: datetime, target: float) -> float: + """Odległość od celu w [−180, 180] — zeruje się dokładnie w syzygii.""" + return ((elongation(when) - target + 180.0) % 360.0) - 180.0 + + best: tuple[datetime, str] | None = None + for target, kind in ((0.0, "new_moon"), (180.0, "full_moon")): + step = timedelta(hours=6) + t1 = moment.when_utc + f1 = signed(t1, target) + scanned = timedelta() + while scanned < timedelta(days=max_days): + t0 = t1 - step + f0 = signed(t0, target) + if (f0 < 0.0) != (f1 < 0.0) and abs(f0 - f1) < 180.0: + lo, hi, flo = t0, t1, f0 + for _ in range(40): + mid = lo + (hi - lo) / 2 + fmid = signed(mid, target) + if (flo < 0.0) != (fmid < 0.0): + hi = mid + else: + lo, flo = mid, fmid + found = lo + (hi - lo) / 2 + if best is None or found > best[0]: + best = (found, kind) + break + t1, f1 = t0, f0 + scanned += step + + if best is None: + return None + + when, kind = best + pts = {p.name: p.longitude for p in engine.positions(_at(moment, when), ["Sun", "Moon"])} + lon = pts["Sun"] if kind == "new_moon" else pts["Moon"] + return { + "type": kind, + "type_pl": "nów" if kind == "new_moon" else "pełnia", + "when_utc": when.isoformat(timespec="seconds"), + "days_before_birth": round((moment.when_utc - when).total_seconds() / 86400.0, 3), + "sign": SIGNS[sign_index(lon)], + "in_sign": in_sign(lon), + "decimal": round(norm360(lon), 6), + } + + +# --- złożenie wszystkiego --------------------------------------------------- +def build_tables(engine, moment: ChartMoment, chart: dict, + heavy: bool = True) -> dict: + """Komplet tabel dla policzonego horoskopu. + + `heavy=False` pomija wyliczenia wymagające szukania numerycznego (godziny + planetarne, syzygia) — przydatne, gdy liczy się czas odpowiedzi. + """ + positions = chart.get("positions") or [] + by_name = {p.get("name"): p for p in positions} + asc_sign = (chart.get("angles") or {}).get("Asc", {}).get("sign") + + out: dict = { + "tally": tally(positions, asc_sign), + "critical_degrees": critical_degrees(positions), + "divisional": divisional(positions), + } + if "Sun" in by_name and "Moon" in by_name: + out["moon_phase"] = moon_phase(by_name["Sun"]["decimal"], by_name["Moon"]["decimal"]) + if heavy: + out["planetary_hours"] = planetary_hours(engine, moment) + out["prenatal_syzygy"] = prenatal_syzygy(engine, moment) + return out diff --git a/services/logic/app/main.py b/services/logic/app/main.py index 04824cc..c19f57b 100644 --- a/services/logic/app/main.py +++ b/services/logic/app/main.py @@ -41,6 +41,7 @@ class PositionsRequest(BaseModel): objects: list[str] | None = None house_system: str = "whole_sign" # whole_sign | equal | porphyry stations: bool = False # licz stacje (LOG-03; wolniejsze — root-findy) + tables: bool = False # tabele dodatkowe (LOG-23; szuka wschodu/zachodu) zodiac: str = "tropical" # LOG-04: tropical | sidereal_{lahiri,fagan_bradley,krishnamurti} | draconic @@ -72,6 +73,10 @@ def chart_positions(req: PositionsRequest) -> dict: st = find_stations(engine, moment, p["name"]) if st: p["stations"] = st + if req.tables: + from app.engine.tables import build_tables + + chart["tables"] = build_tables(engine, moment, chart) return chart diff --git a/services/logic/tests/test_tables.py b/services/logic/tests/test_tables.py new file mode 100644 index 0000000..05ddbe8 --- /dev/null +++ b/services/logic/tests/test_tables.py @@ -0,0 +1,216 @@ +"""Tabele pomocnicze horoskopu (LOG-23). + +Wartości referencyjne dla horoskopu 30.04.1984 09:20 UTC, Kraków (50.0647N, 19.9450E) +sprawdzone wobec faktów NIEZALEŻNYCH od naszego kodu: + * 30.04.1984 to poniedziałek → władca dnia Księżyc; 5. godzina poniedziałku + w porządku chaldejskim to Słońce (Mo, Sa, Ju, Ma, Su), + * wschód/zachód dla Krakowa końcem kwietnia ≈ 5:18 / 19:57 czasu lokalnego + (CEST = UTC+2), czyli 03:18 / 17:57 UTC, + * pełnia poprzedzająca urodzenie: 15.04.1984 ok. 19:11 UTC. +""" +from datetime import datetime, timezone + +import pytest + +from app.engine.chart import build_chart +from app.engine.models import ChartMoment +from app.engine.tables import ( + build_tables, + critical_degrees, + dwadasamsa, + element_of, + moon_phase, + navamsa, + planetary_hours, + prenatal_syzygy, + quality_of, + tally, +) + + +@pytest.fixture(scope="module") +def krakow(): + return ChartMoment(when_utc=datetime(1984, 4, 30, 9, 20, tzinfo=timezone.utc), + lat=50.0647, lon=19.9450) + + +@pytest.fixture(scope="module") +def tables(own_engine, krakow): + return build_tables(own_engine, krakow, build_chart(own_engine, krakow)) + + +# ------------------------------------------------------ żywioły i jakości + +def test_element_and_quality_mapping(): + assert element_of("Aries") == "Fire" and element_of("Cancer") == "Water" + assert quality_of("Aries") == "Cardinal" and quality_of("Taurus") == "Fixed" + assert quality_of("Gemini") == "Mutable" + + +def test_tally_matches_hand_count(tables): + """Ręcznie przeliczone dla horoskopu referencyjnego (10 planet + Asc).""" + base = tables["tally"]["with_modern_10_plus_asc"] + assert base["elements"] == {"Fire": 4, "Earth": 4, "Air": 0, "Water": 3} + assert base["qualities"] == {"Cardinal": 4, "Fixed": 6, "Mutable": 1} + assert base["total"] == 11 + + +def test_missing_element_detected(tables): + """Klasyczne „no air" — podstawa pod scoring siły (LOG-21).""" + assert tables["tally"]["missing_elements"] == ["Air"] + assert tables["tally"]["missing_qualities"] == [] + + +def test_tally_variants_differ_by_object_count(tables): + t = tables["tally"] + assert t["classical_7"]["total"] == 7 + assert t["with_modern_10"]["total"] == 10 + assert t["classical_7_plus_asc"]["total"] == 8 + assert t["with_modern_10_plus_asc"]["total"] == 11 + + +def test_tally_sums_equal_counted_objects(tables): + for variant in ("classical_7", "with_modern_10", "with_modern_10_plus_asc"): + v = tables["tally"][variant] + assert sum(v["elements"].values()) == v["total"] + assert sum(v["qualities"].values()) == v["total"] + + +# ---------------------------------------------------------- faza Księżyca + +def test_moon_phase_reference_is_balsamic_new(tables): + """Nów wypadł 1.05.1984, więc 30.04 Księżyc jest tuż przed nowiem.""" + mp = tables["moon_phase"] + assert mp["phase"] == "New Moon" + assert 340.0 < mp["angle"] < 360.0 + assert mp["illumination"] < 0.05 + assert mp["waxing"] is False # elongacja > 180 = ubywa + + +@pytest.mark.parametrize("angle,expected", [ + (0.0, "New Moon"), (90.0, "First Quarter"), (180.0, "Full Moon"), + (270.0, "Last Quarter"), (46.0, "Waxing Crescent"), (300.0, "Waning Crescent"), +]) +def test_moon_phase_buckets(angle, expected): + assert moon_phase(0.0, angle)["phase"] == expected + + +def test_moon_phase_illumination_extremes(): + assert moon_phase(0.0, 0.0)["illumination"] == 0.0 + assert moon_phase(0.0, 180.0)["illumination"] == 1.0 + assert moon_phase(0.0, 90.0)["illumination"] == pytest.approx(0.5) + + +# ------------------------------------------------------- stopnie krytyczne + +def test_critical_degrees_reference(tables): + found = {c["name"]: c["flags"] for c in tables["critical_degrees"]} + assert "Jupiter" in found # Cap 12°57' -> 13° kardynalny + assert any("13" in f for f in found["Jupiter"]) + assert "Pluto" in found # Sco 0°28' -> wejście w znak + + +def test_anaretic_degree_flagged(): + flags = critical_degrees([{"name": "X", "sign": "Leo", "decimal": 149.5, + "in_sign": "Leo 29°30'"}]) + assert flags and any("anaretyczny" in f for f in flags[0]["flags"]) + + +def test_no_flags_for_ordinary_degree(): + assert critical_degrees([{"name": "X", "sign": "Leo", "decimal": 135.0, + "in_sign": "Leo 15°"}]) == [] + + +# --------------------------------------------------------------- podziały + +def test_dwadasamsa_starts_from_own_sign(): + """12. część liczy się OD znaku, w którym stoi punkt.""" + assert dwadasamsa(0.0) == pytest.approx(0.0) # Ari 0 -> Ari + assert dwadasamsa(2.5) == pytest.approx(30.0) # Ari 2°30' -> Tau 0 + assert dwadasamsa(30.0) == pytest.approx(30.0) # Tau 0 -> Tau + + +def test_navamsa_classic_starts(): + """Znaki kardynalne zaczynają od siebie, stałe od 9. znaku.""" + assert navamsa(0.0) == pytest.approx(0.0) # Ari -> Ari + assert navamsa(30.0) == pytest.approx(270.0) # Tau -> Cap (9. od Byka) + assert navamsa(60.0) == pytest.approx(180.0) # Gem -> Lib + + +def test_divisional_covers_all_positions(tables, own_engine, krakow): + chart = build_chart(own_engine, krakow) + assert len(tables["divisional"]) == len(chart["positions"]) + + +# ------------------------------------------------- dzień i godziny planetarne + +def test_planetary_day_ruler_is_moon_on_monday(tables): + """30.04.1984 to poniedziałek → władcą dnia jest Księżyc.""" + assert tables["planetary_hours"]["day_ruler"] == "Moon" + + +def test_planetary_hour_matches_chaldean_sequence(tables): + """Poniedziałek: 1=Mo, 2=Sa, 3=Ju, 4=Ma, 5=Su — urodzenie w 5. godzinie dnia.""" + ph = tables["planetary_hours"] + assert ph["hour_number"] == 5 + assert ph["hour_ruler"] == "Sun" + assert ph["daytime"] is True + + +def test_sunrise_sunset_match_krakow_late_april(tables): + """Wschód ≈ 03:18 UTC, zachód ≈ 17:57 UTC (5:18 i 19:57 czasu lokalnego).""" + ph = tables["planetary_hours"] + assert ph["period_start"].startswith("1984-04-30T03:1") + assert ph["period_end"].startswith("1984-04-30T17:5") + + +def test_planetary_hours_are_unequal_and_complete(tables): + """Godziny są nierówne: wiosną dzienna trwa dłużej niż 60 minut.""" + ph = tables["planetary_hours"] + assert ph["hour_length_minutes"] > 60.0 + assert len(ph["hours"]) == 12 + assert sum(1 for h in ph["hours"] if h["current"]) == 1 + + +def test_polar_night_returns_none(own_engine): + """Za kołem podbiegunowym w grudniu Słońce nie wschodzi — brak godzin.""" + polar = ChartMoment(when_utc=datetime(2024, 12, 21, 12, 0, tzinfo=timezone.utc), + lat=78.0, lon=15.0) + assert planetary_hours(own_engine, polar) is None + + +# ------------------------------------------------------- syzygia prenatalna + +def test_prenatal_syzygy_is_april_1984_full_moon(tables): + """Rzeczywista pełnia: 15.04.1984 ok. 19:11 UTC.""" + s = tables["prenatal_syzygy"] + assert s["type"] == "full_moon" + assert s["when_utc"].startswith("1984-04-15T19:1") + + +def test_prenatal_syzygy_precedes_birth_within_a_cycle(tables): + days = tables["prenatal_syzygy"]["days_before_birth"] + assert 0 < days < 29.6, "syzygia musi być w ostatnim cyklu przed urodzeniem" + + +def test_prenatal_syzygy_elongation_is_at_target(own_engine, krakow): + """W znalezionym momencie elongacja MUSI wynosić 0° albo 180°.""" + from app.engine.formats import norm360 + + s = prenatal_syzygy(own_engine, krakow) + when = datetime.fromisoformat(s["when_utc"]) + pts = {p.name: p.longitude for p in + own_engine.positions(ChartMoment(when_utc=when, lat=krakow.lat, lon=krakow.lon), + ["Sun", "Moon"])} + elong = norm360(pts["Moon"] - pts["Sun"]) + target = 0.0 if s["type"] == "new_moon" else 180.0 + assert abs(((elong - target + 180.0) % 360.0) - 180.0) < 0.02 + + +# ------------------------------------------------------------------ całość + +def test_build_tables_light_skips_numeric_search(own_engine, krakow): + """heavy=False pomija to, co wymaga szukania numerycznego.""" + light = build_tables(own_engine, krakow, build_chart(own_engine, krakow), heavy=False) + assert "tally" in light and "moon_phase" in light + assert "planetary_hours" not in light and "prenatal_syzygy" not in light diff --git a/services/presentation/app/clients/logic_client.py b/services/presentation/app/clients/logic_client.py index 9e5ed1e..f92e854 100644 --- a/services/presentation/app/clients/logic_client.py +++ b/services/presentation/app/clients/logic_client.py @@ -39,6 +39,7 @@ class LogicClient: house_system: str = "whole_sign", stations: bool = False, zodiac: str = "tropical", + tables: bool = False, ) -> dict[str, Any]: """Pełny horoskop dla danego momentu — woła logic /chart/positions.""" payload = { @@ -49,9 +50,10 @@ class LogicClient: "house_system": house_system, "stations": stations, "zodiac": zodiac, + "tables": tables, } # stacje wymagają root-findów — dłuższy timeout - with httpx.Client(timeout=max(settings.http_timeout, 60.0) if stations else settings.http_timeout) as client: + with httpx.Client(timeout=max(settings.http_timeout, 60.0) if (stations or tables) else settings.http_timeout) as client: r = client.post(f"{self.base_url}/chart/positions", json=payload, headers=_auth_headers()) r.raise_for_status() return r.json() diff --git a/services/presentation/app/main.py b/services/presentation/app/main.py index 3243491..3e13ffd 100644 --- a/services/presentation/app/main.py +++ b/services/presentation/app/main.py @@ -79,17 +79,18 @@ def chart_compute( house_system: str = Form("whole_sign"), stations: bool = Form(False), zodiac: str = Form("tropical"), + tables: bool = Form(False), ): form = {"date": date, "time": time, "tz_offset": tz_offset, "lat": lat, "lon": lon, "house_system": house_system, "stations": stations, - "zodiac": zodiac} + "zodiac": zodiac, "tables": tables} ctx: dict = {"form": form, "result": None, "error": None, "moment": None} try: iso_utc, label = _build_utc(date, time, tz_offset) ctx["moment"] = label ctx["result"] = logic.positions( when_utc_iso=iso_utc, lat=lat, lon=lon, - house_system=house_system, stations=stations, zodiac=zodiac, + house_system=house_system, stations=stations, zodiac=zodiac, tables=tables, ) except (httpx.HTTPError,) as e: ctx["error"] = _logic_error(e) diff --git a/services/presentation/app/templates/chart.html b/services/presentation/app/templates/chart.html index d281a51..d73c80f 100644 --- a/services/presentation/app/templates/chart.html +++ b/services/presentation/app/templates/chart.html @@ -47,6 +47,8 @@
Wstępnie wpisano lokalizację: {{ location_label }} ({{ form.lat }}, {{ form.lon }}). Zmień pola lub kliknij „Tu i teraz".
{% endif %}| Bilans (10 planet + Asc) | Rozkład | |||
|---|---|---|---|---|
| Żywioły | + {% for e, n in bal.elements.items() %} +{{ tb.tally.labels.elements[e] }}: {{ n }} | + {% endfor %} +|||
| Jakości | + {% for q, n in bal.qualities.items() %} +{{ tb.tally.labels.qualities[q] }}: {{ n }} | + {% endfor %} ++ | ||
Brak: + {% for e in tb.tally.missing_elements %}{{ tb.tally.labels.elements[e] }}{{ ", " if not loop.last }}{% endfor %} + {% for q in tb.tally.missing_qualities %}{{ tb.tally.labels.qualities[q] }}{{ ", " if not loop.last }}{% endfor %} +
+ {% endif %} + + {% if tb.moon_phase %} ++ Faza Księżyca: {{ tb.moon_phase.phase_pl }} · + elongacja {{ '%.2f'|format(tb.moon_phase.angle) }}° · + oświetlenie {{ '%.1f'|format(tb.moon_phase.illumination * 100) }}% · + {{ 'przybywa' if tb.moon_phase.waxing else 'ubywa' }} +
+ {% endif %} + + {% if tb.planetary_hours %} + {% set ph = tb.planetary_hours %} ++ Godziny planetarne: władca dnia {{ ph.day_ruler }} · + {{ ph.hour_number }}. godzina ({{ ph.period }}), władca {{ ph.hour_ruler }} · + godzina trwa {{ ph.hour_length_minutes }} min +
+ {% endif %} + + {% if tb.prenatal_syzygy %} + {% set s = tb.prenatal_syzygy %} ++ Syzygia prenatalna: {{ s.type_pl }} {{ s.when_utc }} + ({{ s.days_before_birth }} dni przed) w {{ s.in_sign }} +
+ {% endif %} + + {% if tb.critical_degrees %} + +| Obiekt | Pozycja | Uwaga |
|---|---|---|
| {{ c.name }} | {{ c.in_sign }} | +{{ c.flags | join('; ') }} |
| Obiekt | D12 | D9 |
|---|---|---|
| {{ d.name }} | {{ d.d12_in_sign }} | +{{ d.d9_in_sign }} |