-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
310 lines (254 loc) · 12.5 KB
/
main.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import math
import numpy as np
import pandas as pd
from datetime import datetime, timedelta
from sims4_globe import Sims4Globe
class SimNatalChart:
ZODIAC_SIGNS = [
"Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra",
"Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"
]
HOUSES = range(1, 13)
def __init__(self, sim_age, birth_location, current_sim_day, sim_year_days=28, sim_season_days=7):
self.sim_age = sim_age
self.birth_location = birth_location
self.current_sim_day = current_sim_day
self.SIM_YEAR_DAYS = sim_year_days
self.SIM_SEASON_DAYS = sim_season_days
self.birthdate = self.calculate_birthdate()
self.jd = self.julian_date(self.birthdate)
def calculate_birthdate(self):
total_days_current_year = self.current_sim_day
full_years_passed = total_days_current_year // self.SIM_YEAR_DAYS
remaining_days = total_days_current_year % self.SIM_YEAR_DAYS
birth_year = full_years_passed - (self.sim_age // self.SIM_YEAR_DAYS)
birth_day_of_year = remaining_days - (self.sim_age % self.SIM_YEAR_DAYS)
# Adjust for negative days in year calculation
while birth_day_of_year < 0:
birth_year -= 1
birth_day_of_year += self.SIM_YEAR_DAYS
return (birth_year, birth_day_of_year)
def convert_birthdate_to_days(self, birthdate):
if isinstance(birthdate, tuple):
year, day_of_year = birthdate
return year * self.SIM_YEAR_DAYS + day_of_year
days_from_start = (birthdate - datetime(year=birthdate.year, month=1, day=1)).days
return birthdate.year * self.SIM_YEAR_DAYS + days_from_start
def julian_date(self, date):
if isinstance(date, tuple):
year, day_of_year = date
return self.bce_to_julian_date(year, day_of_year)
a = (14 - date.month) // 12
y = date.year + 4800 - a
m = date.month + 12 * a - 3
jdn = date.day + ((153 * m + 2) // 5) + 365 * y + y // 4 - y // 100 + y // 400 - 32045
return jdn + (date.hour - 12) / 24 + date.minute / 1440 + date.second / 86400
def bce_to_julian_date(self, year, day_of_year):
jd_start_of_year = self.julian_date(datetime(year=1, month=1, day=1)) - (year * 365.25)
return jd_start_of_year + day_of_year
def calculate_planetary_positions(self, jd):
def calc_position(L, g):
L = (L + 1.915 * math.sin(math.radians(g)) + 0.020 * math.sin(math.radians(2 * g))) % 360
return L
def planet_position(jd, L0, g0, n0, rateL, rateg):
n = jd - 2451545.0
L = (L0 + rateL * n) % 360
g = (g0 + rateg * n) % 360
return calc_position(L, g)
positions = {
"sun": planet_position(jd, 280.460, 357.528, 0, 0.9856474, 0.98560028),
"moon": planet_position(jd, 218.316, 134.963, 0, 13.176396, 13.176396),
"mercury": planet_position(jd, 252.250, 77.456, 0, 4.0923388, 4.0923388),
"venus": planet_position(jd, 181.979, 131.563, 0, 1.6021303, 1.6021303),
"mars": planet_position(jd, 355.433, 336.040, 0, 0.5240208, 0.5240208),
"jupiter": planet_position(jd, 34.351, 14.331, 0, 0.083091, 0.083091),
"saturn": planet_position(jd, 50.077, 93.056, 0, 0.033459, 0.033459),
"uranus": planet_position(jd, 314.055, 173.005, 0, 0.011733, 0.011733),
"neptune": planet_position(jd, 304.348, 48.123, 0, 0.006021, 0.006021),
"pluto": planet_position(jd, 238.929, 224.066, 0, 0.003963, 0.003963),
"north_node": planet_position(jd, 174.873, 123.448, 0, 0.001479, 0.001479),
"south_node": planet_position(jd, 354.873, 243.448, 0, 0.001479, 0.001479),
"lilith": planet_position(jd, 120.982, 142.102, 0, 0.004925, 0.004925),
"chiron": planet_position(jd, 209.515, 172.439, 0, 0.007166, 0.007166),
"fortune": planet_position(jd, 238.929, 224.066, 0, 0.003963, 0.003963),
"vertex": planet_position(jd, 238.929, 224.066, 0, 0.003963, 0.003963)
}
E, w, A = 90, 23.44, self.birth_location['latitude']
ascendant = math.degrees(
math.atan(
math.sin(math.radians(E)) /
(math.cos(math.radians(E)) * math.cos(math.radians(w)) -
math.sin(math.radians(w)) * math.tan(math.radians(A)))))
mc = math.degrees(
math.atan(math.tan(math.radians(90)) / math.cos(math.radians(w))))
positions.update({
"midheaven": mc,
"ascendant": ascendant,
"descendant": (ascendant + 180) % 360,
"ic": (mc + 180) % 360
})
return positions
def generate_natal_chart(self):
planetary_positions = self.calculate_planetary_positions(self.jd)
zodiac_chart = self.assign_to_zodiac_and_houses(planetary_positions)
formatted_birthdate = format_birthdate(self.birthdate, self.SIM_SEASON_DAYS)
return {
'planetary_positions': zodiac_chart,
'formatted_birthdate': formatted_birthdate
}
def assign_to_zodiac_and_houses(self, planetary_positions):
zodiac_chart = {}
for planet, position in planetary_positions.items():
sign_index = int(position // 30)
house = (sign_index + 1) % 12 + 1
zodiac_chart[planet] = {
"sign": self.ZODIAC_SIGNS[sign_index],
"house": house
}
return zodiac_chart
class CreateLegacyChallenge:
def __init__(self, natal_chart):
self.natal_chart = natal_chart
def filter_natal_chart(self):
result_text = ""
file_path = 'static/natal_planets_houses_allzodiacs.xlsx'
df = pd.read_excel(file_path, engine='openpyxl')
matching_rows = []
natal_chart = self.natal_chart
for planet, info in natal_chart.items():
if isinstance(info, dict):
matches = df[(df['Planet'] == planet.title())
& (df['Zodiac'] == info['sign']) &
(df['House'] == info['house'])]
matching_rows.append(matches)
if matching_rows:
result_df = pd.concat(matching_rows)
else:
print("No matching rows found.")
return set(), set(), set(), {}, {}, []
columns_of_interest = [
'Trait(s)', 'Aspiration(s)', 'Career', 'Best Skill(s)',
'Worst Skill(s)', 'Rule(s)'
]
result_df = result_df[columns_of_interest]
traits_counts, aspirations_set, careers_set = {}, set(), set()
best_skills_counts, worst_skills_counts, rules_list = {}, {}, []
separators = [',', '.']
aspiration_counts = {}
career_counts = {}
rule_counts = {}
for _, row in result_df.iterrows():
traits = row['Trait(s)'].split(', ')
aspirations = row['Aspiration(s)'].split(', ')
careers = row['Career'].split(', ')
best_skills = row['Best Skill(s)'].split(', ')
worst_skills = row['Worst Skill(s)'].split(', ')
rules = row['Rule(s)'].split('. ')
for trait in traits:
trait_cleaned = clean_split(trait, separators)
if trait_cleaned in traits_counts:
traits_counts[trait_cleaned] += 1
else:
traits_counts[trait_cleaned] = 1
for aspiration in aspirations:
aspirations_set.add(clean_split(aspiration, separators))
if aspiration in aspiration_counts:
aspiration_counts[aspiration] += 1
else:
aspiration_counts[aspiration] = 1
for career in careers:
careers_set.add(clean_split(career, separators))
if career in career_counts:
career_counts[career] += 1
else:
career_counts[career] = 1
for skill in best_skills:
skill_cleaned = clean_split(skill, separators)
if skill_cleaned in best_skills_counts:
best_skills_counts[skill_cleaned] += 1
else:
best_skills_counts[skill_cleaned] = 1
for skill in worst_skills:
skill_cleaned = clean_split(skill, separators)
if skill_cleaned in worst_skills_counts:
worst_skills_counts[skill_cleaned] += 1
else:
worst_skills_counts[skill_cleaned] = 1
for rule in rules:
if "Must master" in rule:
rule_parts = rule.split(" and ")
for part in rule_parts:
part_cleaned = part.replace("Must master", "").strip().capitalize()
rule_cleaned = f"Must master {part_cleaned}"
else:
rule_parts = rule.split(", ")
for part in rule_parts:
part_cleaned = part.capitalize().strip()
if part_cleaned.startswith("And "):
part_cleaned = part_cleaned[4:]
rule_cleaned = part_cleaned
if rule_cleaned in rule_counts:
rule_counts[rule_cleaned] += 1
else:
rule_counts[rule_cleaned] = 1
rules_list.append(rule_cleaned)
top_aspirations = sorted(aspiration_counts, key=aspiration_counts.get, reverse=True)[:6]
top_careers = sorted(career_counts, key=career_counts.get, reverse=True)[:6]
top_rules = sorted(rule_counts, key=rule_counts.get, reverse=True)[:20]
top_rules.sort()
final_best_skills = {
f"{skill} (+{count+1})": count for skill, count in best_skills_counts.items()
}
final_worst_skills = {
f"{skill} (-{count})": count for skill, count in worst_skills_counts.items()
}
# Sort traits by occurrences
sorted_traits = sorted(traits_counts, key=traits_counts.get, reverse=True)
sorted_traits.sort()
result_text += "\nTraits:\n" + "\n".join(sorted(sorted_traits)) + "\n\n"
result_text += "Aspirations:\n" + "\n".join(sorted(top_aspirations)) + "\n\n"
result_text += "Careers:\n" + "\n".join(sorted(top_careers)) + "\n\n"
result_text += "Best Skills:\n" + "\n".join([f"{skill} (+{count+1})" for skill, count in sorted(final_best_skills.items(), key=lambda item: item[1], reverse=True)]) + "\n\n"
result_text += "Worst Skills:\n" + "\n".join([f"{skill} (-{count})" for skill, count in sorted(final_worst_skills.items(), key=lambda item: item[1], reverse=True)]) + "\n\n"
result_text += "Rules:\n" + "\n".join(top_rules) + "\n"
output_file_path = 'cleaned_natal_chart_results.txt'
with open(output_file_path, 'w') as file:
file.write(result_text)
return sorted_traits, top_aspirations, top_careers, final_best_skills, final_worst_skills, top_rules
def format_birthdate(birthdate, sim_season_days):
seasons = ["Spring", "Summer", "Fall", "Winter"]
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
year, day_of_year = birthdate
season_index = (day_of_year // sim_season_days) % 4
season = seasons[season_index]
day_of_week_index = day_of_year % 7
day_of_week = days_of_week[day_of_week_index]
day_number = day_of_year % sim_season_days + 1
if year < 0:
year_str = f"{-year} BC"
else:
year_str = f"{year} AC"
return f"{season} Year {year_str}, {day_of_week} Day {day_number}"
def lat_lon_to_xyz(lat, lon, radius=80.47):
lat_rad = np.deg2rad(lat)
lon_rad = np.deg2rad(lon)
x = radius * np.cos(lat_rad) * np.cos(lon_rad)
y = radius * np.cos(lat_rad) * np.sin(lon_rad)
z = radius * np.sin(lat_rad)
return x, y, z
def calculate_natal_chart(world_name, x, y, z):
globe = Sims4Globe()
location = globe.get_location(world_name, x, y, z)
#print(f"\nCalculating natal chart for location: {location}\n")
return location
def pretty_print_natal_chart(natal_chart):
#print("\nNatal Chart:")
for planet, details in natal_chart.items():
print(
f"{planet.capitalize()}: {details['sign']}, House {details['house']}"
)
def clean_split(entry, separators):
for sep in separators:
entry = entry.split(sep)[0]
return entry.strip()