Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,37 @@ class SajuCalculator:
|
|
27 |
'금': {'목': '편재/정재', '화': '편관/정관', '토': '편인/정인', '금': '비견/겁재', '수': '식신/상관'},
|
28 |
'수': {'목': '식신/상관', '화': '편재/정재', '토': '편관/정관', '금': '편인/정인', '수': '비견/겁재'}
|
29 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def parse_date(self, date_str):
|
32 |
"""날짜 파싱"""
|
@@ -231,87 +262,112 @@ def calculate_saju(birth_date, birth_time, gender, birth_place):
|
|
231 |
except Exception as e:
|
232 |
return f"❌ 계산 중 오류가 발생했습니다: {str(e)}"
|
233 |
|
234 |
-
def format_saju_result(ganzhi, elements, ten_gods, birth_datetime, gender, birth_place, calculator):
|
235 |
-
"""사주 결과 포맷팅"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
result = f"""
|
238 |
# 🔮 사주명리 만세력 분석결과
|
239 |
|
240 |
## 📋 기본정보
|
241 |
- **생년월일**: {birth_datetime.strftime('%Y년 %m월 %d일')}
|
242 |
-
- **출생시간**: {
|
243 |
- **성별**: {gender}
|
244 |
-
|
|
|
245 |
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
252 |
|
253 |
-
|
254 |
-
**{ganzhi['month'][0]}{ganzhi['month'][1]}**
|
255 |
-
- 천간: {ganzhi['month'][0]} ({calculator.five_elements[ganzhi['month'][0]]})
|
256 |
-
- 지지: {ganzhi['month'][1]} ({calculator.five_elements[ganzhi['month'][1]]})
|
257 |
|
258 |
-
|
259 |
-
**{ganzhi['day'][0]}{ganzhi['day'][1]}** (일간: {ganzhi['day'][0]})
|
260 |
-
- 천간: {ganzhi['day'][0]} ({calculator.five_elements[ganzhi['day'][0]]})
|
261 |
-
- 지지: {ganzhi['day'][1]} ({calculator.five_elements[ganzhi['day'][1]]})
|
262 |
|
263 |
-
|
264 |
-
**{ganzhi['hour'][0]}{ganzhi['hour'][1]}**
|
265 |
-
- 천간: {ganzhi['hour'][0]} ({calculator.five_elements[ganzhi['hour'][0]]})
|
266 |
-
- 지지: {ganzhi['hour'][1]} ({calculator.five_elements[ganzhi['hour'][1]]})
|
267 |
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
|
|
270 |
"""
|
271 |
|
272 |
-
# 오행 분석 추가
|
273 |
-
total_elements = sum(elements.values())
|
274 |
-
for element, count in elements.items():
|
275 |
-
percentage = (count / total_elements * 100) if total_elements > 0 else 0
|
276 |
-
result += f"- **{element}**: {count}개 ({percentage:.1f}%)\n"
|
277 |
-
|
278 |
-
# 오행 균형 분석
|
279 |
max_element = max(elements, key=elements.get)
|
280 |
min_element = min(elements, key=elements.get)
|
281 |
|
282 |
-
result += f""
|
283 |
-
|
284 |
-
- **가장 강한 오행**: {max_element} ({elements[max_element]}개)
|
285 |
-
- **가장 약한 오행**: {min_element} ({elements[min_element]}개)
|
286 |
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
-
"""
|
290 |
-
|
291 |
-
pillar_names = {'year': '연주', 'month': '월주', 'day': '일주', 'hour': '시주'}
|
292 |
-
for pillar_name, pillar_kr in pillar_names.items():
|
293 |
-
result += f"### {pillar_kr}\n"
|
294 |
-
result += f"- 천간: {ten_gods[pillar_name]['stem_relation']}\n"
|
295 |
-
result += f"- 지지: {ten_gods[pillar_name]['branch_relation']}\n\n"
|
296 |
-
|
297 |
-
# 기본 해석 추가
|
298 |
-
result += f"""
|
299 |
## 💡 기본 해석
|
300 |
|
301 |
-
###
|
302 |
-
- **일간**: {ganzhi['day'][0]} ({calculator.five_elements[ganzhi['day'][0]]})
|
303 |
-
-
|
304 |
|
305 |
### 오행 조화
|
306 |
{get_element_balance_advice(elements)}
|
307 |
|
308 |
-
### 주의사항
|
309 |
-
- 이 분석은 기본적인 사주명리학 원리에 따른 것입니다.
|
310 |
-
- 정확한 해석을 위해서는 전문가의 상담을 받으시기 바랍니다.
|
311 |
-
- 절기, 시간대, 지역별 차이 등이 고려되지 않았을 수 있습니다.
|
312 |
-
|
313 |
---
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
"""
|
316 |
|
317 |
return result
|
|
|
27 |
'금': {'목': '편재/정재', '화': '편관/정관', '토': '편인/정인', '금': '비견/겁재', '수': '식신/상관'},
|
28 |
'수': {'목': '식신/상관', '화': '편재/정재', '토': '편관/정관', '금': '편인/정인', '수': '비견/겁재'}
|
29 |
}
|
30 |
+
|
31 |
+
# 지역별 시간 보정 (서울 기준 분 단위)
|
32 |
+
self.location_offsets = {
|
33 |
+
'서울': 0, '서울특별시': 0, '경기': 0, '경기도': 0, '인천': 0, '인천광역시': 0,
|
34 |
+
'강원': +12, '강원도': +12, '춘천': +12, '원주': +8, '강릉': +20,
|
35 |
+
'충북': -8, '충청북도': -8, '청주': -8, '충주': 0,
|
36 |
+
'충남': -16, '충청남도': -16, '대전': -12, '대전광역시': -12, '천안': -12,
|
37 |
+
'전북': -20, '전라북도': -20, '전주': -20, '군산': -24,
|
38 |
+
'전남': -24, '전라남도': -24, '광주': -20, '광주광역시': -20, '목포': -32, '여수': -16,
|
39 |
+
'경북': +8, '경상북도': +8, '대구': +4, '대구광역시': +4, '포항': +20, '경주': +16,
|
40 |
+
'경남': -4, '경상남도': -4, '부산': +12, '부산광역시': +12, '울산': +16, '울산광역시': +16, '창원': +4, '마산': +4, '진주': -8,
|
41 |
+
'제주': -20, '제주도': -20, '제주시': -20, '서귀포': -20
|
42 |
+
}
|
43 |
+
|
44 |
+
def get_location_offset(self, location):
|
45 |
+
"""출생지에 따른 시간 보정값 반환 (분 단위)"""
|
46 |
+
if not location:
|
47 |
+
return 0
|
48 |
+
|
49 |
+
location = location.strip()
|
50 |
+
|
51 |
+
# 정확한 매칭 시도
|
52 |
+
if location in self.location_offsets:
|
53 |
+
return self.location_offsets[location]
|
54 |
+
|
55 |
+
# 부분 매칭 시도
|
56 |
+
for key, offset in self.location_offsets.items():
|
57 |
+
if key in location or location in key:
|
58 |
+
return offset
|
59 |
+
|
60 |
+
return 0 # 기본값 (서울 기준)
|
61 |
|
62 |
def parse_date(self, date_str):
|
63 |
"""날짜 파싱"""
|
|
|
262 |
except Exception as e:
|
263 |
return f"❌ 계산 중 오류가 발생했습니다: {str(e)}"
|
264 |
|
265 |
+
def format_saju_result(ganzhi, elements, ten_gods, birth_datetime, gender, birth_place, calculator, original_time, corrected_time, location_offset):
|
266 |
+
"""사주 결과 포맷팅 - 표 형태로 출력"""
|
267 |
+
|
268 |
+
# 오행별 색상 설정
|
269 |
+
element_colors = {
|
270 |
+
'목': '#28a745', # 녹색
|
271 |
+
'화': '#dc3545', # 빨강
|
272 |
+
'토': '#ffc107', # 노랑
|
273 |
+
'금': '#6c757d', # 회색
|
274 |
+
'수': '#007bff' # 파랑
|
275 |
+
}
|
276 |
+
|
277 |
+
def get_colored_element(char, element):
|
278 |
+
color = element_colors.get(element, '#000000')
|
279 |
+
return f'<span style="color: {color}; font-weight: bold;">{char}</span>'
|
280 |
+
|
281 |
+
def get_colored_ganzhi(stem, branch):
|
282 |
+
stem_element = calculator.five_elements[stem]
|
283 |
+
branch_element = calculator.five_elements[branch]
|
284 |
+
colored_stem = get_colored_element(stem, stem_element)
|
285 |
+
colored_branch = get_colored_element(branch, branch_element)
|
286 |
+
return f'{colored_stem}{colored_branch}'
|
287 |
+
|
288 |
+
# 시간 보정 정보
|
289 |
+
time_correction_info = ""
|
290 |
+
if location_offset != 0:
|
291 |
+
sign = "+" if location_offset > 0 else ""
|
292 |
+
time_correction_info = f"""
|
293 |
+
### ⏰ 출생지 시간 보정
|
294 |
+
- **입력 시간**: {original_time}
|
295 |
+
- **보정 시간**: {corrected_time} ({birth_place} 기준 {sign}{location_offset}분 보정)
|
296 |
+
"""
|
297 |
|
298 |
result = f"""
|
299 |
# 🔮 사주명리 만세력 분석결과
|
300 |
|
301 |
## 📋 기본정보
|
302 |
- **생년월일**: {birth_datetime.strftime('%Y년 %m월 %d일')}
|
303 |
+
- **출생시간**: {corrected_time} ({birth_place})
|
304 |
- **성별**: {gender}
|
305 |
+
{time_correction_info}
|
306 |
+
## 🏛️ 사주(四柱) 만세력표
|
307 |
|
308 |
+
<div style="text-align: center;">
|
309 |
|
310 |
+
| 구분 | **연주(年柱)** | **월주(月柱)** | **일주(日柱)** | **시주(時柱)** |
|
311 |
+
|:---:|:---:|:---:|:---:|:---:|
|
312 |
+
| **천간** | {get_colored_element(ganzhi['year'][0], calculator.five_elements[ganzhi['year'][0]])} | {get_colored_element(ganzhi['month'][0], calculator.five_elements[ganzhi['month'][0]])} | {get_colored_element(ganzhi['day'][0], calculator.five_elements[ganzhi['day'][0]])} | {get_colored_element(ganzhi['hour'][0], calculator.five_elements[ganzhi['hour'][0]])} |
|
313 |
+
| **지지** | {get_colored_element(ganzhi['year'][1], calculator.five_elements[ganzhi['year'][1]])} | {get_colored_element(ganzhi['month'][1], calculator.five_elements[ganzhi['month'][1]])} | {get_colored_element(ganzhi['day'][1], calculator.five_elements[ganzhi['day'][1]])} | {get_colored_element(ganzhi['hour'][1], calculator.five_elements[ganzhi['hour'][1]])} |
|
314 |
+
| **간지** | **{get_colored_ganzhi(ganzhi['year'][0], ganzhi['year'][1])}** | **{get_colored_ganzhi(ganzhi['month'][0], ganzhi['month'][1])}** | **{get_colored_ganzhi(ganzhi['day'][0], ganzhi['day'][1])}** | **{get_colored_ganzhi(ganzhi['hour'][0], ganzhi['hour'][1])}** |
|
315 |
+
| **의미** | 조상, 뿌리 | 부모, 성장기 | 본인, 배우자 | 자식, 말년 |
|
316 |
|
317 |
+
</div>
|
|
|
|
|
|
|
318 |
|
319 |
+
## 🌟 오행(五行) 분석
|
|
|
|
|
|
|
320 |
|
321 |
+
<div style="text-align: center;">
|
|
|
|
|
|
|
322 |
|
323 |
+
| 오행 | 개수 | 비율 | 상태 |
|
324 |
+
|:---:|:---:|:---:|:---:|
|
325 |
+
| {get_colored_element('목', '목')} | {elements['목']}개 | {(elements['목']/8*100):.1f}% | {'강함' if elements['목'] >= 3 else '보통' if elements['목'] >= 2 else '약함'} |
|
326 |
+
| {get_colored_element('화', '화')} | {elements['화']}개 | {(elements['화']/8*100):.1f}% | {'강함' if elements['화'] >= 3 else '보통' if elements['화'] >= 2 else '약함'} |
|
327 |
+
| {get_colored_element('토', '토')} | {elements['토']}개 | {(elements['토']/8*100):.1f}% | {'강함' if elements['토'] >= 3 else '보통' if elements['토'] >= 2 else '약함'} |
|
328 |
+
| {get_colored_element('금', '금')} | {elements['금']}개 | {(elements['금']/8*100):.1f}% | {'강함' if elements['금'] >= 3 else '보통' if elements['금'] >= 2 else '약함'} |
|
329 |
+
| {get_colored_element('수', '수')} | {elements['수']}개 | {(elements['수']/8*100):.1f}% | {'강함' if elements['수'] >= 3 else '보통' if elements['수'] >= 2 else '약함'} |
|
330 |
+
|
331 |
+
</div>
|
332 |
|
333 |
+
### 오행 균형 분석
|
334 |
"""
|
335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
max_element = max(elements, key=elements.get)
|
337 |
min_element = min(elements, key=elements.get)
|
338 |
|
339 |
+
result += f"- **가장 강한 오행**: {get_colored_element(max_element, max_element)} ({elements[max_element]}개)\n"
|
340 |
+
result += f"- **가장 약한 오행**: {get_colored_element(min_element, min_element)} ({elements[min_element]}개)\n"
|
|
|
|
|
341 |
|
342 |
+
result += """
|
343 |
+
## 🎭 십신(十神) 분석표
|
344 |
+
|
345 |
+
<div style="text-align: center;">
|
346 |
+
|
347 |
+
| 구분 | **연주** | **월주** | **일주** | **시주** |
|
348 |
+
|:---:|:---:|:---:|:---:|:---:|
|
349 |
+
| **천간 십신** | """ + ten_gods['year']['stem_relation'] + """ | """ + ten_gods['month']['stem_relation'] + """ | """ + ten_gods['day']['stem_relation'] + """ | """ + ten_gods['hour']['stem_relation'] + """ |
|
350 |
+
| **지지 십신** | """ + ten_gods['year']['branch_relation'] + """ | """ + ten_gods['month']['branch_relation'] + """ | """ + ten_gods['day']['branch_relation'] + """ | """ + ten_gods['hour']['branch_relation'] + """ |
|
351 |
+
|
352 |
+
</div>
|
353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
## 💡 기본 해석
|
355 |
|
356 |
+
### 일간 분석
|
357 |
+
- **일간**: {get_colored_element(ganzhi['day'][0], calculator.five_elements[ganzhi['day'][0]])} ({calculator.five_elements[ganzhi['day'][0]]})
|
358 |
+
- **성격**: {get_element_personality(calculator.five_elements[ganzhi['day'][0]])}
|
359 |
|
360 |
### 오행 조화
|
361 |
{get_element_balance_advice(elements)}
|
362 |
|
|
|
|
|
|
|
|
|
|
|
363 |
---
|
364 |
+
|
365 |
+
### 📌 주의사항
|
366 |
+
- 본 분석은 기본적인 사주명리학 원리에 따른 것입니다
|
367 |
+
- 정확한 해석을 위해서는 전문가 상담을 권장합니다
|
368 |
+
- 절기, 음력 변환 등 세부 요소는 고려되지 않았습니다
|
369 |
+
|
370 |
+
*분석 일시: {datetime.datetime.now().strftime('%Y년 %m월 %d일 %H시 %M분')}*
|
371 |
"""
|
372 |
|
373 |
return result
|