{
  "dashboard_title": "Symbol Overview",
  "description": "Company profiles, source health, recent documents, and market snapshot for tracked symbols.",
  "slug": "symbol-overview",
  "position_json": {
    "HEADER_ID": {"id": "HEADER_ID", "type": "HEADER", "meta": {"text": "Symbol Overview"}},
    "ROW-1": {
      "type": "ROW",
      "children": ["CHART-tracked-symbols-kpi", "CHART-total-documents-kpi", "CHART-total-extractions-kpi", "CHART-active-signals-kpi"]
    },
    "ROW-2": {
      "type": "ROW",
      "children": ["CHART-company-summary-table"]
    },
    "ROW-3": {
      "type": "ROW",
      "children": ["CHART-recent-documents-timeseries", "CHART-document-type-breakdown"]
    },
    "ROW-4": {
      "type": "ROW",
      "children": ["CHART-latest-prices-table"]
    },
    "ROW-5": {
      "type": "ROW",
      "children": ["CHART-recent-documents-table"]
    }
  },
  "metadata": {
    "refresh_frequency": 300,
    "default_filters": "{}",
    "color_scheme": "supersetColors"
  },
  "charts": [
    {
      "slice_name": "Tracked Symbols",
      "viz_type": "big_number_total",
      "description": "Count of distinct symbols with documents in the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(DISTINCT ticker) AS tracked_symbols FROM lakehouse.stonks.documents WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Total Documents (30d)",
      "viz_type": "big_number_total",
      "description": "Total documents ingested in the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS total_documents FROM lakehouse.stonks.documents WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Total Extractions (30d)",
      "viz_type": "big_number_total",
      "description": "Total AI extractions completed in the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS total_extractions FROM lakehouse.stonks.document_extractions WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Active Signals (7d)",
      "viz_type": "big_number_total",
      "description": "Trade signals generated in the last 7 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS active_signals FROM lakehouse.stonks.trade_signals WHERE dt >= CURRENT_DATE - INTERVAL '7' DAY"
    },
    {
      "slice_name": "Company Summary",
      "viz_type": "table",
      "description": "Per-symbol summary with document counts, extraction counts, latest signal, and latest price",
      "datasource_type": "trino",
      "query": "SELECT d.ticker, COUNT(DISTINCT d.document_id) AS documents_30d, COUNT(DISTINCT de.document_id) AS extractions_30d, MAX(d.published_at) AS latest_document_at, MAX(ts.generated_at) AS latest_signal_at, MAX(ts.trend_direction) AS latest_trend, MAX(mb.close_price) AS latest_close FROM lakehouse.stonks.documents d LEFT JOIN lakehouse.stonks.document_extractions de ON d.ticker = de.ticker AND de.dt >= CURRENT_DATE - INTERVAL '30' DAY LEFT JOIN lakehouse.stonks.trade_signals ts ON d.ticker = ts.ticker AND ts.dt = (SELECT MAX(dt) FROM lakehouse.stonks.trade_signals WHERE ticker = d.ticker) LEFT JOIN lakehouse.stonks.market_bars mb ON d.ticker = mb.ticker AND mb.dt = (SELECT MAX(dt) FROM lakehouse.stonks.market_bars WHERE ticker = d.ticker) WHERE d.dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY d.ticker ORDER BY d.ticker"
    },
    {
      "slice_name": "Documents Ingested Over Time",
      "viz_type": "echarts_timeseries_bar",
      "description": "Daily document ingestion counts by source type over the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT dt AS bucket, source_type, COUNT(*) AS doc_count FROM lakehouse.stonks.documents WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY dt, source_type ORDER BY dt",
      "params": {
        "x_axis": "bucket",
        "metrics": ["doc_count"],
        "groupby": ["source_type"],
        "time_grain_sqla": "P1D"
      }
    },
    {
      "slice_name": "Document Type Breakdown",
      "viz_type": "pie",
      "description": "Distribution of documents by type in the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT document_type, COUNT(*) AS count FROM lakehouse.stonks.documents WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY document_type ORDER BY count DESC"
    },
    {
      "slice_name": "Latest Prices by Symbol",
      "viz_type": "table",
      "description": "Most recent closing prices and volume for each tracked symbol",
      "datasource_type": "trino",
      "query": "SELECT mb.ticker, mb.close_price, mb.open_price, mb.high_price, mb.low_price, mb.volume, mb.vwap, mb.bar_timestamp FROM lakehouse.stonks.market_bars mb INNER JOIN (SELECT ticker, MAX(bar_timestamp) AS max_ts FROM lakehouse.stonks.market_bars GROUP BY ticker) latest ON mb.ticker = latest.ticker AND mb.bar_timestamp = latest.max_ts ORDER BY mb.ticker"
    },
    {
      "slice_name": "Recent Documents",
      "viz_type": "table",
      "description": "Most recently ingested documents across all symbols",
      "datasource_type": "trino",
      "query": "SELECT ticker, document_type, source_type, title, publisher, published_at, retrieved_at, confidence FROM lakehouse.stonks.documents WHERE dt >= CURRENT_DATE - INTERVAL '7' DAY ORDER BY retrieved_at DESC LIMIT 50"
    }
  ]
}
