File size: 1,792 Bytes
03f0588
 
 
 
 
 
 
 
 
 
d209765
0ad9f78
9565193
 
0ad9f78
 
 
9565193
 
0ad9f78
 
 
 
d209765
0ad9f78
9565193
0ad9f78
9565193
e537d07
 
 
 
0ad9f78
 
e537d07
 
 
 
 
 
 
0ad9f78
9565193
0ad9f78
e537d07
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import swisseph as swe
import math
import datetime
import os
from .models import GeoLocation, PlanetPosition, HexagramAddress, CognitiveProfile

class PrecisionEngine:
    def __init__(self):
        ephe_path = os.getenv("SE_EPHE_PATH", "/app/ephe")
        swe.set_ephe_path(ephe_path)

    def _get_julian_day(self, dt):
        decimal_hour = dt.hour + dt.minute / 60.0 + dt.second / 3600.0
        return swe.julday(dt.year, dt.month, dt.day, decimal_hour)

    def _decode_fractal(self, longitude):
        gate = int((longitude % 360) / 360 * 64) + 1
        line = int((longitude % (360 / 64)) / (360 / 64) * 6) + 1
        return HexagramAddress(gate=gate, line=line, color=1, tone=1, base=1)

    def calculate_chart(self, natal_dt, location):
        jd = self._get_julian_day(natal_dt)
        result = {}
        planet_ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        planet_names = ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']
        for pid, name in zip(planet_ids, planet_names):
            try:
                res, _ = swe.calc_ut(jd, pid)
                lon = res[0]
                lat = res[1]
                speed = res[3]
                fractal = self._decode_fractal(lon)
                result[name] = PlanetPosition(
                    name=name,
                    longitude=lon,
                    latitude=lat,
                    speed=speed,
                    house=int(((lon + 30) % 360) / 30),
                    is_retrograde=speed < 0,
                    gate=fractal.gate,
                    line=fractal.line
                )
            except: pass
        return result

    def get_live_overlay(self):
        now = datetime.datetime.utcnow()
        return self.calculate_chart(now, None)