{
  "__inputs": [
    {
      "name": "DS_EXOVO",
      "label": "Exovo PostgreSQL",
      "description": "PostgreSQL datasource pointed at the Exovo database (user exovo_reporting)",
      "type": "datasource",
      "pluginId": "grafana-postgresql-datasource",
      "pluginName": "PostgreSQL"
    }
  ],
  "title": "Exovo — Call Overview",
  "description": "Sample dashboard over the reporting.* views. Import, pick your Exovo PostgreSQL datasource, done.",
  "tags": ["exovo", "pbx"],
  "timezone": "browser",
  "schemaVersion": 39,
  "time": { "from": "now-30d", "to": "now" },
  "panels": [
    {
      "type": "timeseries",
      "title": "Calls per day",
      "datasource": { "type": "grafana-postgresql-datasource", "uid": "${DS_EXOVO}" },
      "gridPos": { "h": 9, "w": 16, "x": 0, "y": 0 },
      "targets": [
        {
          "refId": "A",
          "format": "time_series",
          "rawSql": "SELECT day AS time, direction AS metric, calls FROM reporting.calls_daily WHERE $__timeFilter(day) ORDER BY day"
        }
      ]
    },
    {
      "type": "stat",
      "title": "Answer rate",
      "datasource": { "type": "grafana-postgresql-datasource", "uid": "${DS_EXOVO}" },
      "gridPos": { "h": 9, "w": 8, "x": 16, "y": 0 },
      "fieldConfig": { "defaults": { "unit": "percentunit", "decimals": 1 } },
      "targets": [
        {
          "refId": "A",
          "format": "table",
          "rawSql": "SELECT COUNT(answer_time)::float / NULLIF(COUNT(*), 0) AS answer_rate FROM reporting.calls WHERE $__timeFilter(start_time) AND direction = 'inbound'"
        }
      ]
    },
    {
      "type": "barchart",
      "title": "Talk minutes per day",
      "datasource": { "type": "grafana-postgresql-datasource", "uid": "${DS_EXOVO}" },
      "gridPos": { "h": 9, "w": 12, "x": 0, "y": 9 },
      "targets": [
        {
          "refId": "A",
          "format": "time_series",
          "rawSql": "SELECT day AS time, SUM(talk_seconds) / 60.0 AS talk_minutes FROM reporting.calls_daily WHERE $__timeFilter(day) GROUP BY day ORDER BY day"
        }
      ]
    },
    {
      "type": "stat",
      "title": "Average call quality (MOS)",
      "datasource": { "type": "grafana-postgresql-datasource", "uid": "${DS_EXOVO}" },
      "gridPos": { "h": 9, "w": 6, "x": 12, "y": 9 },
      "fieldConfig": {
        "defaults": {
          "decimals": 2,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": null },
              { "color": "yellow", "value": 3.5 },
              { "color": "green", "value": 4.0 }
            ]
          }
        }
      },
      "targets": [
        {
          "refId": "A",
          "format": "table",
          "rawSql": "SELECT AVG(mos_score) AS avg_mos FROM reporting.calls WHERE $__timeFilter(start_time) AND mos_score IS NOT NULL"
        }
      ]
    },
    {
      "type": "table",
      "title": "Busiest destinations",
      "datasource": { "type": "grafana-postgresql-datasource", "uid": "${DS_EXOVO}" },
      "gridPos": { "h": 9, "w": 6, "x": 18, "y": 9 },
      "targets": [
        {
          "refId": "A",
          "format": "table",
          "rawSql": "SELECT destination_number, COUNT(*) AS calls FROM reporting.calls WHERE $__timeFilter(start_time) GROUP BY destination_number ORDER BY calls DESC LIMIT 10"
        }
      ]
    }
  ]
}
