{
  "dashboard_title": "Sentiment Heatmap",
  "description": "Market-wide sentiment visualization by sector and symbol, with trend direction and catalyst analysis.",
  "slug": "sentiment-heatmap",
  "position_json": {
    "HEADER_ID": {"id": "HEADER_ID", "type": "HEADER", "meta": {"text": "Sentiment Heatmap"}},
    "ROW-1": {
      "type": "ROW",
      "children": ["CHART-bullish-count-kpi", "CHART-bearish-count-kpi", "CHART-mixed-count-kpi", "CHART-avg-contradiction-kpi"]
    },
    "ROW-2": {
      "type": "ROW",
      "children": ["CHART-sentiment-heatmap"]
    },
    "ROW-3": {
      "type": "ROW",
      "children": ["CHART-sentiment-timeseries", "CHART-catalyst-breakdown"]
    },
    "ROW-4": {
      "type": "ROW",
      "children": ["CHART-contradiction-scatter", "CHART-sentiment-distribution"]
    },
    "ROW-5": {
      "type": "ROW",
      "children": ["CHART-symbol-sentiment-detail"]
    }
  },
  "metadata": {
    "refresh_frequency": 300,
    "default_filters": "{}",
    "color_scheme": "supersetColors"
  },
  "charts": [
    {
      "slice_name": "Bullish Signals (7d)",
      "viz_type": "big_number_total",
      "description": "Count of bullish trend signals in the last 7 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS bullish_count FROM lakehouse.stonks.trade_signals WHERE trend_direction = 'bullish' AND dt >= CURRENT_DATE - INTERVAL '7' DAY"
    },
    {
      "slice_name": "Bearish Signals (7d)",
      "viz_type": "big_number_total",
      "description": "Count of bearish trend signals in the last 7 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS bearish_count FROM lakehouse.stonks.trade_signals WHERE trend_direction = 'bearish' AND dt >= CURRENT_DATE - INTERVAL '7' DAY"
    },
    {
      "slice_name": "Mixed Signals (7d)",
      "viz_type": "big_number_total",
      "description": "Count of mixed or neutral trend signals in the last 7 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS mixed_count FROM lakehouse.stonks.trade_signals WHERE trend_direction IN ('mixed', 'neutral') AND dt >= CURRENT_DATE - INTERVAL '7' DAY"
    },
    {
      "slice_name": "Avg Contradiction Score (7d)",
      "viz_type": "big_number_total",
      "description": "Average contradiction score across all signals in the last 7 days",
      "datasource_type": "trino",
      "query": "SELECT ROUND(AVG(contradiction_score), 3) AS avg_contradiction FROM lakehouse.stonks.trade_signals WHERE dt >= CURRENT_DATE - INTERVAL '7' DAY"
    },
    {
      "slice_name": "Sentiment Heatmap by Symbol",
      "viz_type": "heatmap",
      "description": "Daily average sentiment impact score by symbol over the last 14 days",
      "datasource_type": "trino",
      "query": "SELECT de.ticker, de.dt, ROUND(AVG(de.impact_score), 3) AS avg_impact, AVG(CASE WHEN de.sentiment = 'positive' THEN 1.0 WHEN de.sentiment = 'negative' THEN -1.0 ELSE 0.0 END) AS sentiment_score FROM lakehouse.stonks.document_extractions de WHERE de.dt >= CURRENT_DATE - INTERVAL '14' DAY GROUP BY de.ticker, de.dt ORDER BY de.ticker, de.dt",
      "params": {
        "x_axis": "dt",
        "y_axis": "ticker",
        "metric": "sentiment_score"
      }
    },
    {
      "slice_name": "Sentiment Trend Over Time",
      "viz_type": "echarts_timeseries_line",
      "description": "Daily average sentiment score across all symbols over the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT de.dt AS bucket, ROUND(AVG(CASE WHEN de.sentiment = 'positive' THEN 1.0 WHEN de.sentiment = 'negative' THEN -1.0 ELSE 0.0 END), 3) AS avg_sentiment, COUNT(*) AS extraction_count FROM lakehouse.stonks.document_extractions de WHERE de.dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY de.dt ORDER BY de.dt"
    },
    {
      "slice_name": "Catalyst Type Breakdown",
      "viz_type": "pie",
      "description": "Distribution of catalyst types across extractions in the last 14 days",
      "datasource_type": "trino",
      "query": "SELECT catalyst_type, COUNT(*) AS count FROM lakehouse.stonks.document_extractions WHERE dt >= CURRENT_DATE - INTERVAL '14' DAY AND catalyst_type IS NOT NULL GROUP BY catalyst_type ORDER BY count DESC"
    },
    {
      "slice_name": "Contradiction vs Confidence",
      "viz_type": "echarts_timeseries_scatter",
      "description": "Scatter of contradiction score vs confidence for recent signals",
      "datasource_type": "trino",
      "query": "SELECT ticker, confidence, contradiction_score, trend_strength, trend_direction, dt FROM lakehouse.stonks.trade_signals WHERE dt >= CURRENT_DATE - INTERVAL '14' DAY ORDER BY dt DESC",
      "params": {
        "x_axis": "confidence",
        "y_axis": "contradiction_score",
        "groupby": ["trend_direction"]
      }
    },
    {
      "slice_name": "Sentiment Distribution by Symbol",
      "viz_type": "echarts_timeseries_bar",
      "description": "Count of positive, negative, and neutral extractions per symbol in the last 14 days",
      "datasource_type": "trino",
      "query": "SELECT ticker, sentiment, COUNT(*) AS count FROM lakehouse.stonks.document_extractions WHERE dt >= CURRENT_DATE - INTERVAL '14' DAY GROUP BY ticker, sentiment ORDER BY ticker, sentiment",
      "params": {
        "x_axis": "ticker",
        "metrics": ["count"],
        "groupby": ["sentiment"]
      }
    },
    {
      "slice_name": "Symbol Sentiment Detail",
      "viz_type": "table",
      "description": "Per-symbol sentiment summary with extraction counts, average impact, and dominant catalysts",
      "datasource_type": "trino",
      "query": "SELECT de.ticker, COUNT(*) AS extractions, ROUND(AVG(de.impact_score), 3) AS avg_impact, ROUND(AVG(de.confidence), 3) AS avg_confidence, ROUND(AVG(de.novelty_score), 3) AS avg_novelty, COUNT(CASE WHEN de.sentiment = 'positive' THEN 1 END) AS positive_count, COUNT(CASE WHEN de.sentiment = 'negative' THEN 1 END) AS negative_count, COUNT(CASE WHEN de.sentiment = 'neutral' THEN 1 END) AS neutral_count, ts.trend_direction AS latest_trend, ts.trend_strength AS latest_trend_strength FROM lakehouse.stonks.document_extractions de LEFT JOIN lakehouse.stonks.trade_signals ts ON de.ticker = ts.ticker AND ts.dt = (SELECT MAX(dt) FROM lakehouse.stonks.trade_signals WHERE ticker = de.ticker) WHERE de.dt >= CURRENT_DATE - INTERVAL '14' DAY GROUP BY de.ticker, ts.trend_direction, ts.trend_strength ORDER BY de.ticker"
    }
  ]
}
