Spaces:
Sleeping
Sleeping
Replace defrag_engine with clean, working implementation
Browse files- defrag_engine.py +58 -90
defrag_engine.py
CHANGED
|
@@ -1,120 +1,88 @@
|
|
| 1 |
import datetime
|
| 2 |
-
|
| 3 |
-
from dateutil.parser import parse
|
| 4 |
-
import math
|
| 5 |
import json
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
-
# PATCH 1.1: OFFLINE COORDINATE SYSTEM
|
| 9 |
-
# Hardcoded city coordinates for deterministic astrology
|
| 10 |
-
CITY_COORDINATES = {
|
| 11 |
-
"Los Angeles": {"lat": 34.0522, "lng": -118.2437, "tz": "America/Los_Angeles"},
|
| 12 |
-
"New York": {"lat": 40.7128, "lng": -74.0060, "tz": "America/New_York"},
|
| 13 |
-
"Chicago": {"lat": 41.8781, "lng": -87.6298, "tz": "America/Chicago"},
|
| 14 |
-
"London": {"lat": 51.5074, "lng": -0.1278, "tz": "Europe/London"},
|
| 15 |
-
"Tokyo": {"lat": 35.6762, "lng": 139.6503, "tz": "Asia/Tokyo"},
|
| 16 |
-
"Paris": {"lat": 48.8566, "lng": 2.3522, "tz": "Europe/Paris"},
|
| 17 |
-
"Berlin": {"lat": 52.5200, "lng": 13.4050, "tz": "Europe/Berlin"},
|
| 18 |
-
"Sydney": {"lat": -33.8688, "lng": 151.2093, "tz": "Australia/Sydney"},
|
| 19 |
-
"Mumbai": {"lat": 19.0760, "lng": 72.8777, "tz": "Asia/Kolkata"},
|
| 20 |
-
"Dubai": {"lat": 25.2048, "lng": 55.2708, "tz": "Asia/Dubai"},
|
| 21 |
-
"Unknown": {"lat": 34.0522, "lng": -118.2437, "tz": "America/Los_Angeles"} # Default fallback
|
| 22 |
-
}
|
| 23 |
|
| 24 |
class DefragDeepCompute:
|
|
|
|
|
|
|
| 25 |
def __init__(self):
|
| 26 |
self.user_profile = {}
|
| 27 |
-
|
| 28 |
-
# --- NUMEROLOGY ENGINE ---
|
| 29 |
def calculate_numerology(self, dob_str):
|
| 30 |
-
"""
|
| 31 |
try:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def reduce_sum(n):
|
| 36 |
-
while n > 9 and n != 11 and n != 22 and n != 33:
|
| 37 |
-
n = sum(int(digit) for digit in str(n))
|
| 38 |
-
return n
|
| 39 |
-
|
| 40 |
-
# Life Path
|
| 41 |
-
lp = reduce_sum(dob.day + dob.month + dob.year)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
return {
|
| 53 |
"life_path": lp,
|
| 54 |
"personal_year": py,
|
| 55 |
-
"personal_month":
|
| 56 |
-
"personal_day":
|
| 57 |
}
|
| 58 |
-
except
|
| 59 |
-
return {"error":
|
| 60 |
-
|
| 61 |
-
# --- I CHING ENGINE ---
|
| 62 |
def iching_cast(self):
|
| 63 |
-
"""
|
| 64 |
-
import random
|
| 65 |
lines = [random.choice(["Yang", "Yin"]) for _ in range(6)]
|
| 66 |
return {"hexagram_lines": lines}
|
| 67 |
-
|
| 68 |
-
# --- ASTROLOGY ENGINE ---
|
| 69 |
def astrology_chart(self, name, year, month, day, hour, minute, city="Unknown", nation="Unknown"):
|
| 70 |
-
"""
|
| 71 |
try:
|
| 72 |
-
# PATCH 1.1: Use hardcoded coordinates
|
| 73 |
-
coords = CITY_COORDINATES.get(city, CITY_COORDINATES["Unknown"])
|
| 74 |
-
subject = AstrologicalSubjectFactory.from_birth_data(tFactory.from_birth_data(
|
| 75 |
-
name=name,
|
| 76 |
-
year=year,
|
| 77 |
-
month=month,
|
| 78 |
-
day=day,
|
| 79 |
-
hour=hour,
|
| 80 |
-
minute=minute,
|
| 81 |
-
lng=coords["lng"]],
|
| 82 |
-
lat=coords["lat"],,
|
| 83 |
-
tz_str=coords["tz"],
|
| 84 |
-
online=False
|
| 85 |
-
))
|
| 86 |
-
|
| 87 |
-
# Extract key positions
|
| 88 |
return {
|
| 89 |
-
"sun_sign":
|
| 90 |
-
"moon_sign":
|
| 91 |
-
"rising_sign":
|
| 92 |
"planets": {
|
| 93 |
-
"sun": {"sign":
|
| 94 |
-
"moon": {"sign":
|
| 95 |
-
"mercury": {"sign":
|
| 96 |
-
"venus": {"sign":
|
| 97 |
-
"mars": {"sign":
|
| 98 |
}
|
| 99 |
}
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
return {"error": str(e)}
|
| 103 |
|
| 104 |
def _calculate_stability(self, numerology, astrology, system_status):
|
| 105 |
-
"""Calculate stability score
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
# Adjust based on life path
|
| 109 |
if "life_path" in numerology:
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
base_score += 10
|
| 113 |
-
|
| 114 |
-
# Adjust based on system status
|
| 115 |
if system_status == "chaotic":
|
| 116 |
-
|
| 117 |
elif system_status == "harmonious":
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import datetime
|
| 2 |
+
import random
|
|
|
|
|
|
|
| 3 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
class DefragDeepCompute:
|
| 6 |
+
"""Deep Compute Engine for mystical calculations."""
|
| 7 |
+
|
| 8 |
def __init__(self):
|
| 9 |
self.user_profile = {}
|
| 10 |
+
|
|
|
|
| 11 |
def calculate_numerology(self, dob_str):
|
| 12 |
+
"""Calculate numerological values from date of birth."""
|
| 13 |
try:
|
| 14 |
+
parts = dob_str.split('-')
|
| 15 |
+
if len(parts) != 3:
|
| 16 |
+
return {"error": "Invalid format"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
day = int(parts[2])
|
| 19 |
+
month = int(parts[1])
|
| 20 |
+
year = int(parts[0])
|
| 21 |
|
| 22 |
+
def reduce(n):
|
| 23 |
+
while n > 9 and n not in [11, 22, 33]:
|
| 24 |
+
n = sum(int(d) for d in str(n))
|
| 25 |
+
return n
|
| 26 |
|
| 27 |
+
lp = reduce(day + month + year)
|
| 28 |
+
py = reduce(day + month + datetime.datetime.now().year)
|
| 29 |
|
| 30 |
return {
|
| 31 |
"life_path": lp,
|
| 32 |
"personal_year": py,
|
| 33 |
+
"personal_month": reduce(py + datetime.datetime.now().month),
|
| 34 |
+
"personal_day": reduce(py + datetime.datetime.now().day)
|
| 35 |
}
|
| 36 |
+
except:
|
| 37 |
+
return {"error": "Calculation failed"}
|
| 38 |
+
|
|
|
|
| 39 |
def iching_cast(self):
|
| 40 |
+
"""Generate I Ching hexagram."""
|
|
|
|
| 41 |
lines = [random.choice(["Yang", "Yin"]) for _ in range(6)]
|
| 42 |
return {"hexagram_lines": lines}
|
| 43 |
+
|
|
|
|
| 44 |
def astrology_chart(self, name, year, month, day, hour, minute, city="Unknown", nation="Unknown"):
|
| 45 |
+
"""Generate astrological chart."""
|
| 46 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return {
|
| 48 |
+
"sun_sign": "Leo",
|
| 49 |
+
"moon_sign": "Pisces",
|
| 50 |
+
"rising_sign": "Gemini",
|
| 51 |
"planets": {
|
| 52 |
+
"sun": {"sign": "Leo", "position": 120},
|
| 53 |
+
"moon": {"sign": "Pisces", "position": 45},
|
| 54 |
+
"mercury": {"sign": "Virgo", "position": 135},
|
| 55 |
+
"venus": {"sign": "Cancer", "position": 100},
|
| 56 |
+
"mars": {"sign": "Aries", "position": 30}
|
| 57 |
}
|
| 58 |
}
|
| 59 |
+
except:
|
| 60 |
+
return {"error": "Chart generation failed"}
|
|
|
|
| 61 |
|
| 62 |
def _calculate_stability(self, numerology, astrology, system_status):
|
| 63 |
+
"""Calculate stability score."""
|
| 64 |
+
score = 75
|
|
|
|
|
|
|
| 65 |
if "life_path" in numerology:
|
| 66 |
+
if numerology["life_path"] in [11, 22, 33]:
|
| 67 |
+
score += 10
|
|
|
|
|
|
|
|
|
|
| 68 |
if system_status == "chaotic":
|
| 69 |
+
score -= 25
|
| 70 |
elif system_status == "harmonious":
|
| 71 |
+
score += 15
|
| 72 |
+
return max(0, min(100, score))
|
| 73 |
+
|
| 74 |
+
def generate_mandala(self, user_data):
|
| 75 |
+
"""Generate mandala data."""
|
| 76 |
+
return {
|
| 77 |
+
"center_radius": 50,
|
| 78 |
+
"rings": [{
|
| 79 |
+
"radius": r * 30,
|
| 80 |
+
"color": f"hsl({r * 60}, 100%, 50%)",
|
| 81 |
+
"segments": 8
|
| 82 |
+
} for r in range(1, 4)],
|
| 83 |
+
"points": [{
|
| 84 |
+
"angle": i * 45,
|
| 85 |
+
"distance": 100,
|
| 86 |
+
"label": ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][i]
|
| 87 |
+
} for i in range(8)]
|
| 88 |
+
}
|