8.1 KiB
Dashboard Rebuild — Multi-theme + Real Thai Data
For Hermes: Execute task-by-task, commit per task, verify with backend tests + browser. Plan mode — no code until user approves.
Goal: Rebuild the SET50 dashboard so it reflects REAL multi-theme Thai data (tourism + auto + energy + NPL), not the current tourism-only fixture, per the user's 10-point review.
Architecture: Replace the single-vertical tourism_result-driven dashboard with a multi-theme real-data source; add per-symbol theme exposure (multi-source factors PER theme); update all UI sections to read real data, Thai-only, and remove the 5 obsolete KPI cards + paper ledger.
The 10 user complaints → fix
| # | Complaint | Root cause | Fix |
|---|---|---|---|
| 1 | Theme Surprise ไม่เข้าใจ, ลบได้ | KPI card from tourism-only | Remove card |
| 2 | สัญญาณที่ใช้งาน: ซื้อ 7 แต่โชว์ 8 | total=8 (incl neutral) mislabeled | Show long/short/neutral correctly, Thai |
| 3 | สมุดบันทึก paper มีทำไม — ไม่มี paper trade แล้ว | legacy section | Remove (simulation replaces it) |
| 4 | คุณภาพข้อมูล — ข้อมูลจริงรึยัง? | TOURISM_SOURCE=fixture default |
Switch to real BOT data; show real source+as_of |
| 5 | ประตู backtest (blocked) เอาออก | legacy gate | Remove card (research is exploratory/forward) |
| 6 | แต่ละธีมควรดูหลายแหล่ง (ประชากร ฯลฯ) | 1 source/theme | Add multi-source factors per theme (see Data plan) |
| 7 | ตารางหุ้น + ตารางสัญญาณ ควรรวมกัน | split | Merge into one combined table |
| 8 | Theme surprise ไม่ครบ 3 ธีม | tourism-only | 3 theme surprise (auto, energy, tourism) |
| 9 | ที่มาข้อมูล ควรเป็นตาราง (แหล่ง+เวลา) | prose | Table of all sources + last fetched |
| 10 | บันทึกการวิเคราะห์ มีแค่ 1 ธีม | tourism thesis | Per-theme thesis (3) + multi-source note |
Overall: "ข้อมูลทั้งหมดตอนนี้ยังไม่ได้ใช้ข้อมูลจริงใช่ไหม?" → ใช่, dashboard ใช้ tourism_result (fixture default). Rebuild to real.
User-confirmed decisions (2026-08-25)
- Real data ONLY — switch to BOT real (no fixture fallback); dashboard fails if no real data.
- Theme surprise = z-score of each theme's headline factor (uniform across all themes).
- Multi-source per theme (A+B): wire existing multi-source (auto = volume + NPL + production + export); AND add broader macro (population/GDP/inflation) — found BOT SDDS page (bot.or.th/en/statistics/sdds.html) is server-rendered and scrapable WITHOUT auth: provides GDP (Q2/2026 4,793.5bn), Private Consumption +4.9%, Private Investment +18.1%, Manufacturing −3.1%, Population 70,472k, Headline Inflation 1.95%, Unemployment 0.93%. This is the macro backdrop layer (complaint #6).
Macro backdrop factor (new) — BOT SDDS collector
- Create
backend/app/macro_thai.py— scrape BOT SDDS HTML for: private consumption index %YoY, private investment %YoY, mfg production %YoY, population (thousands), headline inflation, core inflation, unemployment. Real Thai macro backdrop. - Wire into a "macro" theme/context read + into the sources table.
Backend task list
Task A: Real multi-theme dashboard source module
- Create
backend/app/dashboard.py— assembles REAL data from all collectors:- tourism (BOT real, via collector), auto_credit (Trading Econ + auto_npl BOT), energy (TOP), siamchart fundamentals, prices
- Returns
{themes: [{id, name, frequency, read_* , surprise}], board: [{symbol, combined_score, dividend, ...}], sources: [{from, source, as_of, fetched_at}], thesis_per_theme: {...}}
- Multi-source per theme (complaint #6): registry mapping theme → list of factor sources (not 1). E.g. auto theme = {new_car_sales_yoy (TradingEcon), auto_npl_pct (BOT), vehicle_production, auto_exports}. Add aggregatable fields.
- 3 theme surprise (#8): compute surprise per theme (z-score of the theme's headline factor), not just tourism.
Task B: Switch create_app to real data
backend/app/__init__.py: defaultTOURISM_SOURCE→bot(real), or better: buildmulti_dashboardfrom collectors at startup, keep tourism as one theme._load_default_snapshotno longer the dashboard root.dashboard/summary,/signals,/factorsendpoints → read fromdashboard.pyreal assembly, nottourism_result.
Task C: Sources table endpoint
dashboard.pycollectssourceslist: each {from (e.g. "TradingEconomics"), source, url, as_of, fetched_at, frequency}. Expose in/api/v1/themes+ summary.
Task D: Per-theme thesis (#10)
dashboard.pybuilds a short deterministic thesis per theme from that theme's factor readings (not a hardcoded tourism sentence).
Frontend task list
Task F: Remove 5 obsolete items (#1,#3,#5)
- Delete cards: Theme Surprise (#1), คุณภาพข้อมูล (#4 replaced by honest sources), ประตู backtest (#5), สมุดบันทึก paper (#3) → card 2 (สัญญาณ) only + 3-theme panel.
- Remove paper-ledger UI + backtest-gate UI blocks (already partially removed paper ledger; remove backtest KPI).
Task G: Correct signal count (#2)
- Show
long/short/neutralas separate Thai chips; value = long only, with "+X ซื้อ −Y ขาย" clearly, no off-by-one.
Task H: Merge stock + signal tables (#7)
- Single combined table: [สีสัญญาณ, symbol, theme(s), combined_score, dividend, PE, EPS YoY, Yield, P/BV, ROE] — one table, sortable, dividend filter.
Task I: Sources table UI (#9)
- Render
sourcesas a<table>: ตัวจาก, แหล่ง, ข้อมูล, as_of, fetched_at, frequency.
Task J: 3-theme surprise + thesis (#8,#10)
- Theme panel shows 3 themes, each with its own surprise + read + thesis.
Task K: Thai-only consistency + visual verify
- Audit all remaining English; keep only technical terms. Browser verify at 1440/1024/768. Screenshot for user.
Multi-source factor registry (complaint #6) — where to add data
For "แต่ละธีมดูข้อมูลรอบด้านของประเทศ" — extend themes to multiple Thai sources:
- Auto: new_car_sales_yoy (TradingEcon) + auto_npl_pct (BOT) + vehicle_production + auto_exports (TradingEcon) [already in collector]
- Energy: TOP net_profit/ebitda + Thai retail fuel/EPPO + (optional) import/refining
- Tourism: BOT tourism surprise + arrivals + hotel occupancy
- Macro backdrop (new): Thai population / GDP (BOT API — needs auth, mark deferred) per user's "จำนวนประชากร"
Note: Full multi-source (population/GDP via BOT portal API) requires API key registration — mark as a separate later task; this plan wires the already-available multi-source readings per theme.
Verification
- Backend: full suite passes; live
/api/v1/themesshows 3 themes with real Thai readings + sources table + per-theme thesis; no fixture. - Frontend:
npm run build; browser shows combined single table, 3-theme surprise, sources table, no removed cards; Thai-only. - Screenshot evidence for user review before push (push gate).
Open questions / risks
- Real-vs-fixture default: Should dashboard run on BOT real data by default (needs a fetch), or keep a cache so it works offline? → Recommend: real BOT via daily cache, fallback to last-good.
- Population/GDP macro: needs BOT portal API key (user registers). Defer unless user provides key.
- Theme surprise definition: need concrete per-theme surprise metric — z-score on each theme's headline factor (auto YoY, energy net profit trend, tourism surprise). Confirm with user if ambiguous.
- Push gate: after visual verify, user approves before push (per repo convention).