Spaces:
Runtime error

ditgun commited on
Commit
50ffa26
Β·
verified Β·
1 Parent(s): 9dbca56

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +375 -290
src/app.py CHANGED
@@ -26,7 +26,6 @@ today_str = datetime.now().strftime("%Y-%m-%d")
26
  # ============================================================
27
  st.set_page_config(page_title="Invest Pro Alpha", layout="wide", initial_sidebar_state="collapsed")
28
 
29
- # ── λ„€λΉ„κ²Œμ΄μ…˜ λ°” ─────────────────────────────────────────────
30
  NAV_CSS = """
31
  div.element-container:has(.nav-marker) + div {
32
  position: fixed !important; bottom: 0 !important; left: 0 !important;
@@ -67,7 +66,6 @@ div.element-container:has(.nav-marker) + div button:hover em,
67
  div.element-container:has(.nav-marker) + div button:active em { color: #C9A84C !important; }
68
  """
69
 
70
- # ── 포트폴리였 ν–‰ (νŽΈμ§‘/μ‚­μ œ/일지 λ²„νŠΌ) ──────────────────────
71
  PORTFOLIO_ROW_CSS = """
72
  div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stColumns"],
73
  div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stHorizontalBlock"] {
@@ -89,7 +87,6 @@ div.element-container:has(.action-marker.edit) + div button:hover { color: #42
89
  div.element-container:has(.action-marker.log) + div button:hover { color: #C9A84C !important; transform: scale(1.15) !important; }
90
  """
91
 
92
- # ── μŠ€μΊ” μΉ΄λ“œ & 포트폴리였 μš”μ•½ μΉ΄λ“œ ─────────────────────────
93
  CARD_CSS = """
94
  div.element-container:has(.scan-marker) + div.element-container button {
95
  background: #0F1623 !important;
@@ -155,7 +152,6 @@ div.element-container:has(.port-marker) + div.element-container button strong {
155
  }
156
  """
157
 
158
- # ── 곡톡 μ»΄ν¬λ„ŒνŠΈ ─────────────────────────────────────────────
159
  COMPONENT_CSS = """
160
  .menu-overlay-btn > button {
161
  background: #0F1623 !important;
@@ -300,100 +296,6 @@ button[kind="primary"]:not([title]):hover {
300
  0%, 100% { opacity: 1; }
301
  50% { opacity: 0.65; }
302
  }
303
-
304
- /* ══════════════════════════════════════════════════════
305
- NEW: κ·Έλ£Ήν•‘ μ•ŒλžŒ νŒ¨λ„ CSS
306
- ══════════════════════════════════════════════════════ */
307
- @keyframes alertSlideUp {
308
- from { transform: translateY(20px); opacity: 0; }
309
- to { transform: translateY(0); opacity: 1; }
310
- }
311
- @keyframes badgePop {
312
- from { transform: scale(0.7); opacity: 0; }
313
- to { transform: scale(1); opacity: 1; }
314
- }
315
- @keyframes alertPulseGlow {
316
- 0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,53,0.0); }
317
- 50% { box-shadow: 0 0 12px 2px rgba(255,107,53,0.18); }
318
- }
319
- .alert-panel-wrap {
320
- position: fixed;
321
- bottom: 72px;
322
- right: 14px;
323
- width: min(96vw, 370px);
324
- z-index: 99999;
325
- animation: alertSlideUp 0.35s cubic-bezier(0.34,1.56,0.64,1);
326
- font-family: 'Noto Sans KR', sans-serif;
327
- }
328
- .alert-panel-header {
329
- background: linear-gradient(135deg,#1a2035 0%,#131820 100%);
330
- border: 1px solid rgba(255,255,255,0.09);
331
- border-bottom: none;
332
- border-radius: 14px 14px 0 0;
333
- padding: 12px 14px 0;
334
- }
335
- .alert-tabs-row {
336
- display: flex; gap: 3px;
337
- }
338
- .alert-tab {
339
- flex: 1;
340
- background: transparent;
341
- border: 1px solid transparent;
342
- border-bottom: none;
343
- border-radius: 8px 8px 0 0;
344
- padding: 7px 3px;
345
- cursor: pointer;
346
- display: flex; flex-direction: column; align-items: center; gap: 2px;
347
- transition: all 0.18s;
348
- }
349
- .alert-tab.active { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
350
- .alert-tab-icon { font-size: 15px; }
351
- .alert-tab-label { font-size: 9px; font-weight: 700; letter-spacing: 0.04em; }
352
- .alert-tab-badge {
353
- font-size: 9px; font-weight: 700; min-width: 16px; height: 16px;
354
- border-radius: 8px; display: flex; align-items: center; justify-content: center;
355
- padding: 0 4px;
356
- }
357
- .alert-panel-body {
358
- background: linear-gradient(180deg,#161c2a 0%,#111620 100%);
359
- border: 1px solid rgba(255,255,255,0.09);
360
- border-radius: 0 0 14px 14px;
361
- max-height: 260px;
362
- overflow-y: auto;
363
- padding: 6px;
364
- }
365
- .alert-item {
366
- display: flex; align-items: center; gap: 10px;
367
- padding: 9px 11px;
368
- border-radius: 9px;
369
- cursor: pointer;
370
- border: 1px solid transparent;
371
- margin-bottom: 3px;
372
- transition: all 0.15s;
373
- text-decoration: none;
374
- }
375
- .alert-item:hover { background: rgba(255,255,255,0.05) !important; }
376
- .alert-ticker-box {
377
- width: 38px; height: 38px; border-radius: 9px;
378
- display: flex; align-items: center; justify-content: center;
379
- flex-shrink: 0; font-size: 9px; font-weight: 800; letter-spacing: -0.03em;
380
- }
381
- .alert-badge-minimized {
382
- position: fixed;
383
- bottom: 72px; right: 14px;
384
- display: flex; align-items: center; gap: 8px;
385
- background: linear-gradient(135deg,#1a2035,#131820);
386
- border: 1px solid rgba(255,107,53,0.4);
387
- border-radius: 40px; padding: 9px 18px;
388
- cursor: pointer; z-index: 99999;
389
- box-shadow: 0 6px 24px rgba(0,0,0,0.5);
390
- animation: badgePop 0.35s cubic-bezier(0.34,1.56,0.64,1), alertPulseGlow 2s ease-in-out infinite;
391
- font-family: 'Noto Sans KR', sans-serif;
392
- user-select: none;
393
- }
394
- .alert-panel-wrap { width: min(92vw,340px); bottom: 68px; }
395
- .alert-badge-minimized { bottom: 68px; }
396
- }
397
  """
398
 
399
  def load_css():
@@ -522,6 +424,24 @@ def load_css():
522
  color: #EEF2F7 !important;
523
  }}
524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  {NAV_CSS}
526
  {PORTFOLIO_ROW_CSS}
527
  {CARD_CSS}
@@ -539,10 +459,9 @@ if 'api_key' not in st.session_state:
539
  if 'show_menu' not in st.session_state: st.session_state.show_menu = False
540
  if 'main_menu' not in st.session_state: st.session_state.main_menu = "βŒ‚ ν™ˆ & μŠ€μΊ”"
541
 
542
- # ── μ•ŒλžŒ νŒ¨λ„ μ„Έμ…˜ μŠ€ν…Œμ΄νŠΈ μ΄ˆκΈ°ν™” ──────────────────────────
543
  if 'alert_panel_minimized' not in st.session_state: st.session_state.alert_panel_minimized = False
544
  if 'alert_panel_start_time' not in st.session_state: st.session_state.alert_panel_start_time = time.time()
545
- if 'alert_active_tab' not in st.session_state: st.session_state.alert_active_tab = None # None = μžλ™ 선택
546
 
547
  def _key_hash():
548
  return hashlib.sha256(st.session_state.api_key.encode()).hexdigest()[:16]
@@ -1152,15 +1071,10 @@ def render_trade_analytics(tdf):
1152
  )
1153
 
1154
  # ============================================================
1155
- # 8. β˜… NEW: κ·Έλ£Ήν•‘ μ•ŒλžŒ νŒ¨λ„
1156
  # ============================================================
1157
 
1158
  def _build_alert_groups(prices, rate):
1159
- """
1160
- 보유 μ’…λͺ©μ„ μˆœνšŒν•˜λ©° 4개 μΉ΄ν…Œκ³ λ¦¬λ‘œ λΆ„λ₯˜.
1161
- λ°˜ν™˜: { "κΈ‰λ³€": [...], "맀수": [...], "읡절": [...], "μŠ€ν†±λ‘œμŠ€": [...] }
1162
- 각 ν•­λͺ©: { ticker, name, change_pct, current_price, target_price, action }
1163
- """
1164
  groups = {"κΈ‰λ³€": [], "맀수": [], "읡절": [], "μŠ€ν†±λ‘œμŠ€": []}
1165
  if st.session_state.df.empty:
1166
  return groups
@@ -1182,12 +1096,10 @@ def _build_alert_groups(prices, rate):
1182
  current_price=int(ck), avg_price=int(ap),
1183
  target_price=tgp, action=act)
1184
 
1185
- # κΈ‰λ³€: Β±15% 이상 (뢄석 μ—¬λΆ€ 무관)
1186
  if abs(pct) >= 15:
1187
  groups["κΈ‰λ³€"].append(item)
1188
  continue
1189
 
1190
- # λΆ„μ„λœ μ’…λͺ©λ§Œ λ‚˜λ¨Έμ§€ λΆ„λ₯˜
1191
  if not act:
1192
  continue
1193
 
@@ -1201,23 +1113,21 @@ def _build_alert_groups(prices, rate):
1201
  return groups
1202
 
1203
 
1204
- def _navigate_to_ticker(ticker, from_portfolio=True):
1205
- """μ•ŒλžŒ νŒ¨λ„μ—μ„œ μ’…λͺ© 클릭 μ‹œ 뢄석 ν™”λ©΄μœΌλ‘œ 이동"""
1206
- # 보유 μ’…λͺ©μ΄λ©΄ μžμ‚° 상세 μ§„λ‹¨μœΌλ‘œ, μ•„λ‹ˆλ©΄ ν™ˆ μŠ€μΊ”μœΌλ‘œ
1207
  in_portfolio = ticker in st.session_state.df['티컀'].values if not st.session_state.df.empty else False
1208
  if in_portfolio:
1209
  st.session_state.detail_ticker = ticker
1210
  st.session_state.main_menu = "β–€ μžμ‚° 상세 진단"
1211
  st.session_state.p_diag_mode = False
 
1212
  else:
1213
  st.session_state.active_ticker = ticker
1214
  st.session_state.main_menu = "βŒ‚ ν™ˆ & μŠ€μΊ”"
1215
  st.session_state.p_diag_mode = False
1216
- st.session_state.pop('detail_ticker' if not in_portfolio else 'active_ticker', None)
1217
 
1218
 
1219
  def render_grouped_alert_panel(prices, rate):
1220
- """μš°ν•˜λ‹¨ ν”Œλ‘œνŒ… μ•ŒλžŒ νŒ¨λ„ β€” components.html + CSS fixed overlay"""
1221
  groups = _build_alert_groups(prices, rate)
1222
  total_cnt = sum(len(v) for v in groups.values())
1223
  if total_cnt == 0:
@@ -1241,11 +1151,13 @@ def render_grouped_alert_panel(prices, rate):
1241
 
1242
  if st.session_state.alert_active_tab not in TAB_CFG:
1243
  for pt in ["μŠ€ν†±λ‘œμŠ€", "κΈ‰λ³€", "읡절", "맀수"]:
1244
- if groups[pt]: st.session_state.alert_active_tab = pt; break
1245
- else: st.session_state.alert_active_tab = "κΈ‰λ³€"
 
 
 
1246
  active_tab = st.session_state.alert_active_tab
1247
 
1248
- # μ’…λͺ© 데이터 JSON 직렬화
1249
  data = {}
1250
  for tab, tc in TAB_CFG.items():
1251
  rows = []
@@ -1259,195 +1171,370 @@ def render_grouped_alert_panel(prices, rate):
1259
  })
1260
  data[tab] = rows
1261
 
1262
- tab_json = json.dumps({t: {"icon": v["icon"], "accent": v["accent"],
1263
- "bg": v["bg"], "border": v["border"]}
1264
- for t, v in TAB_CFG.items()}, ensure_ascii=False)
 
 
1265
  data_json = json.dumps(data, ensure_ascii=False)
1266
  timer_col = "#E53E3E" if time_left <= 15 else ("#EAB308" if time_left <= 30 else "#8B98B4")
1267
 
1268
- # iframe CSS: 전체화면 투λͺ… μ˜€λ²„λ ˆμ΄
1269
- st.markdown("""
1270
- <style>
1271
- iframe[title="components.v1.html"] {
1272
- position: fixed !important;
1273
- top: 0 !important; left: 0 !important;
1274
- width: 100vw !important; height: 100vh !important;
1275
- border: none !important; z-index: 2147483640 !important;
1276
- background: transparent !important; pointer-events: none !important;
1277
- }
1278
- div:has(> iframe[title="components.v1.html"]) {
1279
- height: 0 !important; overflow: visible !important;
1280
- }
1281
- </style>""", unsafe_allow_html=True)
1282
-
1283
- B = badge_col
1284
- T = str(time_left)
1285
- N = str(total_cnt)
1286
- TC = timer_col
1287
- DMIN = "flex" if minimized else "none"
1288
- DPAN = "none" if minimized else "block"
1289
  IMIN = "true" if minimized else "false"
1290
  ITAB = json.dumps(active_tab, ensure_ascii=False)
 
 
 
1291
 
1292
- html = """<!DOCTYPE html>
1293
- <html><head><meta charset='utf-8'>
1294
- <link href='https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700;900&family=DM+Mono:wght@500;700&display=swap' rel='stylesheet'>
 
 
1295
  <style>
1296
- *{margin:0;padding:0;box-sizing:border-box;font-family:'Noto+Sans+KR',sans-serif}
1297
- html,body{background:transparent;overflow:hidden;width:100vw;height:100vh}
1298
- @keyframes slideUp{from{transform:translateY(20px);opacity:0}to{transform:none;opacity:1}}
1299
- @keyframes badgePop{from{transform:scale(0.6);opacity:0}to{transform:scale(1);opacity:1}}
1300
- @keyframes pulse{0%%,100%%{opacity:1}50%%{opacity:.3}}
1301
- @keyframes itemIn{from{transform:translateX(8px);opacity:0}to{transform:none;opacity:1}}
1302
- #panel{position:fixed;bottom:24px;right:20px;width:min(96vw,360px);z-index:9999;animation:slideUp .4s cubic-bezier(.34,1.56,.64,1);pointer-events:auto}
1303
- #badge{position:fixed;bottom:24px;right:20px;display:flex;align-items:center;gap:9px;
1304
- background:linear-gradient(135deg,#1a2035,#131820);border:1px solid %(B)s;
1305
- border-radius:40px;padding:10px 20px;cursor:pointer;z-index:9999;
1306
- box-shadow:0 8px 32px rgba(0,0,0,.6);animation:badgePop .35s cubic-bezier(.34,1.56,.64,1);
1307
- pointer-events:auto;user-select:none}
1308
- #badge:hover{border-color:#fff}
1309
- .tab-btn{transition:all .15s}
1310
- .tab-btn:hover{opacity:.9!important}
1311
- .alert-item{transition:all .15s;border:1px solid transparent;cursor:pointer}
1312
- .alert-item:hover{background:rgba(255,255,255,.06)!important;transform:translateX(-2px)}
1313
- .min-btn:hover{color:rgba(255,255,255,.7)!important;background:rgba(255,255,255,.08)!important}
1314
- #body::-webkit-scrollbar{width:3px}
1315
- #body::-webkit-scrollbar-thumb{background:rgba(255,255,255,.15);border-radius:3px}
1316
- </style></head><body>
1317
-
1318
- <div id='badge' style='display:%(DMIN)s'>
1319
- <span style='font-size:20px;position:relative;line-height:1'>&#x1F514;
1320
- <span style='position:absolute;top:-6px;right:-9px;background:%(B)s;color:#fff;
1321
- border-radius:10px;font-size:9px;font-weight:700;min-width:17px;height:17px;
1322
- display:flex;align-items:center;justify-content:center;padding:0 3px;
1323
- font-family:DM Mono,monospace;box-shadow:0 0 8px %(B)s80'>%(N)s</span>
1324
- </span>
1325
- <span style='font-size:12px;font-weight:700;color:#e8eaf0'>μ•ŒλžŒ %(N)s개</span>
1326
- <span style='width:6px;height:6px;border-radius:50%%;background:%(B)s;animation:pulse 1.5s infinite;display:inline-block'></span>
1327
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1328
 
1329
- <div id='panel' style='display:%(DPAN)s'>
1330
- <div style='background:linear-gradient(135deg,#1e2538,#161c2c);border:1px solid rgba(255,255,255,.09);border-bottom:none;border-radius:16px 16px 0 0;padding:13px 14px 0'>
1331
- <div style='display:flex;align-items:center;justify-content:space-between;margin-bottom:12px'>
1332
- <div style='display:flex;align-items:center;gap:7px'>
1333
- <div style='width:7px;height:7px;border-radius:50%%;background:#FF6B35;animation:pulse 1.5s infinite;box-shadow:0 0 8px rgba(255,107,53,.7)'></div>
1334
- <span style='color:#eef2f7;font-size:12px;font-weight:700;letter-spacing:.08em'>LIVE ALERTS</span>
1335
- <span style='background:rgba(229,62,62,.15);border:1px solid rgba(229,62,62,.3);border-radius:5px;padding:1px 7px;font-size:10px;color:#E53E3E;font-weight:700'>%(N)s</span>
1336
- </div>
1337
- <div style='display:flex;align-items:center;gap:6px'>
1338
- <div style='background:rgba(255,255,255,.06);border-radius:8px;padding:3px 9px;display:flex;align-items:center;gap:4px'>
1339
- <span style='font-size:11px'>&#x23F1;</span>
1340
- <span id='timer' style='font-size:11px;font-weight:700;font-family:DM Mono,monospace;color:%(TC)s'>%(T)ss</span>
 
 
 
 
1341
  </div>
1342
- <button class='min-btn' onclick='minimize()' style='background:transparent;border:1px solid rgba(255,255,255,.1);border-radius:6px;color:rgba(255,255,255,.35);font-size:15px;padding:3px 8px;cursor:pointer;line-height:1'>&#x2212;</button>
1343
  </div>
 
1344
  </div>
1345
- <div id='tabs' style='display:flex;gap:3px'></div>
1346
  </div>
1347
- <div id='body' style='background:linear-gradient(180deg,#161c2a,#111620);border:1px solid rgba(255,255,255,.09);border-radius:0 0 16px 16px;max-height:260px;overflow-y:auto;padding:6px'></div>
1348
- <button class='min-btn' onclick='minimize()' style='width:100%%%%;margin-top:4px;padding:6px;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);border-radius:9px;color:rgba(255,255,255,.35);font-size:11px;cursor:pointer;font-family:Noto Sans KR,sans-serif'>&#x2212; μ΅œμ†Œν™”</button>
1349
  </div>
1350
 
1351
  <script>
1352
- var M=%(IMIN)s, T=%(T)s, TAB=%(ITAB)s;
1353
- var TABS=%(TAB_JSON)s;
1354
- var DATA=%(DATA_JSON)s;
1355
- var te=document.getElementById('timer');
1356
-
1357
- function renderTabs(){
1358
- var el=document.getElementById('tabs'); el.innerHTML='';
1359
- Object.keys(TABS).forEach(function(tab){
1360
- var tc=TABS[tab], cnt=DATA[tab].length, isAct=tab===TAB;
1361
- var d=document.createElement('div');
1362
- d.className='tab-btn';
1363
- d.style.cssText='flex:1;background:'+(isAct?tc.bg:'transparent')+
1364
- ';border:1px solid '+(isAct?tc.border:'rgba(255,255,255,0.06)')+
1365
- ';border-bottom:'+(isAct?'2px solid '+tc.accent:'1px solid transparent')+
1366
- ';border-radius:8px 8px 0 0;padding:7px 3px;cursor:pointer;'+
1367
- 'display:flex;flex-direction:column;align-items:center;gap:2px;'+
1368
- 'opacity:'+(isAct?'1':'0.55')+';';
1369
- var bgb=cnt>0?tc.accent:'rgba(255,255,255,0.15)';
1370
- var lc=isAct?tc.accent:'rgba(255,255,255,0.4)';
1371
- d.innerHTML='<span style="font-size:13px">'+tc.icon+'</span>'+
1372
- '<span style="font-size:9px;font-weight:700;color:'+lc+'">'+tab+'</span>'+
1373
- '<span style="background:'+bgb+';color:#fff;border-radius:8px;'+
1374
- 'min-width:16px;height:16px;display:flex;align-items:center;'+
1375
- 'justify-content:center;font-size:9px;font-weight:700;padding:0 4px">'+cnt+'</span>';
1376
- d.onclick=(function(t){return function(){switchTab(t);};})(tab);
1377
- el.appendChild(d);
1378
- });
1379
- }
1380
-
1381
- function renderBody(){
1382
- var el=document.getElementById('body');
1383
- var tc=TABS[TAB], items=DATA[TAB];
1384
- el.style.borderTop='2px solid '+tc.accent;
1385
- if(!items.length){
1386
- el.innerHTML='<p style="text-align:center;padding:24px;color:rgba(255,255,255,0.2);font-size:13px;margin:0">μ•ŒλžŒ μ—†μŒ</p>';
1387
- return;
1388
- }
1389
- el.innerHTML='';
1390
- items.forEach(function(item,i){
1391
- var d=document.createElement('div');
1392
- d.className='alert-item';
1393
- d.style.cssText='display:flex;align-items:center;gap:10px;padding:9px 11px;border-radius:10px;margin-bottom:'+(i<items.length-1?'3px':'0')+';';
1394
- d.style.animation='itemIn .3s ease '+(i*0.07)+'s both';
1395
- d.innerHTML=
1396
- '<div style="width:40px;height:40px;border-radius:9px;flex-shrink:0;'+
1397
- 'background:'+tc.bg+';border:1px solid '+tc.border+';'+
1398
- 'display:flex;align-items:center;justify-content:center;'+
1399
- 'font-size:9px;font-weight:800;color:'+tc.accent+';'+
1400
- 'font-family:DM Mono,monospace">'+item.ticker.slice(0,4)+'</div>'+
1401
- '<div style="flex:1;min-width:0">'+
1402
- '<div style="font-size:12px;font-weight:700;color:#eef2f7;margin-bottom:2px">'+
1403
- item.ticker+' <span style="font-size:10px;color:rgba(255,255,255,0.3);font-weight:400">'+item.name+'</span></div>'+
1404
- '<div style="font-size:11px;color:rgba(255,255,255,0.3)">'+item.price+'</div>'+
1405
- '</div>'+
1406
- '<div style="text-align:right;flex-shrink:0">'+
1407
- '<div style="font-size:12px;font-weight:700;color:'+tc.accent+'">'+item.pct_str+'</div>'+
1408
- '<div style="font-size:10px;color:rgba(255,255,255,0.2);margin-top:1px">&#x2192; 뢄석</div>'+
1409
- '</div>';
1410
- d.onclick=(function(tk){return function(){send('goto:'+tk);};})(item.ticker);
1411
- el.appendChild(d);
1412
- });
1413
- }
1414
-
1415
- renderTabs(); renderBody();
1416
-
1417
- var iv=setInterval(function(){
1418
- if(M)return; T--;
1419
- if(T<=0){clearInterval(iv);minimize();send('expired');return;}
1420
- if(te){te.textContent=T+'s';te.style.color=T<=15?'#E53E3E':T<=30?'#EAB308':'#8B98B4';}
1421
- },1000);
1422
-
1423
- function send(a){window.parent.postMessage({type:'alert_action',action:a},'*');}
1424
- function minimize(){M=true;document.getElementById('panel').style.display='none';document.getElementById('badge').style.display='flex';send('minimize');}
1425
- function openPanel(){
1426
- M=false; T=60; clearInterval(iv);
1427
- iv=setInterval(function(){if(M)return;T--;if(T<=0){clearInterval(iv);minimize();send('expired');return;}if(te){te.textContent=T+'s';te.style.color=T<=15?'#E53E3E':T<=30?'#EAB308':'#8B98B4';}},1000);
1428
- if(te){te.textContent='60s';te.style.color='#8B98B4';}
1429
- document.getElementById('badge').style.display='none';
1430
- document.getElementById('panel').style.display='block';
1431
- send('open');
1432
- }
1433
- function switchTab(t){TAB=t;renderTabs();renderBody();send('tab:'+t);}
1434
- document.getElementById('badge').onclick=openPanel;
1435
- </script>
1436
- </body></html>""" % {
1437
- "B": B, "T": T, "N": N, "TC": TC,
1438
- "DMIN": DMIN, "DPAN": DPAN, "IMIN": IMIN, "ITAB": ITAB,
1439
- "TAB_JSON": tab_json, "DATA_JSON": data_json,
1440
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1441
 
1442
- # postMessage β†’ URL query λ³€ν™˜ (Streamlit λ¦¬λ Œλ” 트리거)
1443
- st.markdown("""
1444
- <script>
1445
- window.addEventListener('message', function(e){
1446
- if(!e.data||e.data.type!=='alert_action') return;
1447
- var base=window.location.href.split('?')[0];
1448
- window.location.href=base+'?alert_action='+encodeURIComponent(e.data.action);
1449
- });
1450
- </script>""", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1451
 
1452
  components.html(html, height=0, scrolling=False)
1453
 
@@ -1456,7 +1543,6 @@ window.addEventListener('message', function(e){
1456
  # 9. 메인 λΌμš°νŒ…
1457
  # ============================================================
1458
 
1459
- # ── μ•ŒλžŒ νŒ¨λ„ query_params μ•‘μ…˜ 처리 (μ΅œμƒλ‹¨) ────────────────
1460
  _ap = st.query_params.get("alert_action", "")
1461
  if _ap:
1462
  st.query_params.clear()
@@ -1519,7 +1605,6 @@ elif st.session_state.main_menu == "βŒ‚ ν™ˆ & μŠ€μΊ”":
1519
  """, unsafe_allow_html=True)
1520
 
1521
  if not st.session_state.df.empty:
1522
- # β˜… NEW: κ·Έλ£Ήν•‘ μ•ŒλžŒ νŒ¨λ„ (κΈ°μ‘΄ render_alert_banners λŒ€μ²΄)
1523
  render_grouped_alert_panel(prices, rate)
1524
 
1525
  with st.spinner("포트폴리였 뢄석 쀑..."):
 
26
  # ============================================================
27
  st.set_page_config(page_title="Invest Pro Alpha", layout="wide", initial_sidebar_state="collapsed")
28
 
 
29
  NAV_CSS = """
30
  div.element-container:has(.nav-marker) + div {
31
  position: fixed !important; bottom: 0 !important; left: 0 !important;
 
66
  div.element-container:has(.nav-marker) + div button:active em { color: #C9A84C !important; }
67
  """
68
 
 
69
  PORTFOLIO_ROW_CSS = """
70
  div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stColumns"],
71
  div.element-container:has(.portfolio-item-row-marker) + div [data-testid="stHorizontalBlock"] {
 
87
  div.element-container:has(.action-marker.log) + div button:hover { color: #C9A84C !important; transform: scale(1.15) !important; }
88
  """
89
 
 
90
  CARD_CSS = """
91
  div.element-container:has(.scan-marker) + div.element-container button {
92
  background: #0F1623 !important;
 
152
  }
153
  """
154
 
 
155
  COMPONENT_CSS = """
156
  .menu-overlay-btn > button {
157
  background: #0F1623 !important;
 
296
  0%, 100% { opacity: 1; }
297
  50% { opacity: 0.65; }
298
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  """
300
 
301
  def load_css():
 
424
  color: #EEF2F7 !important;
425
  }}
426
 
427
+ /* ── μ•ŒλžŒ νŒ¨λ„ iframe κ³ μ • ── */
428
+ iframe[title="components.v1.html"] {{
429
+ position: fixed !important;
430
+ top: 0 !important;
431
+ left: 0 !important;
432
+ width: 100vw !important;
433
+ height: 100vh !important;
434
+ border: none !important;
435
+ z-index: 2147483640 !important;
436
+ background: transparent !important;
437
+ pointer-events: none !important;
438
+ }}
439
+ div:has(> iframe[title="components.v1.html"]) {{
440
+ height: 0 !important;
441
+ overflow: visible !important;
442
+ position: static !important;
443
+ }}
444
+
445
  {NAV_CSS}
446
  {PORTFOLIO_ROW_CSS}
447
  {CARD_CSS}
 
459
  if 'show_menu' not in st.session_state: st.session_state.show_menu = False
460
  if 'main_menu' not in st.session_state: st.session_state.main_menu = "βŒ‚ ν™ˆ & μŠ€μΊ”"
461
 
 
462
  if 'alert_panel_minimized' not in st.session_state: st.session_state.alert_panel_minimized = False
463
  if 'alert_panel_start_time' not in st.session_state: st.session_state.alert_panel_start_time = time.time()
464
+ if 'alert_active_tab' not in st.session_state: st.session_state.alert_active_tab = None
465
 
466
  def _key_hash():
467
  return hashlib.sha256(st.session_state.api_key.encode()).hexdigest()[:16]
 
1071
  )
1072
 
1073
  # ============================================================
1074
+ # 8. κ·Έλ£Ήν•‘ μ•ŒλžŒ νŒ¨λ„ (μ™„μ „ μž¬μž‘μ„± β€” HuggingFace Spaces ν˜Έν™˜)
1075
  # ============================================================
1076
 
1077
  def _build_alert_groups(prices, rate):
 
 
 
 
 
1078
  groups = {"κΈ‰λ³€": [], "맀수": [], "읡절": [], "μŠ€ν†±λ‘œμŠ€": []}
1079
  if st.session_state.df.empty:
1080
  return groups
 
1096
  current_price=int(ck), avg_price=int(ap),
1097
  target_price=tgp, action=act)
1098
 
 
1099
  if abs(pct) >= 15:
1100
  groups["κΈ‰λ³€"].append(item)
1101
  continue
1102
 
 
1103
  if not act:
1104
  continue
1105
 
 
1113
  return groups
1114
 
1115
 
1116
+ def _navigate_to_ticker(ticker):
 
 
1117
  in_portfolio = ticker in st.session_state.df['티컀'].values if not st.session_state.df.empty else False
1118
  if in_portfolio:
1119
  st.session_state.detail_ticker = ticker
1120
  st.session_state.main_menu = "β–€ μžμ‚° 상세 진단"
1121
  st.session_state.p_diag_mode = False
1122
+ st.session_state.pop('active_ticker', None)
1123
  else:
1124
  st.session_state.active_ticker = ticker
1125
  st.session_state.main_menu = "βŒ‚ ν™ˆ & μŠ€μΊ”"
1126
  st.session_state.p_diag_mode = False
1127
+ st.session_state.pop('detail_ticker', None)
1128
 
1129
 
1130
  def render_grouped_alert_panel(prices, rate):
 
1131
  groups = _build_alert_groups(prices, rate)
1132
  total_cnt = sum(len(v) for v in groups.values())
1133
  if total_cnt == 0:
 
1151
 
1152
  if st.session_state.alert_active_tab not in TAB_CFG:
1153
  for pt in ["μŠ€ν†±λ‘œμŠ€", "κΈ‰λ³€", "읡절", "맀수"]:
1154
+ if groups[pt]:
1155
+ st.session_state.alert_active_tab = pt
1156
+ break
1157
+ else:
1158
+ st.session_state.alert_active_tab = "κΈ‰λ³€"
1159
  active_tab = st.session_state.alert_active_tab
1160
 
 
1161
  data = {}
1162
  for tab, tc in TAB_CFG.items():
1163
  rows = []
 
1171
  })
1172
  data[tab] = rows
1173
 
1174
+ tab_json = json.dumps(
1175
+ {t: {"icon": v["icon"], "accent": v["accent"], "bg": v["bg"], "border": v["border"]}
1176
+ for t, v in TAB_CFG.items()},
1177
+ ensure_ascii=False
1178
+ )
1179
  data_json = json.dumps(data, ensure_ascii=False)
1180
  timer_col = "#E53E3E" if time_left <= 15 else ("#EAB308" if time_left <= 30 else "#8B98B4")
1181
 
1182
+ B = badge_col
1183
+ T = str(time_left)
1184
+ N = str(total_cnt)
1185
+ TC = timer_col
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1186
  IMIN = "true" if minimized else "false"
1187
  ITAB = json.dumps(active_tab, ensure_ascii=False)
1188
+ # CSS display 값은 직접 λ¬Έμžμ—΄λ‘œ 처리 (% ν¬λ§€νŒ… 좩돌 λ°©μ§€)
1189
+ DMIN = "flex" if minimized else "none"
1190
+ DPAN = "none" if minimized else "flex"
1191
 
1192
+ html_template = """<!DOCTYPE html>
1193
+ <html>
1194
+ <head>
1195
+ <meta charset="utf-8">
1196
+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@600;700;800&family=Noto+Sans+KR:wght@400;500;700;900&display=swap" rel="stylesheet">
1197
  <style>
1198
+ * { margin:0; padding:0; box-sizing:border-box; }
1199
+ html, body {
1200
+ background: transparent;
1201
+ overflow: hidden;
1202
+ width: 100vw;
1203
+ height: 100vh;
1204
+ font-family: 'Noto Sans KR', sans-serif;
1205
+ }
1206
+ #alert-root {
1207
+ position: fixed;
1208
+ bottom: 24px;
1209
+ right: 20px;
1210
+ z-index: 9999;
1211
+ pointer-events: auto;
1212
+ }
1213
+ #badge {
1214
+ align-items: center;
1215
+ gap: 10px;
1216
+ background: linear-gradient(135deg, #1a1f2e 0%%, #151921 100%%);
1217
+ border: 1px solid __BADGE_COL__;
1218
+ border-radius: 40px;
1219
+ padding: 10px 20px;
1220
+ cursor: pointer;
1221
+ box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04);
1222
+ animation: badgePop 0.4s cubic-bezier(0.34,1.56,0.64,1);
1223
+ user-select: none;
1224
+ transition: border-color 0.2s;
1225
+ }
1226
+ #badge:hover { border-color: rgba(255,255,255,0.3); }
1227
+ .badge-dot {
1228
+ width: 6px; height: 6px; border-radius: 50%%;
1229
+ background: __BADGE_COL__;
1230
+ animation: pulse 1.5s infinite;
1231
+ display: inline-block;
1232
+ }
1233
+ #panel {
1234
+ flex-direction: column;
1235
+ width: min(96vw, 380px);
1236
+ animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
1237
+ }
1238
+ .p-header {
1239
+ background: linear-gradient(135deg, #1e2538 0%%, #161c2c 100%%);
1240
+ border: 1px solid rgba(255,255,255,0.09);
1241
+ border-bottom: none;
1242
+ border-radius: 16px 16px 0 0;
1243
+ padding: 14px 16px 0;
1244
+ }
1245
+ .p-header-row {
1246
+ display: flex; align-items: center;
1247
+ justify-content: space-between;
1248
+ margin-bottom: 14px;
1249
+ }
1250
+ .live-dot {
1251
+ width: 8px; height: 8px; border-radius: 50%%;
1252
+ background: #FF6B35;
1253
+ box-shadow: 0 0 8px rgba(255,107,53,0.8);
1254
+ animation: pulse 1.5s infinite;
1255
+ display: inline-block;
1256
+ }
1257
+ .live-label {
1258
+ font-size: 12px; font-weight: 700; color: #e8eaf0;
1259
+ letter-spacing: 0.08em;
1260
+ font-family: 'JetBrains Mono', monospace;
1261
+ }
1262
+ .total-badge {
1263
+ background: rgba(229,62,62,0.15);
1264
+ border: 1px solid rgba(229,62,62,0.3);
1265
+ border-radius: 5px; padding: 1px 7px;
1266
+ font-size: 10px; color: #E53E3E; font-weight: 700;
1267
+ font-family: 'JetBrains Mono', monospace;
1268
+ }
1269
+ .timer-wrap {
1270
+ display: flex; align-items: center; gap: 5px;
1271
+ background: rgba(255,255,255,0.06);
1272
+ border-radius: 8px; padding: 4px 10px;
1273
+ }
1274
+ .min-btn {
1275
+ background: transparent;
1276
+ border: 1px solid rgba(255,255,255,0.1);
1277
+ border-radius: 6px;
1278
+ color: rgba(255,255,255,0.35);
1279
+ font-size: 16px; padding: 3px 9px;
1280
+ cursor: pointer; line-height: 1;
1281
+ transition: all 0.15s;
1282
+ font-family: 'JetBrains Mono', monospace;
1283
+ }
1284
+ .min-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); }
1285
+ .tabs-row { display: flex; gap: 4px; }
1286
+ .tab-btn {
1287
+ flex: 1;
1288
+ border: 1px solid rgba(255,255,255,0.06);
1289
+ border-bottom: none;
1290
+ border-radius: 8px 8px 0 0;
1291
+ padding: 8px 3px;
1292
+ cursor: pointer;
1293
+ display: flex; flex-direction: column; align-items: center; gap: 3px;
1294
+ transition: all 0.18s;
1295
+ background: transparent;
1296
+ }
1297
+ .tab-btn:hover { opacity: 0.9 !important; }
1298
+ .tab-icon { font-size: 14px; }
1299
+ .tab-label { font-size: 9px; font-weight: 700; letter-spacing: 0.04em; font-family: 'Noto Sans KR', sans-serif; }
1300
+ .tab-count {
1301
+ border-radius: 8px; min-width: 16px; height: 16px;
1302
+ display: flex; align-items: center; justify-content: center;
1303
+ font-size: 9px; font-weight: 700; padding: 0 4px; color: #fff;
1304
+ font-family: 'JetBrains Mono', monospace;
1305
+ }
1306
+ .p-body {
1307
+ background: linear-gradient(180deg, #161c2a 0%%, #111620 100%%);
1308
+ border: 1px solid rgba(255,255,255,0.09);
1309
+ border-radius: 0 0 16px 16px;
1310
+ max-height: 280px;
1311
+ overflow-y: auto;
1312
+ padding: 8px;
1313
+ }
1314
+ .p-body::-webkit-scrollbar { width: 3px; }
1315
+ .p-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
1316
+ .alert-item {
1317
+ display: flex; align-items: center; gap: 12px;
1318
+ padding: 10px 12px;
1319
+ border-radius: 10px;
1320
+ cursor: pointer;
1321
+ border: 1px solid transparent;
1322
+ margin-bottom: 4px;
1323
+ transition: all 0.15s ease;
1324
+ animation: itemIn 0.3s ease both;
1325
+ }
1326
+ .alert-item:last-child { margin-bottom: 0; }
1327
+ .alert-item:hover { background: rgba(255,255,255,0.06) !important; transform: translateX(-2px); }
1328
+ .ticker-box {
1329
+ width: 40px; height: 40px; border-radius: 10px;
1330
+ display: flex; align-items: center; justify-content: center;
1331
+ flex-shrink: 0;
1332
+ font-size: 9px; font-weight: 800; letter-spacing: -0.02em;
1333
+ font-family: 'JetBrains Mono', monospace;
1334
+ }
1335
+ .item-name { font-size: 12px; font-weight: 700; color: #e8eaf0; margin-bottom: 2px; }
1336
+ .item-sub { font-size: 10px; color: rgba(255,255,255,0.35); font-family: 'Noto Sans KR', sans-serif; }
1337
+ .item-price { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 1px; font-family: 'Noto Sans KR', sans-serif; }
1338
+ .item-pct { font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
1339
+ .item-arrow { font-size: 10px; color: rgba(255,255,255,0.25); margin-top: 2px; }
1340
+ .empty-msg { text-align: center; padding: 24px; color: rgba(255,255,255,0.2); font-size: 13px; }
1341
+ @keyframes slideUp {
1342
+ from { transform: translateY(30px); opacity: 0; }
1343
+ to { transform: translateY(0); opacity: 1; }
1344
+ }
1345
+ @keyframes badgePop {
1346
+ from { transform: scale(0.5); opacity: 0; }
1347
+ to { transform: scale(1); opacity: 1; }
1348
+ }
1349
+ @keyframes pulse {
1350
+ 0%%, 100%% { opacity: 1; }
1351
+ 50%% { opacity: 0.3; }
1352
+ }
1353
+ @keyframes itemIn {
1354
+ from { transform: translateX(10px); opacity: 0; }
1355
+ to { transform: translateX(0); opacity: 1; }
1356
+ }
1357
+ </style>
1358
+ </head>
1359
+ <body>
1360
+ <div id="alert-root">
1361
+
1362
+ <!-- μ΅œμ†Œν™” λ°°μ§€ -->
1363
+ <div id="badge" style="display:__DMIN__;">
1364
+ <span style="font-size:20px;position:relative;line-height:1;">&#x1F514;
1365
+ <span style="position:absolute;top:-7px;right:-10px;
1366
+ background:__BADGE_COL__;color:#fff;border-radius:10px;
1367
+ font-size:9px;font-weight:700;min-width:18px;height:18px;
1368
+ display:flex;align-items:center;justify-content:center;padding:0 4px;
1369
+ font-family:'JetBrains Mono',monospace;
1370
+ box-shadow:0 0 8px __BADGE_COL__80;">__N__</span>
1371
+ </span>
1372
+ <span style="font-size:13px;font-weight:700;color:#e8eaf0;font-family:'JetBrains Mono',monospace;">μ•ŒλžŒ __N__개</span>
1373
+ <span class="badge-dot"></span>
1374
+ </div>
1375
 
1376
+ <!-- ν’€ νŒ¨λ„ -->
1377
+ <div id="panel" style="display:__DPAN__;">
1378
+ <div class="p-header">
1379
+ <div class="p-header-row">
1380
+ <div style="display:flex;align-items:center;gap:8px;">
1381
+ <span class="live-dot"></span>
1382
+ <span class="live-label">LIVE ALERTS</span>
1383
+ <span class="total-badge">__N__</span>
1384
+ </div>
1385
+ <div style="display:flex;align-items:center;gap:6px;">
1386
+ <div class="timer-wrap">
1387
+ <span style="font-size:12px;">&#x23F1;</span>
1388
+ <span id="timer-txt"
1389
+ style="font-size:11px;font-weight:700;font-family:'JetBrains Mono',monospace;color:__TC__;">__T__s</span>
1390
+ </div>
1391
+ <button class="min-btn" onclick="minimize()">&#x2212;</button>
1392
  </div>
 
1393
  </div>
1394
+ <div class="tabs-row" id="tabs-row"></div>
1395
  </div>
1396
+ <div class="p-body" id="panel-body"></div>
1397
  </div>
1398
+
 
1399
  </div>
1400
 
1401
  <script>
1402
+ var MINIMIZED = __IMIN__;
1403
+ var TIME_LEFT = __T__;
1404
+ var ACTIVE_TAB = __ITAB__;
1405
+ var TABS = __TAB_JSON__;
1406
+ var DATA = __DATA_JSON__;
1407
+ var timerEl = document.getElementById('timer-txt');
1408
+
1409
+ function renderTabs() {
1410
+ var el = document.getElementById('tabs-row');
1411
+ el.innerHTML = '';
1412
+ Object.keys(TABS).forEach(function(tab) {
1413
+ var tc = TABS[tab];
1414
+ var cnt = DATA[tab].length;
1415
+ var isA = (tab === ACTIVE_TAB);
1416
+ var btn = document.createElement('div');
1417
+ btn.className = 'tab-btn';
1418
+ btn.style.cssText =
1419
+ 'background:' + (isA ? tc.bg : 'transparent') + ';' +
1420
+ 'border-color:' + (isA ? tc.border : 'rgba(255,255,255,0.06)') + ';' +
1421
+ 'border-bottom:' + (isA ? '2px solid ' + tc.accent : '1px solid transparent') + ';' +
1422
+ 'opacity:' + (isA ? '1' : '0.55') + ';';
1423
+ btn.innerHTML =
1424
+ '<span class="tab-icon">' + tc.icon + '</span>' +
1425
+ '<span class="tab-label" style="color:' + (isA ? tc.accent : 'rgba(255,255,255,0.4)') + '">' + tab + '</span>' +
1426
+ '<span class="tab-count" style="background:' + (cnt > 0 ? tc.accent : 'rgba(255,255,255,0.15)') + '">' + cnt + '</span>';
1427
+ btn.onclick = (function(t) { return function() { switchTab(t); }; })(tab);
1428
+ el.appendChild(btn);
1429
+ });
1430
+ }
1431
+
1432
+ function renderBody() {
1433
+ var el = document.getElementById('panel-body');
1434
+ var tc = TABS[ACTIVE_TAB];
1435
+ var items = DATA[ACTIVE_TAB];
1436
+ el.style.borderTop = '2px solid ' + tc.accent;
1437
+ el.innerHTML = '';
1438
+ if (!items.length) {
1439
+ el.innerHTML = '<div class="empty-msg">μ•ŒλžŒ μ—†μŒ</div>';
1440
+ return;
1441
+ }
1442
+ items.forEach(function(item, i) {
1443
+ var row = document.createElement('div');
1444
+ row.className = 'alert-item';
1445
+ row.style.animationDelay = (i * 0.06) + 's';
1446
+ row.innerHTML =
1447
+ '<div class="ticker-box" style="background:' + tc.bg + ';border:1px solid ' + tc.border + ';color:' + tc.accent + ';">' +
1448
+ item.ticker.slice(0, 4) +
1449
+ '</div>' +
1450
+ '<div style="flex:1;min-width:0;">' +
1451
+ '<div class="item-name">' + item.ticker + ' <span class="item-sub">' + item.name + '</span></div>' +
1452
+ '<div class="item-price">' + item.price + '</div>' +
1453
+ '</div>' +
1454
+ '<div style="text-align:right;flex-shrink:0;">' +
1455
+ '<div class="item-pct" style="color:' + tc.accent + ';">' + item.pct_str + '</div>' +
1456
+ '<div class="item-arrow">&#x2192; 뢄석</div>' +
1457
+ '</div>';
1458
+ row.onclick = (function(tk) { return function() { sendAction('goto:' + tk); }; })(item.ticker);
1459
+ el.appendChild(row);
1460
+ });
1461
+ }
1462
+
1463
+ renderTabs();
1464
+ renderBody();
1465
+
1466
+ var iv = setInterval(function() {
1467
+ if (MINIMIZED) return;
1468
+ TIME_LEFT--;
1469
+ if (TIME_LEFT <= 0) {
1470
+ clearInterval(iv);
1471
+ minimize();
1472
+ sendAction('expired');
1473
+ return;
1474
+ }
1475
+ if (timerEl) {
1476
+ timerEl.textContent = TIME_LEFT + 's';
1477
+ timerEl.style.color = TIME_LEFT <= 15 ? '#E53E3E' : (TIME_LEFT <= 30 ? '#EAB308' : '#8B98B4');
 
 
 
 
 
 
 
 
 
 
 
 
1478
  }
1479
+ }, 1000);
1480
+
1481
+ function minimize() {
1482
+ MINIMIZED = true;
1483
+ document.getElementById('panel').style.display = 'none';
1484
+ document.getElementById('badge').style.display = 'flex';
1485
+ sendAction('minimize');
1486
+ }
1487
+
1488
+ function openPanel() {
1489
+ MINIMIZED = false;
1490
+ TIME_LEFT = 60;
1491
+ clearInterval(iv);
1492
+ iv = setInterval(function() {
1493
+ if (MINIMIZED) return;
1494
+ TIME_LEFT--;
1495
+ if (TIME_LEFT <= 0) { clearInterval(iv); minimize(); sendAction('expired'); return; }
1496
+ if (timerEl) {
1497
+ timerEl.textContent = TIME_LEFT + 's';
1498
+ timerEl.style.color = TIME_LEFT <= 15 ? '#E53E3E' : (TIME_LEFT <= 30 ? '#EAB308' : '#8B98B4');
1499
+ }
1500
+ }, 1000);
1501
+ if (timerEl) { timerEl.textContent = '60s'; timerEl.style.color = '#8B98B4'; }
1502
+ document.getElementById('badge').style.display = 'none';
1503
+ document.getElementById('panel').style.display = 'flex';
1504
+ sendAction('open');
1505
+ }
1506
 
1507
+ function switchTab(t) {
1508
+ ACTIVE_TAB = t;
1509
+ renderTabs();
1510
+ renderBody();
1511
+ sendAction('tab:' + t);
1512
+ }
1513
+
1514
+ document.getElementById('badge').onclick = openPanel;
1515
+
1516
+ function sendAction(action) {
1517
+ try {
1518
+ var base = window.parent.location.href.split('?')[0];
1519
+ window.parent.location.href = base + '?alert_action=' + encodeURIComponent(action);
1520
+ } catch(e) {}
1521
+ }
1522
+ </script>
1523
+ </body>
1524
+ </html>"""
1525
+
1526
+ # ν”Œλ ˆμ΄μŠ€ν™€λ” μΉ˜ν™˜ (% ν¬λ§€νŒ… μ™„μ „ 우회)
1527
+ html = html_template
1528
+ html = html.replace("__BADGE_COL__", B)
1529
+ html = html.replace("__N__", N)
1530
+ html = html.replace("__T__", T)
1531
+ html = html.replace("__TC__", TC)
1532
+ html = html.replace("__DMIN__", DMIN)
1533
+ html = html.replace("__DPAN__", DPAN)
1534
+ html = html.replace("__IMIN__", IMIN)
1535
+ html = html.replace("__ITAB__", ITAB)
1536
+ html = html.replace("__TAB_JSON__", tab_json)
1537
+ html = html.replace("__DATA_JSON__", data_json)
1538
 
1539
  components.html(html, height=0, scrolling=False)
1540
 
 
1543
  # 9. 메인 λΌμš°νŒ…
1544
  # ============================================================
1545
 
 
1546
  _ap = st.query_params.get("alert_action", "")
1547
  if _ap:
1548
  st.query_params.clear()
 
1605
  """, unsafe_allow_html=True)
1606
 
1607
  if not st.session_state.df.empty:
 
1608
  render_grouped_alert_panel(prices, rate)
1609
 
1610
  with st.spinner("포트폴리였 뢄석 쀑..."):