PICK SKY overlay: D3 natal wheel, Character model, PySwiss aspects+tz
All checks were successful
ci/woodpecker/push/pyswiss Pipeline was successful
ci/woodpecker/push/main Pipeline was successful

PySwiss:
- calculate_aspects() in calc.py (conjunction/sextile/square/trine/opposition with orbs)
- /api/tz/ endpoint (timezonefinder lat/lon → IANA timezone)
- aspects included in /api/chart/ response
- timezonefinder==8.2.2 added to requirements
- 14 new unit tests (test_calc.py) + 12 new integration tests (TimezoneApiTest, aspect fields)

Main app:
- Sign, Planet, AspectType, HouseLabel reference models + seeded migrations (0032–0033)
- Character model with birth_dt/lat/lon/place, house_system, chart_data, celtic_cross,
  confirmed_at/retired_at lifecycle (migration 0034)
- natus_preview proxy view: calls PySwiss /api/chart/ + optional /api/tz/ auto-resolution,
  computes planet-in-house distinctions, returns enriched JSON
- natus_save view: find-or-create draft Character, confirmed_at on action='confirm'
- natus-wheel.js: D3 v7 SVG natal wheel (elements pie, signs, houses, planets, aspects,
  ASC/MC axes); NatusWheel.draw() / redraw() / clear()
- _natus_overlay.html: Nominatim place autocomplete (debounced 400ms), geolocation button
  with reverse-geocode city name, live chart preview (debounced 300ms), tz auto-fill,
  NVM / SAVE SKY footer; html.natus-open class toggle pattern
- _natus.scss: Gaussian backdrop+modal, two-column form|wheel layout, suggestion dropdown,
  portrait collapse at 600px, landscape sidebar z-index sink
- room.html: include overlay when table_status == SKY_SELECT

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Disco DeDisco
2026-04-14 02:09:26 -04:00
parent 44cf399352
commit 6248d95bf3
17 changed files with 1909 additions and 3 deletions

View File

@@ -19,6 +19,14 @@ SIGN_ELEMENT = {
'Cancer': 'Water', 'Scorpio': 'Water', 'Pisces': 'Water',
}
ASPECTS = [
('Conjunction', 0, 8.0),
('Sextile', 60, 6.0),
('Square', 90, 8.0),
('Trine', 120, 8.0),
('Opposition', 180, 10.0),
]
PLANET_CODES = {
'Sun': swe.SUN,
'Moon': swe.MOON,
@@ -90,3 +98,33 @@ def get_element_counts(planets):
counts['Space'] = max_seq - 1
return counts
def calculate_aspects(planets):
"""Return a list of aspects between all planet pairs.
Each entry: {planet1, planet2, type, angle (actual, rounded), orb (rounded)}.
Only the first matching aspect type is reported per pair (aspects are
well-separated enough that at most one can apply with standard orbs).
"""
names = list(planets.keys())
aspects = []
for i, name1 in enumerate(names):
for name2 in names[i + 1:]:
deg1 = planets[name1]['degree']
deg2 = planets[name2]['degree']
angle = abs(deg1 - deg2)
if angle > 180:
angle = 360 - angle
for aspect_name, target, max_orb in ASPECTS:
orb = abs(angle - target)
if orb <= max_orb:
aspects.append({
'planet1': name1,
'planet2': name2,
'type': aspect_name,
'angle': round(angle, 2),
'orb': round(orb, 2),
})
break
return aspects

View File

@@ -1,7 +1,7 @@
"""
Integration tests for the PySwiss chart calculation API.
These tests drive the TDD implementation of GET /api/chart/.
These tests drive the TDD implementation of GET /api/chart/ and GET /api/tz/.
They verify the HTTP contract using Django's test client.
Run:
@@ -18,6 +18,11 @@ from django.test import TestCase
J2000 = '2000-01-01T12:00:00Z'
LONDON = {'lat': 51.5074, 'lon': -0.1278}
# Well-known coordinates with unambiguous timezone results
NEW_YORK = {'lat': 40.7128, 'lon': -74.0060} # America/New_York
TOKYO = {'lat': 35.6762, 'lon': 139.6503} # Asia/Tokyo
REYKJAVIK = {'lat': 64.1355, 'lon': -21.8954} # Atlantic/Reykjavik
class ChartApiTest(TestCase):
"""GET /api/chart/ — calculate a natal chart from datetime + coordinates."""
@@ -124,3 +129,87 @@ class ChartApiTest(TestCase):
"""House system override is superuser-only; plain requests get 403."""
response = self._get({'dt': J2000, **LONDON, 'house_system': 'P'})
self.assertEqual(response.status_code, 403)
# ── aspects ───────────────────────────────────────────────────────────
def test_chart_returns_aspects_list(self):
data = self._get({'dt': J2000, **LONDON}).json()
self.assertIn('aspects', data)
self.assertIsInstance(data['aspects'], list)
def test_each_aspect_has_required_fields(self):
data = self._get({'dt': J2000, **LONDON}).json()
for aspect in data['aspects']:
with self.subTest(aspect=aspect):
self.assertIn('planet1', aspect)
self.assertIn('planet2', aspect)
self.assertIn('type', aspect)
self.assertIn('angle', aspect)
self.assertIn('orb', aspect)
def test_sun_saturn_trine_present_at_j2000(self):
"""Sun ~280.37° (Capricorn) and Saturn ~40.73° (Taurus) are ~120.36° apart — Trine."""
data = self._get({'dt': J2000, **LONDON}).json()
pairs = {(a['planet1'], a['planet2'], a['type']) for a in data['aspects']}
self.assertIn(('Sun', 'Saturn', 'Trine'), pairs)
class TimezoneApiTest(TestCase):
"""GET /api/tz/ — resolve IANA timezone from lat/lon coordinates."""
def _get(self, params):
return self.client.get('/api/tz/', params)
# ── guards ────────────────────────────────────────────────────────────
def test_returns_400_if_lat_missing(self):
response = self._get({'lon': -74.0060})
self.assertEqual(response.status_code, 400)
def test_returns_400_if_lon_missing(self):
response = self._get({'lat': 40.7128})
self.assertEqual(response.status_code, 400)
def test_returns_400_for_invalid_lat(self):
response = self._get({'lat': 'abc', 'lon': -74.0060})
self.assertEqual(response.status_code, 400)
def test_returns_400_for_out_of_range_lat(self):
response = self._get({'lat': 999, 'lon': -74.0060})
self.assertEqual(response.status_code, 400)
def test_returns_400_for_out_of_range_lon(self):
response = self._get({'lat': 40.7128, 'lon': 999})
self.assertEqual(response.status_code, 400)
# ── response shape ────────────────────────────────────────────────────
def test_returns_200_for_valid_coords(self):
response = self._get(NEW_YORK)
self.assertEqual(response.status_code, 200)
def test_response_is_json(self):
response = self._get(NEW_YORK)
self.assertIn('application/json', response['Content-Type'])
def test_response_contains_timezone_key(self):
data = self._get(NEW_YORK).json()
self.assertIn('timezone', data)
def test_timezone_is_a_string(self):
data = self._get(NEW_YORK).json()
self.assertIsInstance(data['timezone'], str)
# ── correctness ───────────────────────────────────────────────────────
def test_new_york_timezone(self):
data = self._get(NEW_YORK).json()
self.assertEqual(data['timezone'], 'America/New_York')
def test_tokyo_timezone(self):
data = self._get(TOKYO).json()
self.assertEqual(data['timezone'], 'Asia/Tokyo')
def test_reykjavik_timezone(self):
data = self._get(REYKJAVIK).json()
self.assertEqual(data['timezone'], 'Atlantic/Reykjavik')

View File

@@ -0,0 +1,148 @@
"""
Unit tests for calc.py helper functions.
These tests verify pure calculation logic without hitting the database
or the Swiss Ephemeris — all inputs are fixed synthetic data.
Run:
pyswiss/.venv/Scripts/python pyswiss/manage.py test pyswiss/apps/charts
"""
from django.test import SimpleTestCase
from apps.charts.calc import calculate_aspects
# ---------------------------------------------------------------------------
# Synthetic planet data — degrees chosen for predictable aspects
# Matches FAKE_PLANETS in test_populate_ephemeris.py
# ---------------------------------------------------------------------------
FAKE_PLANETS = {
'Sun': {'degree': 10.0}, # Aries
'Moon': {'degree': 130.0}, # Leo — 120° from Sun → Trine
'Mercury': {'degree': 250.0}, # Sagittarius — 120° from Sun → Trine
'Venus': {'degree': 40.0}, # Taurus — 90° from Moon → Square
'Mars': {'degree': 160.0}, # Virgo — 60° from Neptune → Sextile
'Jupiter': {'degree': 280.0}, # Capricorn — 120° from Mars → Trine
'Saturn': {'degree': 70.0}, # Gemini — 120° from Uranus → Trine
'Uranus': {'degree': 310.0}, # Aquarius — 60° from Sun (wrap) → Sextile
'Neptune': {'degree': 100.0}, # Cancer
'Pluto': {'degree': 340.0}, # Pisces
}
def _aspect_pairs(aspects):
"""Return a set of (planet1, planet2, type) tuples for easy assertion."""
return {(a['planet1'], a['planet2'], a['type']) for a in aspects}
class CalculateAspectsTest(SimpleTestCase):
def setUp(self):
self.aspects = calculate_aspects(FAKE_PLANETS)
# ── return shape ──────────────────────────────────────────────────────
def test_returns_a_list(self):
self.assertIsInstance(self.aspects, list)
def test_each_aspect_has_required_keys(self):
for aspect in self.aspects:
with self.subTest(aspect=aspect):
self.assertIn('planet1', aspect)
self.assertIn('planet2', aspect)
self.assertIn('type', aspect)
self.assertIn('angle', aspect)
self.assertIn('orb', aspect)
def test_each_aspect_type_is_a_known_name(self):
known = {'Conjunction', 'Sextile', 'Square', 'Trine', 'Opposition'}
for aspect in self.aspects:
with self.subTest(aspect=aspect):
self.assertIn(aspect['type'], known)
def test_angle_and_orb_are_floats(self):
for aspect in self.aspects:
with self.subTest(aspect=aspect):
self.assertIsInstance(aspect['angle'], float)
self.assertIsInstance(aspect['orb'], float)
def test_no_self_aspects(self):
for aspect in self.aspects:
self.assertNotEqual(aspect['planet1'], aspect['planet2'])
def test_no_duplicate_pairs(self):
pairs = [(a['planet1'], a['planet2']) for a in self.aspects]
self.assertEqual(len(pairs), len(set(pairs)))
# ── known aspects in FAKE_PLANETS ────────────────────────────────────
def test_sun_moon_trine(self):
"""Moon at 130° is exactly 120° from Sun at 10°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Sun', 'Moon', 'Trine'), pairs)
def test_sun_mercury_trine(self):
"""Mercury at 250° wraps to 120° from Sun at 10° (360-250+10=120)."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Sun', 'Mercury', 'Trine'), pairs)
def test_moon_mercury_trine(self):
"""Moon 130° → Mercury 250° = 120°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Moon', 'Mercury', 'Trine'), pairs)
def test_moon_venus_square(self):
"""Moon 130° → Venus 40° = 90°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Moon', 'Venus', 'Square'), pairs)
def test_venus_neptune_sextile(self):
"""Venus 40° → Neptune 100° = 60°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Venus', 'Neptune', 'Sextile'), pairs)
def test_mars_neptune_sextile(self):
"""Mars 160° → Neptune 100° = 60°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Mars', 'Neptune', 'Sextile'), pairs)
def test_sun_uranus_sextile(self):
"""Sun 10° → Uranus 310° — angle = |10-310| = 300° → 360-300 = 60°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Sun', 'Uranus', 'Sextile'), pairs)
def test_mars_jupiter_trine(self):
"""Mars 160° → Jupiter 280° = 120°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Mars', 'Jupiter', 'Trine'), pairs)
def test_saturn_uranus_trine(self):
"""Saturn 70° → Uranus 310° = |70-310| = 240° → 360-240 = 120°."""
pairs = _aspect_pairs(self.aspects)
self.assertIn(('Saturn', 'Uranus', 'Trine'), pairs)
# ── orb bounds ────────────────────────────────────────────────────────
def test_orb_is_within_allowed_maximum(self):
max_orbs = {
'Conjunction': 8.0,
'Sextile': 6.0,
'Square': 8.0,
'Trine': 8.0,
'Opposition': 10.0,
}
for aspect in self.aspects:
with self.subTest(aspect=aspect):
self.assertLessEqual(
aspect['orb'], max_orbs[aspect['type']],
msg=f"{aspect['planet1']}-{aspect['planet2']} orb exceeds maximum",
)
def test_exact_trine_has_zero_orb(self):
"""Sun-Moon at exactly 120° should report orb of 0.0."""
sun_moon = next(
a for a in self.aspects
if a['planet1'] == 'Sun' and a['planet2'] == 'Moon'
)
self.assertAlmostEqual(sun_moon['orb'], 0.0, places=5)

View File

@@ -4,4 +4,5 @@ from . import views
urlpatterns = [
path('chart/', views.chart, name='chart'),
path('charts/', views.charts_list, name='charts_list'),
path('tz/', views.timezone_lookup, name='timezone_lookup'),
]

View File

@@ -1,11 +1,13 @@
from datetime import datetime, timezone
from django.http import HttpResponse, JsonResponse
from timezonefinder import TimezoneFinder
import swisseph as swe
from .calc import (
DEFAULT_HOUSE_SYSTEM,
calculate_aspects,
get_element_counts,
get_julian_day,
get_planet_positions,
@@ -61,10 +63,41 @@ def chart(request):
'planets': planets,
'houses': houses,
'elements': get_element_counts(planets),
'aspects': calculate_aspects(planets),
'house_system': house_system,
})
_tf = TimezoneFinder()
def timezone_lookup(request):
"""GET /api/tz/ — resolve IANA timezone string from lat/lon.
Query params: lat (float), lon (float)
Returns: { "timezone": "America/New_York" }
Returns 404 JSON { "timezone": null } if coordinates fall in international
waters (no timezone found) — not an error, just no result.
"""
lat_str = request.GET.get('lat')
lon_str = request.GET.get('lon')
if lat_str is None or lon_str is None:
return HttpResponse(status=400)
try:
lat = float(lat_str)
lon = float(lon_str)
except ValueError:
return HttpResponse(status=400)
if not (-90 <= lat <= 90) or not (-180 <= lon <= 180):
return HttpResponse(status=400)
tz = _tf.timezone_at(lat=lat, lng=lon)
return JsonResponse({'timezone': tz})
def charts_list(request):
date_from_str = request.GET.get('date_from')
date_to_str = request.GET.get('date_to')