-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_streamlit_issue.py
More file actions
243 lines (196 loc) ยท 9.05 KB
/
Copy pathdebug_streamlit_issue.py
File metadata and controls
243 lines (196 loc) ยท 9.05 KB
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
#!/usr/bin/env python3
"""
Streamlit ๋ฐ์ดํฐ ์์ง ๋ฌธ์ ์ง๋จ ์คํฌ๋ฆฝํธ
"""
import sys
import os
import time
import traceback
from datetime import datetime
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def test_data_collection_step_by_step():
"""๋จ๊ณ๋ณ ๋ฐ์ดํฐ ์์ง ํ
์คํธ"""
print("๐ Streamlit ๋ฐ์ดํฐ ์์ง ๋ฌธ์ ์ง๋จ")
print("=" * 50)
# ํ๊ฒฝ๋ณ์ ํ์ธ
print("\n1๏ธโฃ ํ๊ฒฝ๋ณ์ ํ์ธ:")
alpha_key = os.getenv('ALPHA_VANTAGE_API_KEY')
fred_key = os.getenv('FRED_API_KEY')
print(f" ALPHA_VANTAGE_API_KEY: {'โ
์ค์ ๋จ' if alpha_key else 'โ ์์'}")
print(f" FRED_API_KEY: {'โ
์ค์ ๋จ' if fred_key else 'โ ์์'}")
# Enhanced Data Collector ์ด๊ธฐํ ํ
์คํธ
print("\n2๏ธโฃ Enhanced Data Collector ์ด๊ธฐํ ํ
์คํธ:")
try:
from data_monitoring.enhanced_data_collector import EnhancedGlobalDataCollector
collector = EnhancedGlobalDataCollector()
print(" โ
Enhanced Data Collector ์ด๊ธฐํ ์ฑ๊ณต")
except Exception as e:
print(f" โ Enhanced Data Collector ์ด๊ธฐํ ์คํจ: {e}")
traceback.print_exc()
return False
# ๊ฐ ๋ฐ์ดํฐ ์์ค๋ณ ๊ฐ๋ณ ํ
์คํธ
results = {}
# Intelligence ๋ฐ์ดํฐ ํ
์คํธ
print("\n3๏ธโฃ Intelligence ๋ฐ์ดํฐ ์์ง ํ
์คํธ:")
start_time = time.time()
try:
intelligence_data = collector.collect_intelligence_data()
elapsed = time.time() - start_time
if intelligence_data.get('status') == 'success':
print(f" โ
Intelligence ๋ฐ์ดํฐ ์์ง ์ฑ๊ณต ({elapsed:.1f}์ด)")
summary = intelligence_data.get('summary', {})
print(f" ์์ฅ ์ํ: {summary.get('market_status_count', 0)}๊ฐ")
results['intelligence'] = True
else:
print(f" โ Intelligence ๋ฐ์ดํฐ ์์ง ์คํจ ({elapsed:.1f}์ด)")
print(f" ์ค๋ฅ: {intelligence_data.get('error', 'Unknown')}")
results['intelligence'] = False
except Exception as e:
elapsed = time.time() - start_time
print(f" โ Intelligence ๋ฐ์ดํฐ ์์ง ์์ธ ({elapsed:.1f}์ด): {e}")
results['intelligence'] = False
# FRED ๋ฐ์ดํฐ ํ
์คํธ
print("\n4๏ธโฃ FRED ๋ฐ์ดํฐ ์์ง ํ
์คํธ:")
start_time = time.time()
try:
fred_data = collector.collect_fred_data()
elapsed = time.time() - start_time
if fred_data.get('status') == 'success':
print(f" โ
FRED ๋ฐ์ดํฐ ์์ง ์ฑ๊ณต ({elapsed:.1f}์ด)")
summary = fred_data.get('summary', {})
print(f" ๊ฒฝ์ ์งํ: {summary.get('collected_indicators', 0)}๊ฐ")
results['fred'] = True
else:
print(f" โ FRED ๋ฐ์ดํฐ ์์ง ์คํจ ({elapsed:.1f}์ด)")
print(f" ์ค๋ฅ: {fred_data.get('error', 'Unknown')}")
results['fred'] = False
except Exception as e:
elapsed = time.time() - start_time
print(f" โ FRED ๋ฐ์ดํฐ ์์ง ์์ธ ({elapsed:.1f}์ด): {e}")
results['fred'] = False
# ๋ด์ค ๋ฐ์ดํฐ ํ
์คํธ
print("\n5๏ธโฃ ๋ด์ค ๋ฐ์ดํฐ ์์ง ํ
์คํธ:")
start_time = time.time()
try:
news_data = collector.collect_enhanced_news_data()
elapsed = time.time() - start_time
if news_data.get('status') == 'success':
print(f" โ
๋ด์ค ๋ฐ์ดํฐ ์์ง ์ฑ๊ณต ({elapsed:.1f}์ด)")
summary = news_data.get('summary', {})
print(f" ๋ด์ค ๊ธฐ์ฌ: {summary.get('total_articles', 0)}๊ฐ")
results['news'] = True
else:
print(f" โ ๋ด์ค ๋ฐ์ดํฐ ์์ง ์คํจ ({elapsed:.1f}์ด)")
print(f" ์ค๋ฅ: {news_data.get('error', 'Unknown')}")
results['news'] = False
except Exception as e:
elapsed = time.time() - start_time
print(f" โ ๋ด์ค ๋ฐ์ดํฐ ์์ง ์์ธ ({elapsed:.1f}์ด): {e}")
results['news'] = False
# ์ ์ฒด ๋ฐ์ดํฐ ์์ง ํ
์คํธ (Streamlit์์ ์ฌ์ฉํ๋ ํจ์)
print("\n6๏ธโฃ ์ ์ฒด ๋ฐ์ดํฐ ์์ง ํ
์คํธ (Streamlit ํจ์):")
start_time = time.time()
try:
# Streamlit์์ ์ฌ์ฉํ๋ collect_all_data ํจ์ ์๋ฎฌ๋ ์ด์
all_data = {
'intelligence': collector.collect_intelligence_data(),
'fred': collector.collect_fred_data(),
'news': collector.collect_enhanced_news_data(),
'timestamp': datetime.now().isoformat()
}
elapsed = time.time() - start_time
print(f" โ
์ ์ฒด ๋ฐ์ดํฐ ์์ง ์๋ฃ ({elapsed:.1f}์ด)")
# ๊ฐ ๋ฐ์ดํฐ ์์ค ์ํ ํ์ธ
for source, data in all_data.items():
if source != 'timestamp':
status = data.get('status', 'unknown')
print(f" {source}: {status}")
results['total'] = True
except Exception as e:
elapsed = time.time() - start_time
print(f" โ ์ ์ฒด ๋ฐ์ดํฐ ์์ง ์คํจ ({elapsed:.1f}์ด): {e}")
traceback.print_exc()
results['total'] = False
# ๊ฒฐ๊ณผ ์์ฝ
print("\n" + "=" * 50)
print("๐ ์ง๋จ ๊ฒฐ๊ณผ ์์ฝ")
print("-" * 25)
for test_name, success in results.items():
status = "โ
์ฑ๊ณต" if success else "โ ์คํจ"
print(f"{test_name:12} {status}")
# ๋ฌธ์ ๋ถ์ ๋ฐ ํด๊ฒฐ์ฑ
์ ์
print("\n๐ง ๋ฌธ์ ๋ถ์ ๋ฐ ํด๊ฒฐ์ฑ
:")
failed_tests = [name for name, success in results.items() if not success]
if not failed_tests:
print(" โ
๋ชจ๋ ํ
์คํธ ํต๊ณผ! Streamlit ๋ฌธ์ ๋ ๋ค๋ฅธ ์์ธ์ผ ์ ์์ต๋๋ค.")
print(" - ์บ์ ๋ฌธ์ : st.cache_data.clear() ์๋")
print(" - ๋ธ๋ผ์ฐ์ ์๋ก๊ณ ์นจ")
print(" - Streamlit ์ฌ์์")
else:
print(f" โ ์คํจํ ํ
์คํธ: {', '.join(failed_tests)}")
if 'intelligence' in failed_tests:
print(" - Alpha Vantage API ํค ํ์ธ")
print(" - ๋คํธ์ํฌ ์ฐ๊ฒฐ ํ์ธ")
if 'fred' in failed_tests:
print(" - FRED API ํค ํ์ธ")
print(" - FRED API ์๋ฒ ์ํ ํ์ธ")
if 'news' in failed_tests:
print(" - RSS ํผ๋ ์ ๊ทผ ํ์ธ")
print(" - textblob ํจํค์ง ์ค์น ํ์ธ")
return results
def test_streamlit_cache_function():
"""Streamlit ์บ์ ํจ์ ํ
์คํธ"""
print("\n7๏ธโฃ Streamlit ์บ์ ํจ์ ํ
์คํธ:")
try:
# Streamlit ์์ด ์บ์ ํจ์ ์๋ฎฌ๋ ์ด์
from data_monitoring.enhanced_data_collector import EnhancedGlobalDataCollector
def collect_all_data_simulation():
collector = EnhancedGlobalDataCollector()
intelligence_data = collector.collect_intelligence_data()
fred_data = collector.collect_fred_data()
news_data = collector.collect_enhanced_news_data()
return {
'intelligence': intelligence_data,
'fred': fred_data,
'news': news_data,
'timestamp': datetime.now().isoformat()
}, None
start_time = time.time()
all_data, error = collect_all_data_simulation()
elapsed = time.time() - start_time
if error:
print(f" โ ์บ์ ํจ์ ์๋ฎฌ๋ ์ด์
์คํจ ({elapsed:.1f}์ด): {error}")
return False
else:
print(f" โ
์บ์ ํจ์ ์๋ฎฌ๋ ์ด์
์ฑ๊ณต ({elapsed:.1f}์ด)")
return True
except Exception as e:
print(f" โ ์บ์ ํจ์ ์๋ฎฌ๋ ์ด์
์์ธ: {e}")
return False
def main():
"""๋ฉ์ธ ์ง๋จ ํ๋ก์ธ์ค"""
print(f"๐ ์ง๋จ ์์ ์๊ฐ: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# ๋จ๊ณ๋ณ ํ
์คํธ
results = test_data_collection_step_by_step()
# ์บ์ ํจ์ ํ
์คํธ
cache_result = test_streamlit_cache_function()
# ์ต์ข
๊ถ์ฅ์ฌํญ
print("\n" + "=" * 50)
print("๐ฏ ์ต์ข
๊ถ์ฅ์ฌํญ")
print("-" * 25)
if all(results.values()) and cache_result:
print("โ
๋ชจ๋ ๋ฐ์ดํฐ ์์ง ๊ธฐ๋ฅ์ด ์ ์ ์๋ํฉ๋๋ค.")
print("๐ง Streamlit ๊ด๋ จ ํด๊ฒฐ์ฑ
:")
print(" 1. ๋ธ๋ผ์ฐ์ ๊ฐ๋ ฅ ์๋ก๊ณ ์นจ (Ctrl+Shift+R)")
print(" 2. Streamlit ์ฌ์์")
print(" 3. ๋ธ๋ผ์ฐ์ ์บ์ ์ญ์ ")
print(" 4. ๋ค๋ฅธ ๋ธ๋ผ์ฐ์ ๋ก ํ
์คํธ")
else:
print("โ ๋ฐ์ดํฐ ์์ง์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.")
print("๐ง ์ฐ์ ํด๊ฒฐํด์ผ ํ ๋ฌธ์ :")
failed = [name for name, success in results.items() if not success]
for fail in failed:
print(f" - {fail} ๋ฐ์ดํฐ ์์ง ๋ฌธ์ ")
print(f"\n๐ ์ง๋จ ์๋ฃ ์๊ฐ: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
if __name__ == "__main__":
main()