cjo93 commited on
Commit
84e48a0
·
verified ·
1 Parent(s): 98323c0

Update defrag_engine.py

Browse files
Files changed (1) hide show
  1. defrag_engine.py +87 -95
defrag_engine.py CHANGED
@@ -1,6 +1,5 @@
1
  import datetime
2
- # FIXED IMPORT: Uses 'Report' class for kerykeion > 2.0
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
- # Fallback if date parse fails
45
- return {"life_path": 1, "personal_year": 1, "personal_month": 1, "personal_day": 1}
 
 
 
 
 
 
46
 
47
  # --- ASTROLOGY ENGINE ---
48
- def calculate_astrology(self, name, dob_str, time_str, city, country_code="US"):
49
- """Calculates Natal Chart using Kerykeion Report class."""
50
  try:
51
- # Parse Date
52
- dt = parse(f"{dob_str} {time_str}")
53
-
54
- # FIXED INITIALIZATION: Using Report class
55
- natal = Report(name, dt.year, dt.month, dt.day, dt.hour, dt.minute, city, country_code)
 
 
 
 
 
 
56
 
57
- # Simple Element Calculation (Based on Sun/Moon signs)
58
- elements = {"Fire": 0, "Earth": 0, "Air": 0, "Water": 0}
59
- signs_element = {
60
- "Aries": "Fire", "Leo": "Fire", "Sagittarius": "Fire",
61
- "Taurus": "Earth", "Virgo": "Earth", "Capricorn": "Earth",
62
- "Gemini": "Air", "Libra": "Air", "Aquarius": "Air",
63
- "Cancer": "Water", "Scorpio": "Water", "Pisces": "Water"
 
 
 
 
 
64
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- # Kerykeion returns signs as strings (e.g., "Scorpio")
67
- sun_sign = natal.sun["sign"]
68
- moon_sign = natal.moon["sign"]
69
-
70
- elements[signs_element.get(sun_sign, "Fire")] += 2
71
- elements[signs_element.get(moon_sign, "Water")] += 2
72
 
73
- dominant_element = max(elements, key=elements.get).lower()
 
74
 
75
- return {
76
- "sun_sign": sun_sign,
77
- "moon_sign": moon_sign,
78
- "ascendant": natal.first_house["sign"],
79
- "dominant_element": dominant_element,
80
- "natal_data": "Full chart data calculated"
 
 
 
81
  }
 
 
82
  except Exception as e:
83
- print(f"Astro Error: {e}")
84
- return {"dominant_element": "water", "error": str(e), "sun_sign": "Unknown", "moon_sign": "Unknown"}
85
-
86
- # --- HUMAN DESIGN ENGINE (STUB) ---
87
- def calculate_human_design(self, dob_str, time_str):
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
- # Generates a random binary structure for visual prototype
107
- import random
108
- binary = [random.randint(0,1) for _ in range(6)]
109
- return {
110
- "gate": gate,
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
- # Calculate Friction Level based on Numerology Cycle
122
- friction = "STABLE"
123
- if nums['personal_day'] == 5 or nums['personal_day'] == 7:
124
- friction = "CRITICAL"
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 soul_log
 
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))