{
  "license": "CC BY 4.0",
  "recipe": {
    "slug": "incident-customer-impact-by-plan",
    "title": "Measure Incident Customer Impact by Plan",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-28"
  },
  "contract": {
    "tableName": "incident_account_impact_events",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Impact assessment time in UTC."
      },
      {
        "name": "incident_id",
        "type": "Utf8",
        "description": "Stable incident identifier."
      },
      {
        "name": "account_id",
        "type": "Utf8",
        "description": "Approved pseudonymous account identifier."
      },
      {
        "name": "plan",
        "type": "Utf8",
        "description": "Bounded plan or service tier."
      },
      {
        "name": "impact_type",
        "type": "Utf8",
        "description": "Controlled customer-visible impact category."
      },
      {
        "name": "affected",
        "type": "Boolean",
        "description": "Whether the account met the documented impact definition."
      },
      {
        "name": "impact_duration_ms",
        "type": "Int64",
        "description": "Measured impact duration in milliseconds."
      },
      {
        "name": "environment",
        "type": "Utf8",
        "description": "Deployment environment."
      }
    ]
  },
  "query": "SELECT\n  incident_id,\n  plan,\n  COUNT(*) AS assessed_accounts,\n  SUM(CASE WHEN affected THEN 1 ELSE 0 END) AS affected_accounts,\n  100.0 * SUM(CASE WHEN affected THEN 1 ELSE 0 END)\n    / NULLIF(COUNT(*), 0) AS affected_accounts_pct,\n  AVG(CASE WHEN affected THEN impact_duration_ms ELSE NULL END)\n    AS avg_impact_duration_ms\nFROM incident_account_impact_events\nWHERE timestamp_utc >= now() - INTERVAL '7 days'\n  AND environment = 'production'\nGROUP BY incident_id, plan\nORDER BY affected_accounts DESC, plan;",
  "fixtureKind": "reproducible",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T18:00:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-1",
      "plan": "enterprise",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 20000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:54:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-2",
      "plan": "enterprise",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 40000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:48:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-3",
      "plan": "enterprise",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 60000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:42:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-4",
      "plan": "enterprise",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:36:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-1",
      "plan": "starter",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 15000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:30:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-2",
      "plan": "starter",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 25000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:24:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-3",
      "plan": "starter",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:18:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-4",
      "plan": "starter",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:12:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-5",
      "plan": "starter",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T18:00:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-1",
      "plan": "enterprise",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 20000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:54:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-2",
      "plan": "enterprise",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 40000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:48:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-3",
      "plan": "enterprise",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 60000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:42:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-ent-4",
      "plan": "enterprise",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:36:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-1",
      "plan": "starter",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 15000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:30:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-2",
      "plan": "starter",
      "impact_type": "checkout_failed",
      "affected": true,
      "impact_duration_ms": 25000,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:24:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-3",
      "plan": "starter",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:18:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-4",
      "plan": "starter",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T17:12:00.000Z",
      "incident_id": "incident-checkout-42",
      "account_id": "account-start-5",
      "plan": "starter",
      "impact_type": "none",
      "affected": false,
      "impact_duration_ms": 0,
      "environment": "production"
    }
  ],
  "expectedOutput": {
    "columns": [
      "incident_id",
      "plan",
      "assessed_accounts",
      "affected_accounts",
      "affected_accounts_pct",
      "avg_impact_duration_ms"
    ],
    "rows": [
      {
        "incident_id": "incident-checkout-42",
        "plan": "enterprise",
        "assessed_accounts": 4,
        "affected_accounts": 3,
        "affected_accounts_pct": 75,
        "avg_impact_duration_ms": 40000
      },
      {
        "incident_id": "incident-checkout-42",
        "plan": "starter",
        "assessed_accounts": 5,
        "affected_accounts": 2,
        "affected_accounts_pct": 40,
        "avg_impact_duration_ms": 20000
      }
    ]
  },
  "notes": [
    "The included synthetic input rows generate the expected output when timestamps are shifted into the documented query window.",
    "Run this fixture in the public browser SQL playground; the selected query executes locally with DuckDB-Wasm.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}