Spaces:
Sleeping
Sleeping
Update chatbot.py
Browse files- chatbot.py +11 -19
chatbot.py
CHANGED
|
@@ -6,7 +6,7 @@ import traceback
|
|
| 6 |
from dateutil import parser as date_parser
|
| 7 |
|
| 8 |
# Local imports
|
| 9 |
-
from supabase_utils import get_supabase_client
|
| 10 |
|
| 11 |
# Attempt to import Gemini
|
| 12 |
try:
|
|
@@ -72,31 +72,23 @@ def retrieve_context_from_db(intent: dict) -> str:
|
|
| 72 |
return "질문에서 시간 정보를 찾을 수 없습니다."
|
| 73 |
|
| 74 |
try:
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
-
end_query_str = end_time.strftime('%Y-%m-%d %H:%M:%S')
|
| 80 |
-
|
| 81 |
-
result = supabase.table('tide_predictions')\
|
| 82 |
-
.select('*')\
|
| 83 |
-
.eq('station_id', station_id)\
|
| 84 |
-
.gte('predicted_at', start_query_str)\
|
| 85 |
-
.lte('predicted_at', end_query_str)\
|
| 86 |
-
.order('predicted_at')\
|
| 87 |
-
.execute()
|
| 88 |
-
|
| 89 |
-
if result.data:
|
| 90 |
info_text = f"'{station_name}'의 '{start_time_str}'부터 '{end_time_str}'까지 조위 정보입니다.\n\n"
|
| 91 |
|
| 92 |
-
if len(
|
| 93 |
-
levels = [d['final_tide_level'] for d in
|
| 94 |
max_level = max(levels)
|
| 95 |
min_level = min(levels)
|
| 96 |
info_text += f"- 최고 조위: {max_level:.1f}cm\n- 최저 조위: {min_level:.1f}cm"
|
| 97 |
else:
|
| 98 |
-
for d in
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
info_text += f"- {time_kst}: 최종 조위 {d['final_tide_level']:.1f}cm (잔차 {d['predicted_residual']:.1f}cm)\n"
|
| 101 |
return info_text
|
| 102 |
else:
|
|
|
|
| 6 |
from dateutil import parser as date_parser
|
| 7 |
|
| 8 |
# Local imports
|
| 9 |
+
from supabase_utils import get_supabase_client, get_tide_predictions
|
| 10 |
|
| 11 |
# Attempt to import Gemini
|
| 12 |
try:
|
|
|
|
| 72 |
return "질문에서 시간 정보를 찾을 수 없습니다."
|
| 73 |
|
| 74 |
try:
|
| 75 |
+
# KST 시간을 UTC로 변환하여 쿼리
|
| 76 |
+
result_data = get_tide_predictions(station_id, start_time_str, end_time_str)
|
| 77 |
|
| 78 |
+
if result_data:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
info_text = f"'{station_name}'의 '{start_time_str}'부터 '{end_time_str}'까지 조위 정보입니다.\n\n"
|
| 80 |
|
| 81 |
+
if len(result_data) > 10:
|
| 82 |
+
levels = [d['final_tide_level'] for d in result_data]
|
| 83 |
max_level = max(levels)
|
| 84 |
min_level = min(levels)
|
| 85 |
info_text += f"- 최고 조위: {max_level:.1f}cm\n- 최저 조위: {min_level:.1f}cm"
|
| 86 |
else:
|
| 87 |
+
for d in result_data:
|
| 88 |
+
# UTC 시간을 KST로 변환하여 표시
|
| 89 |
+
utc_time = date_parser.parse(d['predicted_at']).replace(tzinfo=pytz.UTC)
|
| 90 |
+
kst_time = utc_time.astimezone(pytz.timezone('Asia/Seoul'))
|
| 91 |
+
time_kst = kst_time.strftime('%H:%M')
|
| 92 |
info_text += f"- {time_kst}: 최종 조위 {d['final_tide_level']:.1f}cm (잔차 {d['predicted_residual']:.1f}cm)\n"
|
| 93 |
return info_text
|
| 94 |
else:
|