Spaces:
Sleeping
Sleeping
Create calculations.py
Browse files- utils/calculations.py +77 -0
utils/calculations.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils/calculations.py
|
| 2 |
+
|
| 3 |
+
def get_ganji(year):
|
| 4 |
+
"""
|
| 5 |
+
์ฐ๋๋ฅผ ์
๋ ฅ๋ฐ์ ์ฒ๊ฐ(Heavenly Stem)๊ณผ ์ง์ง(Earthly Branch), ์คํ(Element)์ ๊ณ์ฐ
|
| 6 |
+
"""
|
| 7 |
+
cheon = ["๊ฐ(Green)", "์(Green)", "๋ณ(Red)", "์ (Red)", "๋ฌด(Yellow)", "๊ธฐ(Yellow)", "๊ฒฝ(White)", "์ (White)", "์(Black)", "๊ณ(Black)"]
|
| 8 |
+
ji = ["์(์ฅ)", "์ถ(์)", "์ธ(ํธ๋์ด)", "๋ฌ(ํ ๋ผ)", "์ง(์ฉ)", "์ฌ(๋ฑ)", "์ค(๋ง)", "๋ฏธ(์)", "์ (์์ญ์ด)", "์ (๋ญ)", "์ (๊ฐ)", "ํด(๋ผ์ง)"]
|
| 9 |
+
|
| 10 |
+
# ์คํ ๋งคํ (์ฒ๊ฐ ๊ธฐ์ค)
|
| 11 |
+
elements = {
|
| 12 |
+
"๊ฐ": "๋ชฉ(๋๋ฌด)", "์": "๋ชฉ(๋๋ฌด)",
|
| 13 |
+
"๋ณ": "ํ(๋ถ)", "์ ": "ํ(๋ถ)",
|
| 14 |
+
"๋ฌด": "ํ (ํ)", "๊ธฐ": "ํ (ํ)",
|
| 15 |
+
"๊ฒฝ": "๊ธ(์ )", "์ ": "๊ธ(์ )",
|
| 16 |
+
"์": "์(๋ฌผ)", "๊ณ": "์(๋ฌผ)"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
# 4๋
์์ด ๊ฐ์๋
๊ธฐ์ค (index 0)
|
| 20 |
+
year_idx = year - 4
|
| 21 |
+
stem_idx = year_idx % 10
|
| 22 |
+
branch_idx = year_idx % 12
|
| 23 |
+
|
| 24 |
+
stem_kor = cheon[stem_idx][0] # ๊ฐ, ์..
|
| 25 |
+
|
| 26 |
+
return {
|
| 27 |
+
"year_ganji": f"{cheon[stem_idx].split('(')[0]}{ji[branch_idx].split('(')[0]}๋
", # ๊ฐ์๋
|
| 28 |
+
"animal": ji[branch_idx], # ์ฅ, ์...
|
| 29 |
+
"color": cheon[stem_idx].split('(')[1].replace(')', ''), # Green, Red...
|
| 30 |
+
"element": elements[stem_kor], # ๋ชฉ, ํ...
|
| 31 |
+
"stem_desc": f"์ฒ๊ฐ์ {cheon[stem_idx]}",
|
| 32 |
+
"branch_desc": f"์ง์ง๋ {ji[branch_idx]}"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
def get_fengshui_info(birth_year, gender):
|
| 36 |
+
"""
|
| 37 |
+
๋ณธ๋ช
๊ถ(Life Gua) ๊ณ์ฐ ๋ฐ ๊ธธํ ๋ฐฉ์ ์ฐ์ถ (๊ฐ์ฅ ์ค์ํ ๊ณต์)
|
| 38 |
+
"""
|
| 39 |
+
# 1. ์ซ์๋ฅผ ๋ค ๋ํด์ ํ ์๋ฆฌ๋ก ๋ง๋ฆ (์: 1988 -> 1+9+8+8=26 -> 2+6=8)
|
| 40 |
+
# (์ฝ์ ๊ณ์ฐ๋ฒ ์ฌ์ฉ)
|
| 41 |
+
digits_sum = sum(int(digit) for digit in str(birth_year))
|
| 42 |
+
while digits_sum > 9:
|
| 43 |
+
digits_sum = sum(int(digit) for digit in str(digits_sum))
|
| 44 |
+
|
| 45 |
+
# 2. ๋ณธ๋ช
๊ถ ์์(Gua Number) ๊ณ์ฐ
|
| 46 |
+
if gender == "๋จ์ฑ":
|
| 47 |
+
gua_num = 11 - digits_sum
|
| 48 |
+
else: # ์ฌ์ฑ
|
| 49 |
+
gua_num = digits_sum + 4
|
| 50 |
+
|
| 51 |
+
# ์์ธ์ฒ๋ฆฌ (9๋ฅผ ๋๊ฑฐ๋ ์์ ์ฒ๋ฆฌ)
|
| 52 |
+
while gua_num > 9: gua_num -= 9
|
| 53 |
+
while gua_num < 1: gua_num += 9
|
| 54 |
+
if gua_num == 5: # 5ํฉํ ์ฑ์ ๋จ์๋ 2(๊ณค), ์ฌ์๋ 8(๊ฐ)์ผ๋ก ์นํ
|
| 55 |
+
gua_num = 2 if gender == "๋จ์ฑ" else 8
|
| 56 |
+
|
| 57 |
+
# 3. ๋์ฌํ(East Group) vs ์์ฌํ(West Group) ํ๋ณ
|
| 58 |
+
# ๋์ฌํ: 1, 3, 4, 9 / ์์ฌํ: 2, 6, 7, 8
|
| 59 |
+
is_east_group = gua_num in [1, 3, 4, 9]
|
| 60 |
+
group_name = "๋์ฌํ(East Group)" if is_east_group else "์์ฌํ(West Group)"
|
| 61 |
+
|
| 62 |
+
# 4. ๊ธธํ ๋ฐฉํฅ ๋ฐ์ดํฐ
|
| 63 |
+
directions = {
|
| 64 |
+
"๋์ฌํ": {"๊ธธ": ["๋ถ", "๋", "๋จ", "๋จ๋"], "ํ": ["๋ถ๋", "๋จ์", "์", "๋ถ์"]},
|
| 65 |
+
"์์ฌํ": {"๊ธธ": ["๋ถ๋", "๋จ์", "์", "๋ถ์"], "ํ": ["๋ถ", "๋", "๋จ", "๋จ๋"]}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
good_dirs = directions["๋์ฌํ" if is_east_group else "์์ฌํ"]["๊ธธ"]
|
| 69 |
+
bad_dirs = directions["๋์ฌํ" if is_east_group else "์์ฌํ"]["ํ"]
|
| 70 |
+
|
| 71 |
+
return {
|
| 72 |
+
"gua_number": gua_num,
|
| 73 |
+
"group": group_name,
|
| 74 |
+
"good_direction": ", ".join(good_dirs),
|
| 75 |
+
"bad_direction": ", ".join(bad_dirs),
|
| 76 |
+
"advice": f"๋น์ ์ {group_name}์ด๋ฏ๋ก ๋จธ๋ฆฌ๋ฅผ {good_dirs[0]}์ชฝ์ผ๋ก ๋๊ณ ์์ผ ํฉ๋๋ค. ์ ๋ {bad_dirs[0]}์ชฝ์ ๋ณด์ง ๋ง์ธ์."
|
| 77 |
+
}
|