File size: 2,537 Bytes
c6262df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
CRE dashboard (spec Β§11) β€” SKELETON STUB. Step 4, not yet implemented.

The continuing agent should build the real dashboard here per the design brief
(Build Log Entry 003 + decision D10) and HANDOFF.md Β§1:

  β€’ Dark theme, Nunito font, SVG logo + uniform SVG animations, `Ver. 1.0` tag,
    live status badges, Title Case labels, responsive.
  β€’ 4 tabs: Signals (conviction-ranked, colored tags 🟣🟒🟑βšͺ, Chart + TV links),
    Market, Performance (spec Β§7 analytics), Health.
  β€’ Live updates via gr.Timer β€” NO page refresh (D10).

CONTRACT (app.py depends on this): expose `build(get_state)` returning a
`gr.Blocks`. `get_state` is a zero-arg callable returning the live
workers.UniverseState (or None during boot). app.py already lazy-imports this and
falls back to its built-in placeholder UI if `build` raises β€” so the app keeps
running until this is finished.

Read data via store.db helpers:
  db.recent_signals(), db.active_signals(), db.latest_snapshots(),
  db.liq_baseline_days(symbol), db.query(sql, params)
Conviction tag colors live in alerts/telegram._TAG_EMOJI; mirror them as CSS
accent colors (Elite=violet, Strong=green, Moderate=amber, Watch=grey).
"""
from __future__ import annotations

import gradio as gr

import config
from store import db

# Conviction tag β†’ accent color (use for colored tags in the Signals tab)
TAG_COLORS = {"elite": "#a855f7", "strong": "#22c55e", "moderate": "#eab308", "watch": "#9ca3af"}


def _status_md() -> str:
    """Minimal live status β€” placeholder until the full 4-tab UI is built."""
    try:
        n_sig = len(db.recent_signals(100000))
        n_active = len(db.active_signals())
        n_mkt = len(db.latest_snapshots())
    except Exception:
        n_sig = n_active = n_mkt = 0
    return (
        f"### πŸš€ Confluence Reversal Engine β€” Ver. 1.0\n"
        f"_Dashboard skeleton β€” full 4-tab UI is the remaining Step 4 (see HANDOFF.md)._\n\n"
        f"- Signals Logged: **{n_sig}**  Β·  Active: **{n_active}**\n"
        f"- Market Snapshots: **{n_mkt}**\n"
        f"- Alerts: **{'On' if config.ALERTS_ENABLED else 'Off'}**"
    )


def build(get_state) -> gr.Blocks:
    """Return the dashboard Blocks. STUB: status + live timer only.

    Replace the body with the full themed 4-tab dashboard. Keep this signature.
    """
    with gr.Blocks(title="CRE v1.0", theme=gr.themes.Base()) as demo:
        status = gr.Markdown(_status_md())
        timer = gr.Timer(5.0)
        timer.tick(_status_md, outputs=status)
    return demo