Update src/app.py
Browse files- src/app.py +237 -1
src/app.py
CHANGED
|
@@ -1121,7 +1121,8 @@ REPO_ID = "ditgun/my-invest-db"
|
|
| 1121 |
DB_FILE = "my_assets_v30.csv"
|
| 1122 |
CACHE_FILE = "analysis_cache_v31.json"
|
| 1123 |
FAV_FILE = "my_fav_v30.csv"
|
| 1124 |
-
TRADE_FILE
|
|
|
|
| 1125 |
|
| 1126 |
_OWNED_NEW_FIELDS = {"thesis_validity", "action_analysis", "additional_buy_analysis", "target_remaining", "portfolio_context_judgment"}
|
| 1127 |
_SCAN_NEW_FIELDS = {"growth_moat_quantitative", "growth_moat_qualitative", "catalyst", "entry_zones", "portfolio_fit"}
|
|
@@ -1224,6 +1225,234 @@ def save_cache():
|
|
| 1224 |
json.dump(d, f, ensure_ascii=False, indent=2, default=_s)
|
| 1225 |
_hf_ul(CACHE_FILE)
|
| 1226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1227 |
# ============================================================
|
| 1228 |
# AI ํ๋กฌํํธ
|
| 1229 |
# ============================================================
|
|
@@ -3255,6 +3484,7 @@ if st.session_state.show_menu:
|
|
| 3255 |
elif st.session_state.main_menu == "โ ํ & ์ค์บ":
|
| 3256 |
prices = get_all_prices()
|
| 3257 |
rate = get_exchange_rate()
|
|
|
|
| 3258 |
|
| 3259 |
if 'active_ticker' not in st.session_state:
|
| 3260 |
t_cost = t_val = 0
|
|
@@ -3374,6 +3604,7 @@ elif st.session_state.main_menu == "โ ํ & ์ค์บ":
|
|
| 3374 |
st.session_state.full_stock_reports[scan_key] = {
|
| 3375 |
"date": today_str, "report": report, "avg_price": 0
|
| 3376 |
}
|
|
|
|
| 3377 |
save_cache()
|
| 3378 |
else:
|
| 3379 |
report = stored_scan["report"]
|
|
@@ -3426,10 +3657,12 @@ elif st.session_state.main_menu == "โ ํ & ์ค์บ":
|
|
| 3426 |
|
| 3427 |
draw_chart(tn)
|
| 3428 |
render_scan_report(report, analyst_target_krw=tp, current_price_krw=p)
|
|
|
|
| 3429 |
|
| 3430 |
elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
| 3431 |
prices = get_all_prices()
|
| 3432 |
rate = get_exchange_rate()
|
|
|
|
| 3433 |
|
| 3434 |
if st.session_state.get('p_diag_mode'):
|
| 3435 |
if st.button("์ต์ ๋ฐ์ดํฐ๋ก ์ฌ์ง๋จ", key="port_reanalyze", use_container_width=True):
|
|
@@ -3528,6 +3761,7 @@ elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
|
| 3528 |
)
|
| 3529 |
if report and "action_type" in report:
|
| 3530 |
st.session_state.full_stock_reports[ukey] = {"date":today_str,"report":report,"avg_price":row['ํ๋จ๊ฐ']}
|
|
|
|
| 3531 |
save_cache()
|
| 3532 |
else:
|
| 3533 |
report = stored["report"]; has_rich = True
|
|
@@ -3584,6 +3818,7 @@ elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
|
| 3584 |
|
| 3585 |
draw_chart(dt)
|
| 3586 |
render_owned_report(report, analyst_target_krw=tp, current_price_krw=cur_k)
|
|
|
|
| 3587 |
|
| 3588 |
elif not st.session_state.get('p_diag_mode'):
|
| 3589 |
st.markdown("### ๋ณด์ ์์ฐ ๊ด๋ฆฌ")
|
|
@@ -3783,6 +4018,7 @@ elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
|
| 3783 |
st.session_state.p_diag_mode = True; st.rerun()
|
| 3784 |
|
| 3785 |
st.divider()
|
|
|
|
| 3786 |
st.markdown("### ๋ด ํฌํธํด๋ฆฌ์ค")
|
| 3787 |
|
| 3788 |
# โโ ํฌํธํด๋ฆฌ์ค ์นด๋: v16 ๋ฐฉ์ (st.button + action-marker) ์ผ๋ก ๋ฒํผ ์๋
|
|
|
|
| 1121 |
DB_FILE = "my_assets_v30.csv"
|
| 1122 |
CACHE_FILE = "analysis_cache_v31.json"
|
| 1123 |
FAV_FILE = "my_fav_v30.csv"
|
| 1124 |
+
TRADE_FILE = "my_trades_v30.csv"
|
| 1125 |
+
HISTORY_FILE = "portfolio_history_v1.json"
|
| 1126 |
|
| 1127 |
_OWNED_NEW_FIELDS = {"thesis_validity", "action_analysis", "additional_buy_analysis", "target_remaining", "portfolio_context_judgment"}
|
| 1128 |
_SCAN_NEW_FIELDS = {"growth_moat_quantitative", "growth_moat_qualitative", "catalyst", "entry_zones", "portfolio_fit"}
|
|
|
|
| 1225 |
json.dump(d, f, ensure_ascii=False, indent=2, default=_s)
|
| 1226 |
_hf_ul(CACHE_FILE)
|
| 1227 |
|
| 1228 |
+
# ============================================================
|
| 1229 |
+
# โ
ํ์คํ ๋ฆฌ: ๋ก๋ / ์ ์ฅ / ์ค๋
์ท / ๋ฆฌํฌํธ ๊ธฐ๋ก
|
| 1230 |
+
# ============================================================
|
| 1231 |
+
if "portfolio_history" not in st.session_state:
|
| 1232 |
+
_hf_dl(HISTORY_FILE)
|
| 1233 |
+
try:
|
| 1234 |
+
with open(HISTORY_FILE, "r", encoding="utf-8") as _hf:
|
| 1235 |
+
_hdata = json.load(_hf)
|
| 1236 |
+
st.session_state.portfolio_history = _hdata.get("portfolio_snapshots", [])
|
| 1237 |
+
st.session_state.report_history = _hdata.get("report_history", {})
|
| 1238 |
+
except:
|
| 1239 |
+
st.session_state.portfolio_history = []
|
| 1240 |
+
st.session_state.report_history = {}
|
| 1241 |
+
|
| 1242 |
+
def save_history():
|
| 1243 |
+
def _s(o):
|
| 1244 |
+
if hasattr(o, "item"): return o.item()
|
| 1245 |
+
raise TypeError
|
| 1246 |
+
payload = {
|
| 1247 |
+
"portfolio_snapshots": st.session_state.portfolio_history,
|
| 1248 |
+
"report_history": st.session_state.report_history,
|
| 1249 |
+
}
|
| 1250 |
+
with open(HISTORY_FILE, "w", encoding="utf-8") as f:
|
| 1251 |
+
json.dump(payload, f, ensure_ascii=False, indent=2, default=_s)
|
| 1252 |
+
_hf_ul(HISTORY_FILE)
|
| 1253 |
+
|
| 1254 |
+
def _take_portfolio_snapshot(prices, rate):
|
| 1255 |
+
"""์ค๋ ๋ ์ง ์ค๋
์ท์ด ์์ผ๋ฉด ํฌํธํด๋ฆฌ์ค ์์ต๋ฅ ๊ธฐ๋ก (ํ๋ฃจ 1ํ)."""
|
| 1256 |
+
today = datetime.now().strftime("%Y-%m-%d")
|
| 1257 |
+
history = st.session_state.portfolio_history
|
| 1258 |
+
if history and history[-1].get("date") == today:
|
| 1259 |
+
return
|
| 1260 |
+
if st.session_state.df.empty:
|
| 1261 |
+
return
|
| 1262 |
+
total_cost = total_val = 0.0
|
| 1263 |
+
snapshots = []
|
| 1264 |
+
for _, row in st.session_state.df.iterrows():
|
| 1265 |
+
t = row["ํฐ์ปค"]; ap = float(row["ํ๋จ๊ฐ"]); qty = float(row["์๋"])
|
| 1266 |
+
ck = prices.get(t, 0) * rate
|
| 1267 |
+
if ck <= 0: ck = ap
|
| 1268 |
+
pct = (ck / ap - 1) * 100 if ap > 0 else 0
|
| 1269 |
+
total_cost += ap * qty; total_val += ck * qty
|
| 1270 |
+
snapshots.append({"ticker": t, "pct": round(pct, 2)})
|
| 1271 |
+
port_pct = (total_val / total_cost - 1) * 100 if total_cost > 0 else 0
|
| 1272 |
+
history.append({
|
| 1273 |
+
"date": today,
|
| 1274 |
+
"total_cost": round(total_cost),
|
| 1275 |
+
"total_val": round(total_val),
|
| 1276 |
+
"pct": round(port_pct, 2),
|
| 1277 |
+
"snapshots": snapshots,
|
| 1278 |
+
})
|
| 1279 |
+
st.session_state.portfolio_history = history[-180:]
|
| 1280 |
+
save_history()
|
| 1281 |
+
|
| 1282 |
+
def _record_report_history(key: str, report: dict):
|
| 1283 |
+
"""AI ๋ฆฌํฌํธ๋ฅผ key๋ณ๋ก ๋ ์ง ์์ผ๋ก ์ต๋ 10๊ฐ ๋ณด๊ด."""
|
| 1284 |
+
if not report or not isinstance(report, dict): return
|
| 1285 |
+
rh = st.session_state.report_history
|
| 1286 |
+
today = datetime.now().strftime("%Y-%m-%d")
|
| 1287 |
+
if key not in rh:
|
| 1288 |
+
rh[key] = []
|
| 1289 |
+
if rh[key] and rh[key][-1].get("date") == today:
|
| 1290 |
+
rh[key][-1]["report"] = report
|
| 1291 |
+
else:
|
| 1292 |
+
rh[key].append({"date": today, "report": report})
|
| 1293 |
+
rh[key] = rh[key][-10:]
|
| 1294 |
+
save_history()
|
| 1295 |
+
|
| 1296 |
+
# ============================================================
|
| 1297 |
+
# โ
ํ์คํ ๋ฆฌ ๋ ๋๋ง ํจ์
|
| 1298 |
+
# ============================================================
|
| 1299 |
+
def render_portfolio_history_chart():
|
| 1300 |
+
"""ํฌํธํด๋ฆฌ์ค ์์ต๋ฅ ํ์๋ผ์ธ ์ฐจํธ."""
|
| 1301 |
+
history = st.session_state.get("portfolio_history", [])
|
| 1302 |
+
if len(history) < 2:
|
| 1303 |
+
st.markdown(
|
| 1304 |
+
'<div style="background:#111111; border:1px solid rgba(255,255,255,0.07); border-radius:10px; '
|
| 1305 |
+
'padding:16px; text-align:center; color:#444444; font-size:13px; margin-bottom:16px;">'
|
| 1306 |
+
'๐ ์์ต๋ฅ ํ์๋ผ์ธ์ ์ดํ ์ด์ ๊ธฐ๋ก์ด ์์ด๋ฉด ํ์๋ฉ๋๋ค.</div>',
|
| 1307 |
+
unsafe_allow_html=True,
|
| 1308 |
+
)
|
| 1309 |
+
return
|
| 1310 |
+
df_h = pd.DataFrame(history)
|
| 1311 |
+
df_h["date"] = pd.to_datetime(df_h["date"])
|
| 1312 |
+
latest = df_h.iloc[-1]; first = df_h.iloc[0]
|
| 1313 |
+
delta = latest["pct"] - first["pct"]
|
| 1314 |
+
delta_color = "#AAAAAA" if delta >= 0 else "#9ABBE0"
|
| 1315 |
+
st.markdown(
|
| 1316 |
+
f'<div style="display:flex; align-items:baseline; justify-content:space-between; margin-bottom:6px;">'
|
| 1317 |
+
f'<span style="font-size:10px; font-weight:700; color:#444444; letter-spacing:2px; text-transform:uppercase;">๐ ํฌํธํด๋ฆฌ์ค ์์ต๋ฅ ํ์๋ผ์ธ</span>'
|
| 1318 |
+
f'<span style="font-size:11px; color:{delta_color}; font-weight:700; font-family:IBM Plex Mono,monospace;">'
|
| 1319 |
+
f'๋์ ๋ณํ {delta:+.2f}%p</span></div>',
|
| 1320 |
+
unsafe_allow_html=True,
|
| 1321 |
+
)
|
| 1322 |
+
fill_color = "rgba(170,170,170,0.07)" if latest["pct"] >= 0 else "rgba(154,187,224,0.07)"
|
| 1323 |
+
line_color = "#AAAAAA" if latest["pct"] >= 0 else "#9ABBE0"
|
| 1324 |
+
fig = go.Figure()
|
| 1325 |
+
fig.add_trace(go.Scatter(
|
| 1326 |
+
x=df_h["date"], y=df_h["pct"], mode="lines+markers",
|
| 1327 |
+
line=dict(color=line_color, width=2), marker=dict(size=5, color=line_color),
|
| 1328 |
+
fill="tozeroy", fillcolor=fill_color,
|
| 1329 |
+
hovertemplate="%{x|%Y-%m-%d}<br>์์ต๋ฅ %{y:.2f}%<extra></extra>",
|
| 1330 |
+
))
|
| 1331 |
+
fig.add_hline(y=0, line_dash="dot", line_color="rgba(255,255,255,0.12)", line_width=1)
|
| 1332 |
+
fig.update_layout(
|
| 1333 |
+
height=200, margin=dict(l=0, r=0, t=0, b=0),
|
| 1334 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 1335 |
+
xaxis=dict(showgrid=False, color="#444444", tickfont=dict(size=10)),
|
| 1336 |
+
yaxis=dict(showgrid=True, gridcolor="rgba(255,255,255,0.04)", color="#444444",
|
| 1337 |
+
tickfont=dict(size=10), ticksuffix="%"),
|
| 1338 |
+
hovermode="x unified",
|
| 1339 |
+
)
|
| 1340 |
+
st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
|
| 1341 |
+
# ์ต๊ทผ 7์ผ ํ
์ด๋ธ
|
| 1342 |
+
recent = df_h.tail(7).iloc[::-1]
|
| 1343 |
+
rows_html = ""
|
| 1344 |
+
for _, r in recent.iterrows():
|
| 1345 |
+
pc = "#AAAAAA" if r["pct"] >= 0 else "#9ABBE0"
|
| 1346 |
+
rows_html += (
|
| 1347 |
+
f'<div style="display:flex; justify-content:space-between; align-items:center; '
|
| 1348 |
+
f'padding:7px 12px; border-bottom:1px solid rgba(255,255,255,0.04);">'
|
| 1349 |
+
f'<span style="font-size:12px; color:#888888;">{r["date"].strftime("%m/%d")}</span>'
|
| 1350 |
+
f'<span style="font-size:12px; font-weight:700; color:#EBEBEB; font-family:IBM Plex Mono,monospace;">{int(r["total_val"]):,}์</span>'
|
| 1351 |
+
f'<span style="font-size:12px; font-weight:700; color:{pc}; font-family:IBM Plex Mono,monospace;">{r["pct"]:+.2f}%</span>'
|
| 1352 |
+
f'</div>'
|
| 1353 |
+
)
|
| 1354 |
+
st.markdown(
|
| 1355 |
+
f'<div style="background:#111111; border:1px solid rgba(255,255,255,0.07); border-radius:8px; '
|
| 1356 |
+
f'overflow:hidden; margin-top:8px; margin-bottom:16px;">'
|
| 1357 |
+
f'<div style="display:flex; justify-content:space-between; padding:6px 12px; '
|
| 1358 |
+
f'background:rgba(255,255,255,0.03); font-size:9px; font-weight:700; color:#444444; '
|
| 1359 |
+
f'letter-spacing:1.5px; text-transform:uppercase;"><span>๋ ์ง</span><span>ํ๊ฐ์ก</span><span>์์ต๋ฅ </span></div>'
|
| 1360 |
+
f'{rows_html}</div>',
|
| 1361 |
+
unsafe_allow_html=True,
|
| 1362 |
+
)
|
| 1363 |
+
with st.expander("๐ ์ข
๋ชฉ๋ณ ์์ต๋ฅ ์ถ์ด", expanded=False):
|
| 1364 |
+
all_tickers = sorted(set(s["ticker"] for snap in history for s in snap.get("snapshots", [])))
|
| 1365 |
+
if not all_tickers: return
|
| 1366 |
+
fig2 = go.Figure()
|
| 1367 |
+
palette = ["#D8D8D8","#9ABBE0","#AAAAAA","#888888","#C9A84C","#E0E0E0","#7AABDA"]
|
| 1368 |
+
for i, tk in enumerate(all_tickers[:7]):
|
| 1369 |
+
dates_tk = []; pcts_tk = []
|
| 1370 |
+
for snap in history:
|
| 1371 |
+
for s in snap.get("snapshots", []):
|
| 1372 |
+
if s["ticker"] == tk:
|
| 1373 |
+
dates_tk.append(snap["date"]); pcts_tk.append(s["pct"]); break
|
| 1374 |
+
if len(dates_tk) < 2: continue
|
| 1375 |
+
fig2.add_trace(go.Scatter(
|
| 1376 |
+
x=pd.to_datetime(dates_tk), y=pcts_tk, mode="lines+markers", name=tk,
|
| 1377 |
+
line=dict(color=palette[i % len(palette)], width=1.5), marker=dict(size=4),
|
| 1378 |
+
hovertemplate=f"{tk}: %{{y:.2f}}%<extra></extra>",
|
| 1379 |
+
))
|
| 1380 |
+
fig2.add_hline(y=0, line_dash="dot", line_color="rgba(255,255,255,0.10)", line_width=1)
|
| 1381 |
+
fig2.update_layout(
|
| 1382 |
+
height=220, margin=dict(l=0, r=0, t=10, b=0),
|
| 1383 |
+
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
|
| 1384 |
+
xaxis=dict(showgrid=False, color="#444444", tickfont=dict(size=10)),
|
| 1385 |
+
yaxis=dict(showgrid=True, gridcolor="rgba(255,255,255,0.04)", color="#444444",
|
| 1386 |
+
tickfont=dict(size=10), ticksuffix="%"),
|
| 1387 |
+
legend=dict(font=dict(size=10, color="#888888"), bgcolor="rgba(0,0,0,0)"),
|
| 1388 |
+
hovermode="x unified",
|
| 1389 |
+
)
|
| 1390 |
+
st.plotly_chart(fig2, use_container_width=True, config={"displayModeBar": False})
|
| 1391 |
+
|
| 1392 |
+
|
| 1393 |
+
def render_report_history_diff(key: str, current_report: dict):
|
| 1394 |
+
"""AI ๋ฆฌํฌํธ ๋ณํ ๋น๊ต ๋ทฐ โ render_owned_report / render_scan_report ์งํ์ ํธ์ถ."""
|
| 1395 |
+
rh = st.session_state.get("report_history", {}).get(key, [])
|
| 1396 |
+
if len(rh) < 2: return
|
| 1397 |
+
with st.expander("๐ ์ด์ AI ๋ถ์๊ณผ ๋น๊ต", expanded=False):
|
| 1398 |
+
sorted_rh = sorted(rh, key=lambda x: x["date"], reverse=True)
|
| 1399 |
+
dates = [r["date"] for r in sorted_rh]
|
| 1400 |
+
today_date = dates[0]
|
| 1401 |
+
sel_date = st.selectbox("๋น๊ตํ ๋ ์ง ์ ํ", dates[1:], key=f"rh_sel_{key}")
|
| 1402 |
+
prev_report = next((r["report"] for r in sorted_rh if r["date"] == sel_date), None)
|
| 1403 |
+
if not prev_report: return
|
| 1404 |
+
COMPARE_FIELDS = [
|
| 1405 |
+
("recommendation_stars", "๋ณ์ "),
|
| 1406 |
+
("action_type", "ํ๋จ"),
|
| 1407 |
+
("confidence_score", "์ ๋ขฐ๋"),
|
| 1408 |
+
("summary", "ํ์ค ์์ฝ"),
|
| 1409 |
+
]
|
| 1410 |
+
changed = []; unchanged = []
|
| 1411 |
+
for field, label in COMPARE_FIELDS:
|
| 1412 |
+
cur_val = current_report.get(field, "-"); prev_val = prev_report.get(field, "-")
|
| 1413 |
+
if str(cur_val) != str(prev_val): changed.append((field, label, prev_val, cur_val))
|
| 1414 |
+
else: unchanged.append((label, cur_val))
|
| 1415 |
+
if changed:
|
| 1416 |
+
st.markdown('<div style="font-size:10px; font-weight:700; color:#D8D8D8; letter-spacing:1.5px; '
|
| 1417 |
+
'text-transform:uppercase; margin-bottom:8px;">๐ ๋ณ๊ฒฝ๋ ํญ๋ชฉ</div>', unsafe_allow_html=True)
|
| 1418 |
+
for field, label, prev_val, cur_val in changed:
|
| 1419 |
+
def _act_color(v):
|
| 1420 |
+
v = str(v)
|
| 1421 |
+
if "๋งค์" in v or "์ถ๊ฐ" in v: return "#E0E0E0"
|
| 1422 |
+
if "์ต์ " in v: return "#9ABBE0"
|
| 1423 |
+
if "์์ " in v: return "#E05C5C"
|
| 1424 |
+
return "#888888"
|
| 1425 |
+
prev_c = _act_color(prev_val) if field == "action_type" else "#888888"
|
| 1426 |
+
cur_c = _act_color(cur_val) if field == "action_type" else "#EBEBEB"
|
| 1427 |
+
prev_str = str(prev_val)[:80] + ("โฆ" if len(str(prev_val)) > 80 else "")
|
| 1428 |
+
cur_str = str(cur_val)[:80] + ("โฆ" if len(str(cur_val)) > 80 else "")
|
| 1429 |
+
st.markdown(
|
| 1430 |
+
f'<div style="background:#111111; border:1px solid rgba(255,255,255,0.09); '
|
| 1431 |
+
f'border-left:3px solid #D8D8D8; border-radius:8px; padding:12px 14px; margin-bottom:8px;">'
|
| 1432 |
+
f'<div style="font-size:10px; color:#444444; font-weight:700; text-transform:uppercase; '
|
| 1433 |
+
f'letter-spacing:1px; margin-bottom:8px;">{label}</div>'
|
| 1434 |
+
f'<div style="display:grid; grid-template-columns:1fr 1fr; gap:10px;">'
|
| 1435 |
+
f'<div><div style="font-size:9px; color:#444444; margin-bottom:4px;">{sel_date} (์ด์ )</div>'
|
| 1436 |
+
f'<div style="font-size:13px; color:{prev_c}; line-height:1.6;">{prev_str}</div></div>'
|
| 1437 |
+
f'<div style="border-left:1px solid rgba(255,255,255,0.06); padding-left:10px;">'
|
| 1438 |
+
f'<div style="font-size:9px; color:#D8D8D8; font-weight:700; margin-bottom:4px;">{today_date} (์ต์ )</div>'
|
| 1439 |
+
f'<div style="font-size:13px; color:{cur_c}; line-height:1.6; font-weight:600;">{cur_str}</div>'
|
| 1440 |
+
f'</div></div></div>',
|
| 1441 |
+
unsafe_allow_html=True,
|
| 1442 |
+
)
|
| 1443 |
+
else:
|
| 1444 |
+
st.markdown('<div style="text-align:center; padding:16px; color:#444444; font-size:13px;">'
|
| 1445 |
+
'์ฃผ์ ํญ๋ชฉ ๋ณ๊ฒฝ ์์ (ํ๋จยท๋ณ์ ยท์ ๋ขฐ๋ยท์์ฝ ๋์ผ)</div>', unsafe_allow_html=True)
|
| 1446 |
+
if unchanged:
|
| 1447 |
+
with st.expander("๋ณ๊ฒฝ ์๋ ํญ๋ชฉ", expanded=False):
|
| 1448 |
+
for label, val in unchanged:
|
| 1449 |
+
st.markdown(
|
| 1450 |
+
f'<div style="display:flex; gap:12px; padding:7px 0; border-bottom:1px solid rgba(255,255,255,0.04);">'
|
| 1451 |
+
f'<span style="font-size:11px; color:#444444; min-width:70px;">{label}</span>'
|
| 1452 |
+
f'<span style="font-size:11px; color:#888888;">{str(val)[:80]}</span></div>',
|
| 1453 |
+
unsafe_allow_html=True,
|
| 1454 |
+
)
|
| 1455 |
+
|
| 1456 |
# ============================================================
|
| 1457 |
# AI ํ๋กฌํํธ
|
| 1458 |
# ============================================================
|
|
|
|
| 3484 |
elif st.session_state.main_menu == "โ ํ & ์ค์บ":
|
| 3485 |
prices = get_all_prices()
|
| 3486 |
rate = get_exchange_rate()
|
| 3487 |
+
_take_portfolio_snapshot(prices, rate)
|
| 3488 |
|
| 3489 |
if 'active_ticker' not in st.session_state:
|
| 3490 |
t_cost = t_val = 0
|
|
|
|
| 3604 |
st.session_state.full_stock_reports[scan_key] = {
|
| 3605 |
"date": today_str, "report": report, "avg_price": 0
|
| 3606 |
}
|
| 3607 |
+
_record_report_history(scan_key, report)
|
| 3608 |
save_cache()
|
| 3609 |
else:
|
| 3610 |
report = stored_scan["report"]
|
|
|
|
| 3657 |
|
| 3658 |
draw_chart(tn)
|
| 3659 |
render_scan_report(report, analyst_target_krw=tp, current_price_krw=p)
|
| 3660 |
+
render_report_history_diff(scan_key, report)
|
| 3661 |
|
| 3662 |
elif st.session_state.main_menu == "โค ์์ฐ ์์ธ ์ง๋จ":
|
| 3663 |
prices = get_all_prices()
|
| 3664 |
rate = get_exchange_rate()
|
| 3665 |
+
_take_portfolio_snapshot(prices, rate)
|
| 3666 |
|
| 3667 |
if st.session_state.get('p_diag_mode'):
|
| 3668 |
if st.button("์ต์ ๋ฐ์ดํฐ๋ก ์ฌ์ง๋จ", key="port_reanalyze", use_container_width=True):
|
|
|
|
| 3761 |
)
|
| 3762 |
if report and "action_type" in report:
|
| 3763 |
st.session_state.full_stock_reports[ukey] = {"date":today_str,"report":report,"avg_price":row['ํ๋จ๊ฐ']}
|
| 3764 |
+
_record_report_history(ukey, report)
|
| 3765 |
save_cache()
|
| 3766 |
else:
|
| 3767 |
report = stored["report"]; has_rich = True
|
|
|
|
| 3818 |
|
| 3819 |
draw_chart(dt)
|
| 3820 |
render_owned_report(report, analyst_target_krw=tp, current_price_krw=cur_k)
|
| 3821 |
+
render_report_history_diff(ukey, report)
|
| 3822 |
|
| 3823 |
elif not st.session_state.get('p_diag_mode'):
|
| 3824 |
st.markdown("### ๋ณด์ ์์ฐ ๊ด๋ฆฌ")
|
|
|
|
| 4018 |
st.session_state.p_diag_mode = True; st.rerun()
|
| 4019 |
|
| 4020 |
st.divider()
|
| 4021 |
+
render_portfolio_history_chart()
|
| 4022 |
st.markdown("### ๋ด ํฌํธํด๋ฆฌ์ค")
|
| 4023 |
|
| 4024 |
# โโ ํฌํธํด๋ฆฌ์ค ์นด๋: v16 ๋ฐฉ์ (st.button + action-marker) ์ผ๋ก ๋ฒํผ ์๋
|