Spaces:
Sleeping
Sleeping
Update defrag_engine.py
Browse files- defrag_engine.py +87 -95
defrag_engine.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import datetime
|
| 2 |
-
|
| 3 |
-
from kerykeion import Report
|
| 4 |
from dateutil.parser import parse
|
| 5 |
import math
|
| 6 |
import json
|
|
@@ -9,7 +8,7 @@ import os
|
|
| 9 |
class DefragDeepCompute:
|
| 10 |
def __init__(self):
|
| 11 |
self.user_profile = {}
|
| 12 |
-
|
| 13 |
# --- NUMEROLOGY ENGINE ---
|
| 14 |
def calculate_numerology(self, dob_str):
|
| 15 |
"""Calculates Life Path and Personal Year/Month/Day."""
|
|
@@ -21,7 +20,7 @@ class DefragDeepCompute:
|
|
| 21 |
while n > 9 and n != 11 and n != 22 and n != 33:
|
| 22 |
n = sum(int(digit) for digit in str(n))
|
| 23 |
return n
|
| 24 |
-
|
| 25 |
# Life Path
|
| 26 |
lp = reduce_sum(dob.day + dob.month + dob.year)
|
| 27 |
|
|
@@ -40,107 +39,100 @@ class DefragDeepCompute:
|
|
| 40 |
"personal_month": pm,
|
| 41 |
"personal_day": pd
|
| 42 |
}
|
| 43 |
-
except:
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# --- ASTROLOGY ENGINE ---
|
| 48 |
-
def
|
| 49 |
-
"""
|
| 50 |
try:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
-
"
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
elements[signs_element.get(sun_sign, "Fire")] += 2
|
| 71 |
-
elements[signs_element.get(moon_sign, "Water")] += 2
|
| 72 |
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
"
|
| 78 |
-
"
|
| 79 |
-
"
|
| 80 |
-
"
|
|
|
|
|
|
|
|
|
|
| 81 |
}
|
|
|
|
|
|
|
| 82 |
except Exception as e:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
"""
|
| 89 |
-
Approximates HD Profile based on Sun position logic stub.
|
| 90 |
-
"""
|
| 91 |
-
return {
|
| 92 |
-
"type": "Generator",
|
| 93 |
-
"strategy": "Wait to Respond",
|
| 94 |
-
"authority": "Sacral",
|
| 95 |
-
"profile": "5/1"
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
# --- HEXAGRAM ENGINE ---
|
| 99 |
-
def get_current_hexagram(self):
|
| 100 |
-
"""
|
| 101 |
-
Calculates the I-Ching Hexagram based on current transit Sun (Day of Year).
|
| 102 |
-
"""
|
| 103 |
-
day_of_year = datetime.datetime.now().timetuple().tm_yday
|
| 104 |
-
gate = (day_of_year % 64) + 1
|
| 105 |
|
| 106 |
-
#
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
"hexagram_binary": binary
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
# --- MASTER SYNTH ---
|
| 115 |
-
def run_deep_compute(self, name, dob, time, loc, user_input):
|
| 116 |
-
astro = self.calculate_astrology(name, dob, time, loc)
|
| 117 |
-
nums = self.calculate_numerology(dob)
|
| 118 |
-
hd = self.calculate_human_design(dob, time)
|
| 119 |
-
hex_data = self.get_current_hexagram()
|
| 120 |
|
| 121 |
-
#
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
# The Soul Log
|
| 127 |
-
soul_log = {
|
| 128 |
-
"timestamp": datetime.datetime.now().isoformat(),
|
| 129 |
-
"user_input": user_input,
|
| 130 |
-
"hardware": {
|
| 131 |
-
"hd": hd,
|
| 132 |
-
"numerology": nums
|
| 133 |
-
},
|
| 134 |
-
"weather": {
|
| 135 |
-
"astro": astro,
|
| 136 |
-
"hexagram": hex_data
|
| 137 |
-
},
|
| 138 |
-
"computed_vector": {
|
| 139 |
-
"friction_level": friction,
|
| 140 |
-
"visual_seed": nums['personal_day'],
|
| 141 |
-
"visual_element": astro['dominant_element'],
|
| 142 |
-
"visual_code": hex_data['hexagram_binary']
|
| 143 |
-
}
|
| 144 |
-
}
|
| 145 |
|
| 146 |
-
return
|
|
|
|
| 1 |
import datetime
|
| 2 |
+
from kerykeion import AstrologicalSubjectFactory
|
|
|
|
| 3 |
from dateutil.parser import parse
|
| 4 |
import math
|
| 5 |
import json
|
|
|
|
| 8 |
class DefragDeepCompute:
|
| 9 |
def __init__(self):
|
| 10 |
self.user_profile = {}
|
| 11 |
+
|
| 12 |
# --- NUMEROLOGY ENGINE ---
|
| 13 |
def calculate_numerology(self, dob_str):
|
| 14 |
"""Calculates Life Path and Personal Year/Month/Day."""
|
|
|
|
| 20 |
while n > 9 and n != 11 and n != 22 and n != 33:
|
| 21 |
n = sum(int(digit) for digit in str(n))
|
| 22 |
return n
|
| 23 |
+
|
| 24 |
# Life Path
|
| 25 |
lp = reduce_sum(dob.day + dob.month + dob.year)
|
| 26 |
|
|
|
|
| 39 |
"personal_month": pm,
|
| 40 |
"personal_day": pd
|
| 41 |
}
|
| 42 |
+
except Exception as e:
|
| 43 |
+
return {"error": str(e)}
|
| 44 |
+
|
| 45 |
+
# --- I CHING ENGINE ---
|
| 46 |
+
def iching_cast(self):
|
| 47 |
+
"""Casts a 6-line hexagram."""
|
| 48 |
+
import random
|
| 49 |
+
lines = [random.choice(["Yang", "Yin"]) for _ in range(6)]
|
| 50 |
+
return {"hexagram_lines": lines}
|
| 51 |
|
| 52 |
# --- ASTROLOGY ENGINE ---
|
| 53 |
+
def astrology_chart(self, name, year, month, day, hour, minute, city="Unknown", nation="Unknown"):
|
| 54 |
+
"""Uses kerykeion to calculate natal chart."""
|
| 55 |
try:
|
| 56 |
+
subject = AstrologicalSubjectFactory.from_birth_data(
|
| 57 |
+
name=name,
|
| 58 |
+
year=year,
|
| 59 |
+
month=month,
|
| 60 |
+
day=day,
|
| 61 |
+
hour=hour,
|
| 62 |
+
minute=minute,
|
| 63 |
+
city=city,
|
| 64 |
+
nation=nation,
|
| 65 |
+
online=False
|
| 66 |
+
)
|
| 67 |
|
| 68 |
+
# Extract key positions
|
| 69 |
+
return {
|
| 70 |
+
"sun_sign": subject.sun.sign if hasattr(subject, 'sun') else "Unknown",
|
| 71 |
+
"moon_sign": subject.moon.sign if hasattr(subject, 'moon') else "Unknown",
|
| 72 |
+
"rising_sign": subject.first_house.sign if hasattr(subject, 'first_house') else "Unknown",
|
| 73 |
+
"planets": {
|
| 74 |
+
"sun": {"sign": subject.sun.sign, "position": subject.sun.position} if hasattr(subject, 'sun') else {},
|
| 75 |
+
"moon": {"sign": subject.moon.sign, "position": subject.moon.position} if hasattr(subject, 'moon') else {},
|
| 76 |
+
"mercury": {"sign": subject.mercury.sign, "position": subject.mercury.position} if hasattr(subject, 'mercury') else {},
|
| 77 |
+
"venus": {"sign": subject.venus.sign, "position": subject.venus.position} if hasattr(subject, 'venus') else {},
|
| 78 |
+
"mars": {"sign": subject.mars.sign, "position": subject.mars.position} if hasattr(subject, 'mars') else {}
|
| 79 |
+
}
|
| 80 |
}
|
| 81 |
+
except Exception as e:
|
| 82 |
+
return {"error": str(e)}
|
| 83 |
+
|
| 84 |
+
# --- MASTER COMPUTE ---
|
| 85 |
+
def execute_defrag(self, birth_data, system_status="normal"):
|
| 86 |
+
"""Master function that runs all engines and returns Soul Log."""
|
| 87 |
+
try:
|
| 88 |
+
# Parse birth data
|
| 89 |
+
name = birth_data.get("name", "User")
|
| 90 |
+
dob_str = birth_data.get("dob")
|
| 91 |
+
year = birth_data.get("year")
|
| 92 |
+
month = birth_data.get("month")
|
| 93 |
+
day = birth_data.get("day")
|
| 94 |
+
hour = birth_data.get("hour", 12)
|
| 95 |
+
minute = birth_data.get("minute", 0)
|
| 96 |
+
city = birth_data.get("city", "Unknown")
|
| 97 |
+
nation = birth_data.get("nation", "US")
|
| 98 |
|
| 99 |
+
# Run engines
|
| 100 |
+
numerology = self.calculate_numerology(dob_str)
|
| 101 |
+
iching = self.iching_cast()
|
| 102 |
+
astrology = self.astrology_chart(name, year, month, day, hour, minute, city, nation)
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
# Calculate stability score (0-100)
|
| 105 |
+
stability = self._calculate_stability(numerology, astrology, system_status)
|
| 106 |
|
| 107 |
+
# Generate Soul Log
|
| 108 |
+
soul_log = {
|
| 109 |
+
"timestamp": datetime.datetime.now().isoformat(),
|
| 110 |
+
"user": name,
|
| 111 |
+
"numerology": numerology,
|
| 112 |
+
"iching": iching,
|
| 113 |
+
"astrology": astrology,
|
| 114 |
+
"stability_score": stability,
|
| 115 |
+
"system_status": system_status
|
| 116 |
}
|
| 117 |
+
|
| 118 |
+
return soul_log
|
| 119 |
except Exception as e:
|
| 120 |
+
return {"error": str(e)}
|
| 121 |
+
|
| 122 |
+
def _calculate_stability(self, numerology, astrology, system_status):
|
| 123 |
+
"""Calculate stability score based on various factors."""
|
| 124 |
+
base_score = 75
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
+
# Adjust based on life path
|
| 127 |
+
if "life_path" in numerology:
|
| 128 |
+
lp = numerology["life_path"]
|
| 129 |
+
if lp in [11, 22, 33]:
|
| 130 |
+
base_score += 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
# Adjust based on system status
|
| 133 |
+
if system_status == "chaotic":
|
| 134 |
+
base_score -= 25
|
| 135 |
+
elif system_status == "harmonious":
|
| 136 |
+
base_score += 15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
+
return max(0, min(100, base_score))
|