cjo93 commited on
Commit
f2963c4
·
verified ·
1 Parent(s): 5630077

Update defrag_engine.py

Browse files
Files changed (1) hide show
  1. defrag_engine.py +50 -38
defrag_engine.py CHANGED
@@ -1,5 +1,6 @@
1
  import datetime
2
- from kerykeion import AstrologicalSubject, KerykeionChartSVG
 
3
  from dateutil.parser import parse
4
  import math
5
  import json
@@ -12,43 +13,48 @@ class DefragDeepCompute:
12
  # --- NUMEROLOGY ENGINE ---
13
  def calculate_numerology(self, dob_str):
14
  """Calculates Life Path and Personal Year/Month/Day."""
15
- dob = parse(dob_str)
16
- today = datetime.datetime.now()
17
-
18
- def reduce_sum(n):
19
- while n > 9 and n != 11 and n != 22 and n != 33:
20
- n = sum(int(digit) for digit in str(n))
21
- return n
 
22
 
23
- # Life Path
24
- lp = reduce_sum(dob.day + dob.month + dob.year)
25
-
26
- # Personal Year
27
- py = reduce_sum(dob.day + dob.month + today.year)
28
-
29
- # Personal Month
30
- pm = reduce_sum(py + today.month)
31
-
32
- # Personal Day
33
- pd = reduce_sum(pm + today.day)
34
-
35
- return {
36
- "life_path": lp,
37
- "personal_year": py,
38
- "personal_month": pm,
39
- "personal_day": pd
40
- }
 
 
 
41
 
42
  # --- ASTROLOGY ENGINE ---
43
  def calculate_astrology(self, name, dob_str, time_str, city, country_code="US"):
44
- """Calculates Natal Chart and basic Transits."""
45
  try:
 
46
  dt = parse(f"{dob_str} {time_str}")
47
 
48
- # Create Natal Subject
49
- natal = AstrologicalSubject(name, dt.year, dt.month, dt.day, dt.hour, dt.minute, city, country_code)
50
 
51
- # Simple Element Calculation (Based on Sun/Moon)
52
  elements = {"Fire": 0, "Earth": 0, "Air": 0, "Water": 0}
53
  signs_element = {
54
  "Aries": "Fire", "Leo": "Fire", "Sagittarius": "Fire",
@@ -57,6 +63,7 @@ class DefragDeepCompute:
57
  "Cancer": "Water", "Scorpio": "Water", "Pisces": "Water"
58
  }
59
 
 
60
  sun_sign = natal.sun["sign"]
61
  moon_sign = natal.moon["sign"]
62
 
@@ -70,20 +77,19 @@ class DefragDeepCompute:
70
  "moon_sign": moon_sign,
71
  "ascendant": natal.first_house["sign"],
72
  "dominant_element": dominant_element,
73
- "natal_data": natal.json_dump()
74
  }
75
  except Exception as e:
76
  print(f"Astro Error: {e}")
77
- return {"dominant_element": "water", "error": str(e)}
78
 
79
  # --- HUMAN DESIGN ENGINE (STUB) ---
80
  def calculate_human_design(self, dob_str, time_str):
81
  """
82
- Approximates HD Profile based on Sun position.
83
- Real HD requires complex ephemeris, this is a logic stub for the prototype.
84
  """
85
  return {
86
- "type": "Generator",
87
  "strategy": "Wait to Respond",
88
  "authority": "Sacral",
89
  "profile": "5/1"
@@ -92,12 +98,12 @@ class DefragDeepCompute:
92
  # --- HEXAGRAM ENGINE ---
93
  def get_current_hexagram(self):
94
  """
95
- Calculates the I-Ching Hexagram based on current transit Sun.
96
- (Simplified logic: 365 days / 64 gates)
97
  """
98
  day_of_year = datetime.datetime.now().timetuple().tm_yday
99
  gate = (day_of_year % 64) + 1
100
 
 
101
  import random
102
  binary = [random.randint(0,1) for _ in range(6)]
103
  return {
@@ -112,6 +118,12 @@ class DefragDeepCompute:
112
  hd = self.calculate_human_design(dob, time)
113
  hex_data = self.get_current_hexagram()
114
 
 
 
 
 
 
 
115
  soul_log = {
116
  "timestamp": datetime.datetime.now().isoformat(),
117
  "user_input": user_input,
@@ -124,7 +136,7 @@ class DefragDeepCompute:
124
  "hexagram": hex_data
125
  },
126
  "computed_vector": {
127
- "friction_level": "CRITICAL" if nums['personal_day'] == 5 else "STABLE",
128
  "visual_seed": nums['personal_day'],
129
  "visual_element": astro['dominant_element'],
130
  "visual_code": hex_data['hexagram_binary']
 
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
 
13
  # --- NUMEROLOGY ENGINE ---
14
  def calculate_numerology(self, dob_str):
15
  """Calculates Life Path and Personal Year/Month/Day."""
16
+ try:
17
+ dob = parse(dob_str)
18
+ today = datetime.datetime.now()
19
+
20
+ def reduce_sum(n):
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
+
28
+ # Personal Year
29
+ py = reduce_sum(dob.day + dob.month + today.year)
30
+
31
+ # Personal Month
32
+ pm = reduce_sum(py + today.month)
33
+
34
+ # Personal Day
35
+ pd = reduce_sum(pm + today.day)
36
+
37
+ return {
38
+ "life_path": lp,
39
+ "personal_year": py,
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",
 
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
 
 
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"
 
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 {
 
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,
 
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']