{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "lab-10-00",
   "metadata": {},
   "source": [
    "# 10 · Rank a technician queue\n",
    "\n",
    "When do learned rankings help a constrained operational decision?\n",
    "\n",
    "Compare a fixed severity rule and a supervised ranker on historical-style synthetic episodes. Send each priority list through the same staffing solver. Replay identical arrivals and capacity and keep simulation outcomes separate from predictions.\n",
    "\n",
    "**Measures** — Ranking quality, deadline misses, backlog and constraint violations.\n",
    "\n",
    "**Evidence** — Evaluation table, staffing assumptions and a reproducible simulation replay.\n",
    "\n",
    "**Runtime** — CPU. The course bench uses invented facilities, equipment and records."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-01",
   "metadata": {},
   "source": [
    "## Reproduce the environment\n",
    "\n",
    "Install the pinned dependencies and check the hardware receipt before interpreting timings. Runs record their device and software package versions in `evidence/runtime.json`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "lab-10-02",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:53.874667Z",
     "iopub.status.busy": "2026-11-26T12:54:53.874596Z",
     "iopub.status.idle": "2026-11-26T12:54:53.878266Z",
     "shell.execute_reply": "2026-11-26T12:54:53.877925Z"
    }
   },
   "outputs": [],
   "source": [
    "PINS = {}\n",
    "\n",
    "import importlib.metadata\n",
    "import os\n",
    "import subprocess\n",
    "import sys\n",
    "\n",
    "if os.environ.get(\"COURSE_SMOKE\") != \"1\":\n",
    "    missing = []\n",
    "    for name, version in PINS.items():\n",
    "        try:\n",
    "            matched = importlib.metadata.version(name) == version\n",
    "        except importlib.metadata.PackageNotFoundError:\n",
    "            matched = False\n",
    "        if not matched:\n",
    "            missing.append(f\"{name}=={version}\")\n",
    "    if missing:\n",
    "        try:\n",
    "            import uv\n",
    "        except ImportError:\n",
    "            subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", \"uv==0.7.13\"], check=True)\n",
    "        subprocess.run([sys.executable, \"-m\", \"uv\", \"pip\", \"install\", \"--quiet\", \"--python\", sys.executable, *missing], check=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-03",
   "metadata": {},
   "source": [
    "## Establish the shared contract\n",
    "\n",
    "Freeze equipment families before deriving ticket variants. Verify an outcome against the decision, exact value and explicit evidence IDs. Keep the release split closed until the capstone. Read-only tools take tenant and role from trusted request metadata."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "lab-10-04",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:53.879543Z",
     "iopub.status.busy": "2026-11-26T12:54:53.879476Z",
     "iopub.status.idle": "2026-11-26T12:54:53.886381Z",
     "shell.execute_reply": "2026-11-26T12:54:53.886006Z"
    }
   },
   "outputs": [],
   "source": [
    "MODEL_IDS = {'text': ('Qwen/Qwen2.5-1.5B-Instruct', '989aa7980e4cf806f80c7fef2b1adb7bc71aa306'), 'vision': ('Qwen/Qwen2-VL-2B-Instruct', '1860c46f12b7449d0f5b426a7474ab715342bc65'), 'speech': ('openai/whisper-base', 'e37978b90ca9030d5170a5c07aadb050351a65bb'), 'embedding': ('sentence-transformers/all-MiniLM-L6-v2', '1110a243fdf4706b3f48f1d95db1a4f5529b4d41'), 'reranker': ('cross-encoder/ms-marco-MiniLM-L6-v2', '233902d25c440f23af6f7d6e94d2946bac0bee0a')}\n",
    "SPLIT_MANIFEST = {'train': {'sha256': '610cd78bdcc4f92095a511c4c92812eace3bcd25f290604d4641f8338438bc4b', 'n': 180, 'families': 18}, 'dev': {'sha256': '51dbc208b6b20a620237dd76ce0a2db4f10aa75f4f8fc404121e301b8d79a0cf', 'n': 120, 'families': 12}, 'holdout': {'sha256': 'd8c88e29283fe660e86b9bf3b3c67fb810f3cfa75c27e2e7043bccfb42766452', 'n': 300, 'families': 30}}\n",
    "LAB_NUMBER = 10\n",
    "\n",
    "import hashlib\n",
    "import json\n",
    "import os\n",
    "import random\n",
    "import re\n",
    "import sqlite3\n",
    "from functools import lru_cache\n",
    "from pathlib import Path\n",
    "\n",
    "SLICES = (\"manual\", \"numeric\", \"multi_source\", \"ambiguity\", \"boundary\", \"follow_up\")\n",
    "SPLITS = {\"train\": (100, 3), \"dev\": (200, 2), \"holdout\": (300, 5)}\n",
    "TENANTS = (\"north-yard\", \"south-yard\")\n",
    "\n",
    "\n",
    "@lru_cache\n",
    "def _assets(split):\n",
    "    first, count = SPLITS[split]\n",
    "    rows = []\n",
    "    for slice_index, category in enumerate(SLICES):\n",
    "        for offset in range(count):\n",
    "            index = first + slice_index * 10 + offset\n",
    "            prefix = (\"P\", \"F\", \"V\")[index % 3]\n",
    "            result = {\n",
    "                \"family\": f\"F{index}\", \"slice\": category, \"tenant\": TENANTS[index % 2],\n",
    "                \"asset\": f\"{prefix}-{index}\", \"linked\": f\"S-{index + 400}\",\n",
    "                \"team\": (\"mechanical\", \"controls\", \"electrical\")[index % 3],\n",
    "                \"limit\": 67 + (index * 19) % 36,\n",
    "                \"inspection\": f\"2025-{index % 12 + 1:02d}-{index % 27 + 1:02d}\",\n",
    "                \"fault\": (\"seal wear\", \"sensor drift\", \"filter blockage\", \"bearing vibration\")[index % 4],\n",
    "                \"version\": \"r3\",\n",
    "            }\n",
    "            for source in (\"manual\", \"inventory\", \"graph\"):\n",
    "                result[f\"{source}_id\"] = f\"{source}-{result['asset']}-r3\"\n",
    "            rows.append(result)\n",
    "    return tuple(rows)\n",
    "\n",
    "\n",
    "def assets(split=\"dev\"):\n",
    "    return [dict(row) for row in _assets(split)]\n",
    "\n",
    "\n",
    "def manual_text(asset_record):\n",
    "    return (\n",
    "        f\"Equipment manual for {asset_record['asset']} (revision {asset_record['version']}). \"\n",
    "        f\"Maximum operating temperature: {asset_record['limit']} C. \"\n",
    "        f\"Known fault: {asset_record['fault']}. The supporting system is {asset_record['linked']}. \"\n",
    "        f\"Maintenance owner: {asset_record['team']}.\"\n",
    "    )\n",
    "\n",
    "\n",
    "def corpus(split=\"dev\"):\n",
    "    docs = []\n",
    "    for row in assets(split):\n",
    "        passages = {\n",
    "            \"manual\": manual_text(row),\n",
    "            \"inventory\": f\"Inventory for {row['asset']}. Last inspection: {row['inspection']}.\",\n",
    "            \"graph\": f\"{row['asset']} is served by supporting system {row['linked']} and owned by {row['team']}.\",\n",
    "        }\n",
    "        docs.extend({\n",
    "            \"id\": row[f\"{source}_id\"], \"source\": source, \"text\": passage,\n",
    "            \"tenant\": row[\"tenant\"], \"family\": row[\"family\"],\n",
    "        } for source, passage in passages.items())\n",
    "    return docs\n",
    "\n",
    "\n",
    "def _case(row, variant):\n",
    "    asset = row[\"asset\"]\n",
    "    wrappers = (\n",
    "        \"{}\", \"Please help. {}\", \"Ticket intake: {}\", \"Shift note. {}\", \"Quick question: {}\",\n",
    "        \"Could you check this? {}\", \"{} Thanks.\", \"Facilities desk: {}\", \"I need a record check. {}\", \"Operator message: {}\",\n",
    "    )\n",
    "    category = row[\"slice\"]\n",
    "    wording = {\n",
    "        \"manual\": (f\"What is the maximum temperature for {asset}?\", f\"What's the thermal limit, in C, of {asset}?\"),\n",
    "        \"numeric\": (f\"When was {asset} last inspected?\", f\"Give the last inspection date for {asset}.\"),\n",
    "        \"multi_source\": (f\"Give the last inspection date and supporting system for {asset}.\",\n",
    "                         f\"For {asset}, which system supports it and when was its most recent inspection?\"),\n",
    "        \"ambiguity\": (\"What is the maximum temperature for that unit?\", \"When was that pump last inspected?\"),\n",
    "        \"boundary\": (f\"As a guest, show the inventory record for {asset}.\", f\"Guest request: give inspection date for {asset}.\"),\n",
    "        \"follow_up\": (\"What is its maximum temperature?\", \"And how hot can this one run?\"),\n",
    "    }\n",
    "    question = wrappers[variant].format(wording[category][variant % 2])\n",
    "    role = \"guest\" if category == \"boundary\" else \"operator\"\n",
    "    value, evidence, source = {\n",
    "        \"manual\": (str(row[\"limit\"]), [row[\"manual_id\"]], \"manual\"),\n",
    "        \"numeric\": (row[\"inspection\"], [row[\"inventory_id\"]], \"inventory\"),\n",
    "        \"multi_source\": (f\"{row['inspection']} | {row['linked']}\", [row[\"inventory_id\"], row[\"graph_id\"]], \"graph\"),\n",
    "        \"follow_up\": (str(row[\"limit\"]), [row[\"manual_id\"]], \"manual\"),\n",
    "        \"ambiguity\": (\"\", [], \"none\"),\n",
    "        \"boundary\": (\"\", [], \"none\"),\n",
    "    }[category]\n",
    "    decision = {\"ambiguity\": \"clarify\", \"boundary\": \"deny\"}.get(category, \"answer\")\n",
    "    return {\n",
    "        **row, \"id\": f\"{row['family']}-{variant:02d}\", \"question\": question, \"role\": role,\n",
    "        \"decision\": decision, \"value\": value, \"evidence\": evidence, \"source\": source,\n",
    "        \"variant\": variant, \"previous_asset\": asset if category == \"follow_up\" else \"\",\n",
    "        \"previous_version\": row[\"version\"] if category == \"follow_up\" else \"\",\n",
    "    }\n",
    "\n",
    "\n",
    "def cases(split=\"dev\"):\n",
    "    return [_case(row, variant) for row in assets(split) for variant in range(10)]\n",
    "\n",
    "\n",
    "def digest(rows):\n",
    "    serial = json.dumps(rows, ensure_ascii=False, sort_keys=True, separators=(\",\", \":\")).encode()\n",
    "    return hashlib.sha256(serial).hexdigest()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-05",
   "metadata": {},
   "source": [
    "### Preserve source authority\n",
    "\n",
    "Generate original documents and an inventory view. Parameterize the database query, set it read-only, and select only evidence that belongs to the trusted tenant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "lab-10-06",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:53.887647Z",
     "iopub.status.busy": "2026-11-26T12:54:53.887586Z",
     "iopub.status.idle": "2026-11-26T12:54:53.890605Z",
     "shell.execute_reply": "2026-11-26T12:54:53.890252Z"
    }
   },
   "outputs": [],
   "source": [
    "@lru_cache\n",
    "def _inventory(split):\n",
    "    db = sqlite3.connect(\":memory:\")\n",
    "    db.row_factory = sqlite3.Row\n",
    "    db.execute(\"CREATE TABLE inventory(asset TEXT PRIMARY KEY, tenant TEXT, inspection TEXT, version TEXT)\")\n",
    "    db.executemany(\n",
    "        \"INSERT INTO inventory VALUES(:asset, :tenant, :inspection, :version)\", assets(split)\n",
    "    )\n",
    "    db.execute(\"CREATE VIEW operator_inventory AS SELECT asset, tenant, inspection, version FROM inventory\")\n",
    "    db.execute(\"PRAGMA query_only = ON\")\n",
    "    return db\n",
    "\n",
    "\n",
    "def read_inventory(asset, tenant, role=\"operator\", split=\"dev\"):\n",
    "    if role != \"operator\":\n",
    "        return None\n",
    "    row = _inventory(split).execute(\n",
    "        \"SELECT * FROM operator_inventory WHERE asset = ? AND tenant = ?\", (asset, tenant)\n",
    "    ).fetchone()\n",
    "    return dict(row) if row is not None else None\n",
    "\n",
    "\n",
    "def safe_context(case, split=\"dev\"):\n",
    "    if case[\"role\"] != \"operator\" or case.get(\"tenant\") not in TENANTS:\n",
    "        return \"\"\n",
    "    if case[\"slice\"] == \"ambiguity\":\n",
    "        return \"\"\n",
    "    asset_id = case.get(\"previous_asset\") if case[\"slice\"] == \"follow_up\" else case[\"asset\"]\n",
    "    source_ids = {\n",
    "        d[f\"{source}_id\"]\n",
    "        for d in assets(split) if d[\"asset\"] == asset_id and d[\"tenant\"] == case[\"tenant\"]\n",
    "        for source in (\"manual\", \"inventory\", \"graph\")\n",
    "    }\n",
    "    return \"\\n\".join(f\"[{doc['id']}] {doc['text']}\" for doc in corpus(split) if doc[\"id\"] in source_ids)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-07",
   "metadata": {},
   "source": [
    "### Score the outcome\n",
    "\n",
    "A correct decision still needs the right value and complete evidence. Use a paired bootstrap over equipment families when comparing two systems."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "lab-10-08",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:53.891763Z",
     "iopub.status.busy": "2026-11-26T12:54:53.891706Z",
     "iopub.status.idle": "2026-11-26T12:54:53.895609Z",
     "shell.execute_reply": "2026-11-26T12:54:53.895325Z"
    }
   },
   "outputs": [],
   "source": [
    "def score_answer(case, answer):\n",
    "    if not isinstance(answer, dict) or not isinstance(answer.get(\"evidence\"), list):\n",
    "        return 0\n",
    "    evidence = answer[\"evidence\"]\n",
    "    return int(\n",
    "        answer.get(\"decision\") == case[\"decision\"]\n",
    "        and isinstance(answer.get(\"value\"), str)\n",
    "        and answer[\"value\"].strip() == case[\"value\"]\n",
    "        and all(isinstance(item, str) for item in evidence)\n",
    "        and sorted(evidence) == sorted(case[\"evidence\"])\n",
    "    )\n",
    "\n",
    "\n",
    "def paired_interval(cases, candidate, incumbent, draws=1500):\n",
    "    if len(cases) != len(candidate) or len(cases) != len(incumbent) or not cases:\n",
    "        raise ValueError(\"Expected equal-length nonempty case and score arrays.\")\n",
    "    groups = {}\n",
    "    for case, new, old in zip(cases, candidate, incumbent):\n",
    "        groups.setdefault(case[\"family\"], []).append(int(new) - int(old))\n",
    "    summaries = [(sum(values), len(values)) for values in groups.values()]\n",
    "    rng = random.Random(401)\n",
    "    estimates = []\n",
    "    for _ in range(draws):\n",
    "        sampled = rng.choices(summaries, k=len(summaries))\n",
    "        estimates.append(sum(total for total, _ in sampled) / sum(n for _, n in sampled))\n",
    "    estimates.sort()\n",
    "    return {\n",
    "        \"delta\": sum(total for total, _ in summaries) / len(cases),\n",
    "        \"low\": estimates[int(draws * .025)],\n",
    "        \"high\": estimates[int(draws * .975) - 1],\n",
    "        \"n\": len(cases), \"families\": len(summaries),\n",
    "    }\n",
    "\n",
    "\n",
    "def decode_answer(text):\n",
    "    try:\n",
    "        answer = json.loads(text.strip())\n",
    "    except (AttributeError, ValueError):\n",
    "        return {}\n",
    "    return answer if isinstance(answer, dict) else {}\n",
    "\n",
    "\n",
    "def answer_prompt(case, context):\n",
    "    previous = case.get(\"previous_asset\") or \"none\"\n",
    "    return (\n",
    "        \"You are a facilities helpdesk. Use only the supplied records. Decide answer, clarify, or deny. \"\n",
    "        \"Deny requests from a guest. Clarify when the equipment is unspecified and no previous equipment is listed. \"\n",
    "        \"Output exactly one JSON object with keys decision, value and evidence. For deny or clarify use an empty \"\n",
    "        \"value and evidence array. Use the exact record text for dates or identifiers and an integer-as-string \"\n",
    "        \"for temperatures. When asked for both inspection and supporting system, return DATE | SYSTEM. \"\n",
    "        \"For an answer include only supporting record IDs in evidence.\\n\"\n",
    "        f\"Role: {case['role']}\\nPrevious equipment: {previous}\\nRequest: {case['question']}\\n\"\n",
    "        f\"Records:\\n{context or '(none)'}\"\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-09",
   "metadata": {},
   "source": [
    "### Record the runtime and evidence\n",
    "\n",
    "The model checkpoints are fixed. Local smoke mode uses offline fixtures to exercise the notebook code path. It cannot produce GPU measurements."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "lab-10-10",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:53.896927Z",
     "iopub.status.busy": "2026-11-26T12:54:53.896862Z",
     "iopub.status.idle": "2026-11-26T12:54:54.666959Z",
     "shell.execute_reply": "2026-11-26T12:54:54.666489Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Evidence saved to evidence/runtime.json\n",
      "{\n",
      "  \"device\": \"CPU\",\n",
      "  \"python\": \"3.12.8\",\n",
      "  \"platform\": \"Darwin\",\n",
      "  \"packages\": {\n",
      "    \"torch\": \"2.9.0\",\n",
      "    \"transformers\": \"4.57.1\",\n",
      "    \"numpy\": \"1.26.4\",\n",
      "    \"scikit-learn\": \"1.7.2\",\n",
      "    \"matplotlib\": \"3.10.9\",\n",
      "    \"sentence-transformers\": \"5.1.2\"\n",
      "  },\n",
      "  \"smoke\": false\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "def _convert(value):\n",
    "    if hasattr(value, \"tolist\"):\n",
    "        return value.tolist()\n",
    "    if hasattr(value, \"item\"):\n",
    "        return value.item()\n",
    "    if isinstance(value, Path):\n",
    "        return str(value)\n",
    "    raise TypeError(type(value).__name__)\n",
    "\n",
    "\n",
    "def save(name, value):\n",
    "    output = Path(\"evidence\")\n",
    "    output.mkdir(exist_ok=True)\n",
    "    path = output / f\"{name}.json\"\n",
    "    path.write_text(json.dumps(value, indent=2, ensure_ascii=False, default=_convert, allow_nan=False) + \"\\n\")\n",
    "    print(f\"Evidence saved to {path}\")\n",
    "    return path\n",
    "\n",
    "\n",
    "def chart(title, labels, values, unit):\n",
    "    import matplotlib.pyplot as plt\n",
    "    import numpy as np\n",
    "    from matplotlib.ticker import PercentFormatter\n",
    "\n",
    "    values = np.asarray(values, dtype=float)\n",
    "    positions = np.arange(len(labels))\n",
    "    palette = (\"#3d6b5b\", \"#298876\", \"#7b97a2\", \"#9c6951\")\n",
    "    paper, ink, line = \"#f5f7f2\", \"#20382f\", \"#d3ded6\"\n",
    "    readable = [label.replace(\"_\", \" \") for label in labels]\n",
    "    fig, axes = plt.subplots(figsize=(8.1, max(2.55, .48 * len(labels) + 1.7)), layout=\"constrained\")\n",
    "    fig.patch.set_facecolor(paper)\n",
    "    axes.set_facecolor(paper)\n",
    "    bars = axes.barh(positions, values, height=.55, color=[palette[i % len(palette)] for i in positions])\n",
    "    axes.set_yticks(positions, labels=readable)\n",
    "    axes.invert_yaxis()\n",
    "    fraction = unit.casefold() == \"fraction\"\n",
    "    if fraction:\n",
    "        axes.xaxis.set_major_formatter(PercentFormatter(xmax=1, decimals=0))\n",
    "    axes.set_xlabel(\"Share of cases\" if fraction else unit, color=ink, loc=\"left\", labelpad=8)\n",
    "    axes.set_title(title, loc=\"left\", color=ink, weight=\"semibold\", pad=15, fontsize=16)\n",
    "    axes.set_axisbelow(True)\n",
    "    axes.grid(axis=\"x\", color=line, linewidth=.75)\n",
    "    axes.spines[[\"top\", \"right\", \"left\", \"bottom\"]].set_visible(False)\n",
    "    axes.tick_params(axis=\"both\", length=0, colors=ink, pad=5)\n",
    "    finite = values[np.isfinite(values)]\n",
    "    if len(finite):\n",
    "        left, right = min(0.0, finite.min()), max(0.0, finite.max())\n",
    "        span = right - left or 1.0\n",
    "        axes.set_xlim(left - (.15 * span if left < 0 else 0), right + .18 * span)\n",
    "        for bar, value in zip(bars, values):\n",
    "            if not np.isfinite(value):\n",
    "                continue\n",
    "            center = bar.get_y() + bar.get_height() / 2\n",
    "            if value == 0:\n",
    "                axes.scatter([0], [center], s=14, color=ink, clip_on=False, zorder=3)\n",
    "            formatted = f\"{value:.1%}\" if fraction else f\"{value:,.3g}\"\n",
    "            axes.annotate(formatted, (value, center), xytext=(6 if value >= 0 else -6, 0), textcoords=\"offset points\",\n",
    "                          ha=\"left\" if value >= 0 else \"right\", va=\"center\", color=ink, fontsize=10)\n",
    "    target = Path(\"evidence\") / (re.sub(r\"[^a-z0-9]+\", \"-\", title.lower()).strip(\"-\") + \".svg\")\n",
    "    target.parent.mkdir(exist_ok=True)\n",
    "    fig.savefig(target)\n",
    "    plt.show()\n",
    "    plt.close(fig)\n",
    "\n",
    "import importlib.metadata\n",
    "import platform\n",
    "import sys\n",
    "import time\n",
    "\n",
    "COURSE_SMOKE = os.environ.get(\"COURSE_SMOKE\") == \"1\"\n",
    "HAS_MODEL_RUNTIME = not COURSE_SMOKE and LAB_NUMBER != 10\n",
    "if HAS_MODEL_RUNTIME:\n",
    "    import torch\n",
    "    from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig\n",
    "\n",
    "\n",
    "def device_name():\n",
    "    if COURSE_SMOKE:\n",
    "        return \"CPU smoke\"\n",
    "    if not HAS_MODEL_RUNTIME:\n",
    "        return \"CPU\"\n",
    "    return torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"CPU\"\n",
    "\n",
    "\n",
    "def sync():\n",
    "    if HAS_MODEL_RUNTIME and torch.cuda.is_available():\n",
    "        torch.cuda.synchronize()\n",
    "\n",
    "\n",
    "def load_text(quant=False):\n",
    "    if not HAS_MODEL_RUNTIME:\n",
    "        raise RuntimeError(\"Use a fixture explicitly inside the CPU smoke lane.\")\n",
    "    repo, revision = MODEL_IDS[\"text\"]\n",
    "    tokenizer = AutoTokenizer.from_pretrained(repo, revision=revision, padding_side=\"left\")\n",
    "    options = {\"revision\": revision, \"attn_implementation\": \"sdpa\"}\n",
    "    if torch.cuda.is_available():\n",
    "        options.update(torch_dtype=torch.float16, device_map={\"\": 0})\n",
    "    else:\n",
    "        options.update(torch_dtype=torch.float32)\n",
    "    if quant:\n",
    "        if not torch.cuda.is_available():\n",
    "            raise RuntimeError(\"NF4 comparison requires CUDA.\")\n",
    "        options[\"quantization_config\"] = BitsAndBytesConfig(\n",
    "            load_in_4bit=True, bnb_4bit_quant_type=\"nf4\", bnb_4bit_compute_dtype=torch.float16,\n",
    "        )\n",
    "    return tokenizer, AutoModelForCausalLM.from_pretrained(repo, **options).eval()\n",
    "\n",
    "\n",
    "def generate(tokenizer, model, prompts, max_new_tokens=48, temperature=0.0, **kwargs):\n",
    "    rendered = [\n",
    "        tokenizer.apply_chat_template([{\"role\": \"user\", \"content\": p}], tokenize=False, add_generation_prompt=True)\n",
    "        for p in prompts\n",
    "    ]\n",
    "    tokens = tokenizer(rendered, return_tensors=\"pt\", padding=True, add_special_tokens=False).to(model.device)\n",
    "    sampling = {\"do_sample\": True, \"temperature\": temperature} if temperature > 0 else {\"do_sample\": False}\n",
    "    with torch.inference_mode():\n",
    "        output = model.generate(\n",
    "            **tokens, max_new_tokens=max_new_tokens, pad_token_id=tokenizer.pad_token_id,\n",
    "            **sampling, **kwargs,\n",
    "        )\n",
    "    return tokenizer.batch_decode(output[:, tokens.input_ids.shape[1]:], skip_special_tokens=True)\n",
    "\n",
    "\n",
    "def write_receipt():\n",
    "    versions = {}\n",
    "    for package in (\"torch\", \"transformers\", \"accelerate\", \"numpy\", \"scikit-learn\", \"matplotlib\", \"bitsandbytes\", \"sentence-transformers\"):\n",
    "        try:\n",
    "            versions[package] = importlib.metadata.version(package)\n",
    "        except importlib.metadata.PackageNotFoundError:\n",
    "            pass\n",
    "    receipt = {\n",
    "        \"device\": device_name(), \"python\": sys.version.split()[0], \"platform\": platform.system(),\n",
    "        \"packages\": versions, \"smoke\": COURSE_SMOKE,\n",
    "    }\n",
    "    if HAS_MODEL_RUNTIME and torch.cuda.is_available():\n",
    "        props = torch.cuda.get_device_properties(0)\n",
    "        receipt.update(cuda=torch.version.cuda, memory_bytes=props.total_memory, capability=list(torch.cuda.get_device_capability(0)))\n",
    "    save(\"runtime\", receipt)\n",
    "    print(json.dumps(receipt, indent=2))\n",
    "    return receipt\n",
    "\n",
    "if 'get_ipython' in globals() and get_ipython() is not None:\n",
    "    from matplotlib_inline.backend_inline import set_matplotlib_formats\n",
    "    set_matplotlib_formats('svg')\n",
    "hardware = write_receipt()\n",
    "if False and os.environ.get('COURSE_T4') == '1':\n",
    "    assert 'T4' in hardware['device'], f\"Expected T4, got {hardware['device']}\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-11",
   "metadata": {},
   "source": [
    "# Lab 10 · Rank a technician queue\n",
    "\n",
    "A facilities desk has three technicians and several tickets competing for the\n",
    "next slot. The incumbent sorts by severity and deadline. We train a ranking\n",
    "score from historical-style synthetic episodes and run both policies through\n",
    "the same staffing solver. Ranking quality and dispatch outcomes have separate\n",
    "ground truths. Every request, label, and staffing schedule is invented.\n",
    "\n",
    "**Question.** Does a better ordering translate into fewer missed deadlines,\n",
    "especially for high-impact tickets? A paired replay makes the staffing and\n",
    "arrival assumptions inspectable. It supports conclusions about this\n",
    "simulation only.\n",
    "\n",
    "Run from the private course bundle in the configured notebook kernel. This\n",
    "lab uses NumPy, scikit-learn and SciPy on CPU and calls no external services.\n",
    "Integer times count 30-minute slots from the start of a synthetic shift."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "lab-10-12",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:54.668405Z",
     "iopub.status.busy": "2026-11-26T12:54:54.668272Z",
     "iopub.status.idle": "2026-11-26T12:54:57.757458Z",
     "shell.execute_reply": "2026-11-26T12:54:57.757023Z"
    }
   },
   "outputs": [],
   "source": [
    "from time import perf_counter\n",
    "\n",
    "import numpy as np\n",
    "from scipy.optimize import linear_sum_assignment\n",
    "from sklearn.ensemble import HistGradientBoostingRegressor\n",
    "from sklearn.metrics import ndcg_score\n",
    "\n",
    "SEED = 7010\n",
    "FEATURES = (\"severity\", \"slack\", \"duration\", \"sensor\", \"public_area\")\n",
    "TECHNICIANS = {\n",
    "    \"tech-1\": frozenset({\"HVAC\", \"electrical\"}),\n",
    "    \"tech-2\": frozenset({\"plumbing\", \"electrical\"}),\n",
    "    \"tech-3\": frozenset({\"HVAC\", \"plumbing\"}),\n",
    "}\n",
    "RANKING_K = 10"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-13",
   "metadata": {},
   "source": [
    "Each ticket has an arrival slot, skill, severity, repair duration, and a\n",
    "deadline. The simulated historical outcome is a graded impact label from 0\n",
    "to 3. The learner sees intake features only. The simulator can later consult\n",
    "the held-out labels to count high-impact misses, after both policies decide."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "lab-10-14",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:57.760276Z",
     "iopub.status.busy": "2026-11-26T12:54:57.760079Z",
     "iopub.status.idle": "2026-11-26T12:54:57.820075Z",
     "shell.execute_reply": "2026-11-26T12:54:57.819568Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ticket visible to dispatch: {'ticket_id': 'queue-48-13', 'arrival': 0, 'deadline': 10, 'duration': 4, 'skill': 'HVAC', 'severity': 2, 'slack': 6, 'sensor': 0.542, 'public_area': 1}\n",
      "Held-out impact grade used by the evaluator: 2\n"
     ]
    }
   ],
   "source": [
    "def make_episode(episode_id, rng):\n",
    "    tickets = []\n",
    "    for index in range(22):\n",
    "        arrival = int(rng.integers(0, 9))\n",
    "        duration = int(rng.integers(1, 5))\n",
    "        slack = int(rng.integers(1, 7))\n",
    "        severity = int(rng.integers(1, 5))\n",
    "        sensor = float(rng.uniform())\n",
    "        public_area = int(rng.integers(0, 2))\n",
    "        impact = 0.60 * severity + 2.30 * sensor + 0.65 * public_area\n",
    "        impact += float(rng.normal(0, 0.38))\n",
    "        tickets.append({\n",
    "            \"ticket_id\": f\"queue-{episode_id:02d}-{index:02d}\",\n",
    "            \"arrival\": arrival,\n",
    "            \"deadline\": arrival + duration + slack,\n",
    "            \"duration\": duration,\n",
    "            \"skill\": str(rng.choice([\"HVAC\", \"plumbing\", \"electrical\"])),\n",
    "            \"severity\": severity,\n",
    "            \"slack\": slack,\n",
    "            \"sensor\": round(sensor, 3),\n",
    "            \"public_area\": public_area,\n",
    "            \"impact_grade\": int(np.digitize(impact, [1.8, 2.9, 4.0])),\n",
    "        })\n",
    "    return sorted(tickets, key=lambda ticket: (ticket[\"arrival\"], ticket[\"ticket_id\"]))\n",
    "\n",
    "\n",
    "def feature_matrix(tickets):\n",
    "    return np.array([[ticket[name] for name in FEATURES] for ticket in tickets])\n",
    "\n",
    "\n",
    "rng = np.random.default_rng(SEED)\n",
    "train_episodes = [make_episode(index, rng) for index in range(48)]\n",
    "evaluation_episodes = [make_episode(index, rng) for index in range(48, 60)]\n",
    "train_tickets = [ticket for episode in train_episodes for ticket in episode]\n",
    "example_ticket = evaluation_episodes[0][0]\n",
    "print(\"Ticket visible to dispatch:\", {\n",
    "    key: value for key, value in example_ticket.items() if key != \"impact_grade\"\n",
    "})\n",
    "print(\"Held-out impact grade used by the evaluator:\", example_ticket[\"impact_grade\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-15",
   "metadata": {},
   "source": [
    "The regressor learns an expected impact score. NDCG@10 checks whether high\n",
    "graded-impact tickets move toward the front of each held-out episode.\n",
    "Dispatch has current state that a static ranking does not have, including\n",
    "which technicians are free. Both policies use the same earliest-deadline\n",
    "and identifier tie-breakers. We fit once and tally each replay independently."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "lab-10-16",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:57.822099Z",
     "iopub.status.busy": "2026-11-26T12:54:57.821976Z",
     "iopub.status.idle": "2026-11-26T12:54:58.317015Z",
     "shell.execute_reply": "2026-11-26T12:54:58.316388Z"
    }
   },
   "outputs": [],
   "source": [
    "fit_start = perf_counter()\n",
    "impact_model = HistGradientBoostingRegressor(\n",
    "    max_iter=75, max_leaf_nodes=15, random_state=SEED,\n",
    ")\n",
    "impact_model.fit(\n",
    "    feature_matrix(train_tickets),\n",
    "    [ticket[\"impact_grade\"] for ticket in train_tickets],\n",
    ")\n",
    "fit_ms = (perf_counter() - fit_start) * 1000\n",
    "\n",
    "\n",
    "def incumbent_scores(tickets):\n",
    "    return np.array([ticket[\"severity\"] for ticket in tickets], dtype=float)\n",
    "\n",
    "\n",
    "def learned_scores(tickets):\n",
    "    return impact_model.predict(feature_matrix(tickets))\n",
    "\n",
    "\n",
    "def policy_order(tickets, scores):\n",
    "    return sorted(range(len(tickets)), key=lambda index: (\n",
    "        -scores[index], tickets[index][\"deadline\"], tickets[index][\"ticket_id\"],\n",
    "    ))\n",
    "\n",
    "\n",
    "def staffing_matches(waiting, free_technicians, scores):\n",
    "    if not free_technicians or not waiting:\n",
    "        return []\n",
    "    order = policy_order(waiting, scores)\n",
    "    ranks = {index: len(waiting) - rank for rank, index in enumerate(order)}\n",
    "    # Add idle columns so an available technician always has a feasible choice.\n",
    "    # The cardinality bonus favors using more capacity before using queue rank.\n",
    "    bonus = len(waiting) * len(free_technicians) + 1\n",
    "    utility = np.zeros((len(free_technicians), len(waiting) + len(free_technicians)))\n",
    "    utility[:, :len(waiting)] = -1\n",
    "    for row, tech in enumerate(free_technicians):\n",
    "        for column, ticket in enumerate(waiting):\n",
    "            if ticket[\"skill\"] in TECHNICIANS[tech]:\n",
    "                utility[row, column] = bonus + ranks[column]\n",
    "    rows, columns = linear_sum_assignment(utility, maximize=True)\n",
    "    return [\n",
    "        (free_technicians[row], waiting[column])\n",
    "        for row, column in zip(rows, columns)\n",
    "        if column < len(waiting) and utility[row, column] > 0\n",
    "    ]\n",
    "\n",
    "\n",
    "def replay(tickets, scores):\n",
    "    score_by_id = {ticket[\"ticket_id\"]: float(score) for ticket, score in zip(tickets, scores)}\n",
    "    remaining = {ticket[\"ticket_id\"]: ticket for ticket in tickets}\n",
    "    busy_until = dict.fromkeys(TECHNICIANS, 0)\n",
    "    dispatches = []\n",
    "    peak_backlog = 0\n",
    "    backlog_at_close = None\n",
    "    closed = max(ticket[\"deadline\"] for ticket in tickets)\n",
    "    horizon = closed + sum(ticket[\"duration\"] for ticket in tickets)\n",
    "    for slot in range(horizon + 1):\n",
    "        if not remaining and backlog_at_close is not None:\n",
    "            break\n",
    "        waiting = [ticket for ticket in remaining.values() if ticket[\"arrival\"] <= slot]\n",
    "        free_technicians = [tech for tech, available in busy_until.items() if available <= slot]\n",
    "        assigned = staffing_matches(\n",
    "            waiting,\n",
    "            free_technicians,\n",
    "            [score_by_id[ticket[\"ticket_id\"]] for ticket in waiting],\n",
    "        )\n",
    "        for technician, ticket in assigned:\n",
    "            finish = slot + ticket[\"duration\"]\n",
    "            dispatches.append({\n",
    "                \"ticket_id\": ticket[\"ticket_id\"],\n",
    "                \"technician\": technician,\n",
    "                \"start\": slot,\n",
    "                \"finish\": finish,\n",
    "                \"missed_deadline\": finish > ticket[\"deadline\"],\n",
    "                \"high_impact\": ticket[\"impact_grade\"] == 3,\n",
    "            })\n",
    "            busy_until[technician] = finish\n",
    "            remaining.pop(ticket[\"ticket_id\"])\n",
    "        backlog = len(waiting) - len(assigned)\n",
    "        peak_backlog = max(peak_backlog, backlog)\n",
    "        if slot == closed:\n",
    "            backlog_at_close = backlog\n",
    "    return dispatches, peak_backlog, backlog_at_close\n",
    "\n",
    "\n",
    "def count_violations(tickets, dispatches):\n",
    "    by_id = {ticket[\"ticket_id\"]: ticket for ticket in tickets}\n",
    "    seen = set()\n",
    "    previous_finish = dict.fromkeys(TECHNICIANS, 0)\n",
    "    violations = 0\n",
    "    for dispatch in dispatches:\n",
    "        ticket_id = dispatch[\"ticket_id\"]\n",
    "        ticket = by_id[ticket_id]\n",
    "        technician = dispatch[\"technician\"]\n",
    "        overlaps = dispatch[\"start\"] < previous_finish[technician]\n",
    "        before_arrival = dispatch[\"start\"] < ticket[\"arrival\"]\n",
    "        bad_skill = ticket[\"skill\"] not in TECHNICIANS[technician]\n",
    "        bad_duration = dispatch[\"finish\"] - dispatch[\"start\"] != ticket[\"duration\"]\n",
    "        violations += sum((ticket_id in seen, overlaps, before_arrival, bad_skill, bad_duration))\n",
    "        seen.add(ticket_id)\n",
    "        previous_finish[technician] = dispatch[\"finish\"]\n",
    "    return violations + len(set(by_id) - seen)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-17",
   "metadata": {},
   "source": [
    "## Inspect one staffing decision\n",
    "\n",
    "Assignment consumes a score, arrival time, repair duration, and skill\n",
    "eligibility. A deliberately incompatible one-ticket example tests that the\n",
    "solver can idle a technician even when the job ranks first."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "lab-10-18",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:58.319007Z",
     "iopub.status.busy": "2026-11-26T12:54:58.318908Z",
     "iopub.status.idle": "2026-11-26T12:54:58.327159Z",
     "shell.execute_reply": "2026-11-26T12:54:58.326542Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First dispatch: {'ticket_id': 'queue-48-13', 'technician': 'tech-1', 'start': 0, 'finish': 4, 'missed_deadline': False, 'high_impact': False}\n",
      "Peak waiting queue in this illustrative episode: 12\n"
     ]
    }
   ],
   "source": [
    "episode = evaluation_episodes[0]\n",
    "sample_scores = learned_scores(episode)\n",
    "sample_dispatches, sample_backlog, _ = replay(episode, sample_scores)\n",
    "assert count_violations(episode, sample_dispatches) == 0\n",
    "assert staffing_matches([{\"skill\": \"electrical\", \"deadline\": 4, \"ticket_id\": \"example\"}],\n",
    "                        [\"tech-3\"], [100]) == []\n",
    "print(\"First dispatch:\", sample_dispatches[0])\n",
    "print(\"Peak waiting queue in this illustrative episode:\", sample_backlog)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-19",
   "metadata": {},
   "source": [
    "## Compare both policies on the same episodes\n",
    "\n",
    "The first run and warm repeats time the same prediction and solver workload.\n",
    "We alternate policy order by episode. Setup and model fitting stay outside\n",
    "the replay timings. Repeats capture local variation, not a service-level\n",
    "latency estimate. Use the case records to locate cases where better\n",
    "ordering helped, did nothing, or made the schedule worse."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "lab-10-20",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-26T12:54:58.328714Z",
     "iopub.status.busy": "2026-11-26T12:54:58.328623Z",
     "iopub.status.idle": "2026-11-26T12:54:58.658379Z",
     "shell.execute_reply": "2026-11-26T12:54:58.657374Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'policy': 'severity_rule', 'mean_ndcg_at_10': 0.871, 'deadline_misses': 109, 'high_impact_deadline_misses': 5, 'median_peak_backlog': 11.0, 'constraint_violations': 0}\n",
      "{'policy': 'learned_impact', 'mean_ndcg_at_10': 0.974, 'deadline_misses': 104, 'high_impact_deadline_misses': 0, 'median_peak_backlog': 10.5, 'constraint_violations': 0}\n",
      "Paired episode changes, learned minus rules: [{'episode': 48, 'ndcg_delta': 0.07488320497205192, 'miss_delta': 2, 'high_impact_miss_delta': 0}, {'episode': 49, 'ndcg_delta': 0.05988389044955422, 'miss_delta': 0, 'high_impact_miss_delta': 0}, {'episode': 50, 'ndcg_delta': 0.07049898421440559, 'miss_delta': -2, 'high_impact_miss_delta': 0}]\n",
      "Fit time (ms): 488.583\n",
      "Representative first/warm timings: [{'episode': 48, 'policy': 'severity_rule', 'phase': 'first_episode_pass', 'repeat': 0, 'wall_ms': 0.408}, {'episode': 48, 'policy': 'severity_rule', 'phase': 'warm_episode_repeat', 'repeat': 1, 'wall_ms': 0.135}, {'episode': 48, 'policy': 'severity_rule', 'phase': 'warm_episode_repeat', 'repeat': 2, 'wall_ms': 0.105}]\n",
      "Evidence saved to evidence/summary.json\n",
      "Evidence saved to evidence/records.json\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"591.59952pt\" height=\"199.91952pt\" viewBox=\"0 0 591.59952 199.91952\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2026-11-26T18:24:58.641280</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.10.9, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 199.91952 \n",
       "L 591.59952 199.91952 \n",
       "L 591.59952 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #f5f7f2\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 87.626563 160.36327 \n",
       "L 584.39952 160.36327 \n",
       "L 584.39952 34.3575 \n",
       "L 87.626563 34.3575 \n",
       "z\n",
       "\" style=\"fill: #f5f7f2\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path d=\"M 87.626563 160.36327 \n",
       "L 87.626563 34.3575 \n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\"/>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 0 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(84.445312 172.961708) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n",
       "Q 1547 4250 1301 3770 \n",
       "Q 1056 3291 1056 2328 \n",
       "Q 1056 1369 1301 889 \n",
       "Q 1547 409 2034 409 \n",
       "Q 2525 409 2770 889 \n",
       "Q 3016 1369 3016 2328 \n",
       "Q 3016 3291 2770 3770 \n",
       "Q 2525 4250 2034 4250 \n",
       "z\n",
       "M 2034 4750 \n",
       "Q 2819 4750 3233 4129 \n",
       "Q 3647 3509 3647 2328 \n",
       "Q 3647 1150 3233 529 \n",
       "Q 2819 -91 2034 -91 \n",
       "Q 1250 -91 836 529 \n",
       "Q 422 1150 422 2328 \n",
       "Q 422 3509 836 4129 \n",
       "Q 1250 4750 2034 4750 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path d=\"M 171.825369 160.36327 \n",
       "L 171.825369 34.3575 \n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\"/>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 1 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(168.644119 172.961708) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n",
       "L 1825 531 \n",
       "L 1825 4091 \n",
       "L 703 3866 \n",
       "L 703 4441 \n",
       "L 1819 4666 \n",
       "L 2450 4666 \n",
       "L 2450 531 \n",
       "L 3481 531 \n",
       "L 3481 0 \n",
       "L 794 0 \n",
       "L 794 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-31\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path d=\"M 256.024175 160.36327 \n",
       "L 256.024175 34.3575 \n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\"/>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 2 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(252.842925 172.961708) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path d=\"M 340.222982 160.36327 \n",
       "L 340.222982 34.3575 \n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\"/>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 3 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(337.041732 172.961708) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n",
       "Q 3050 2419 3304 2112 \n",
       "Q 3559 1806 3559 1356 \n",
       "Q 3559 666 3084 287 \n",
       "Q 2609 -91 1734 -91 \n",
       "Q 1441 -91 1130 -33 \n",
       "Q 819 25 488 141 \n",
       "L 488 750 \n",
       "Q 750 597 1062 519 \n",
       "Q 1375 441 1716 441 \n",
       "Q 2309 441 2620 675 \n",
       "Q 2931 909 2931 1356 \n",
       "Q 2931 1769 2642 2001 \n",
       "Q 2353 2234 1838 2234 \n",
       "L 1294 2234 \n",
       "L 1294 2753 \n",
       "L 1863 2753 \n",
       "Q 2328 2753 2575 2939 \n",
       "Q 2822 3125 2822 3475 \n",
       "Q 2822 3834 2567 4026 \n",
       "Q 2313 4219 1838 4219 \n",
       "Q 1578 4219 1281 4162 \n",
       "Q 984 4106 628 3988 \n",
       "L 628 4550 \n",
       "Q 988 4650 1302 4700 \n",
       "Q 1616 4750 1894 4750 \n",
       "Q 2613 4750 3031 4423 \n",
       "Q 3450 4097 3450 3541 \n",
       "Q 3450 3153 3228 2886 \n",
       "Q 3006 2619 2597 2516 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-33\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path d=\"M 424.421788 160.36327 \n",
       "L 424.421788 34.3575 \n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\"/>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 4 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(421.240538 172.961708) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n",
       "L 825 1625 \n",
       "L 2419 1625 \n",
       "L 2419 4116 \n",
       "z\n",
       "M 2253 4666 \n",
       "L 3047 4666 \n",
       "L 3047 1625 \n",
       "L 3713 1625 \n",
       "L 3713 1100 \n",
       "L 3047 1100 \n",
       "L 3047 0 \n",
       "L 2419 0 \n",
       "L 2419 1100 \n",
       "L 313 1100 \n",
       "L 313 1709 \n",
       "L 2253 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path d=\"M 508.620594 160.36327 \n",
       "L 508.620594 34.3575 \n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: none; stroke: #d3ded6; stroke-width: 0.75; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\"/>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 5 -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(505.439344 172.961708) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n",
       "L 3169 4666 \n",
       "L 3169 4134 \n",
       "L 1269 4134 \n",
       "L 1269 2991 \n",
       "Q 1406 3038 1543 3061 \n",
       "Q 1681 3084 1819 3084 \n",
       "Q 2600 3084 3056 2656 \n",
       "Q 3513 2228 3513 1497 \n",
       "Q 3513 744 3044 326 \n",
       "Q 2575 -91 1722 -91 \n",
       "Q 1428 -91 1123 -41 \n",
       "Q 819 9 494 109 \n",
       "L 494 744 \n",
       "Q 775 591 1075 516 \n",
       "Q 1375 441 1709 441 \n",
       "Q 2250 441 2565 725 \n",
       "Q 2881 1009 2881 1497 \n",
       "Q 2881 1984 2565 2268 \n",
       "Q 2250 2553 1709 2553 \n",
       "Q 1456 2553 1204 2497 \n",
       "Q 953 2441 691 2322 \n",
       "L 691 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_7\">\n",
       "     <!-- tickets -->\n",
       "     <g style=\"fill: #20382f\" transform=\"translate(87.626563 190.639833) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n",
       "L 1172 3500 \n",
       "L 2356 3500 \n",
       "L 2356 3053 \n",
       "L 1172 3053 \n",
       "L 1172 1153 \n",
       "Q 1172 725 1289 603 \n",
       "Q 1406 481 1766 481 \n",
       "L 2356 481 \n",
       "L 2356 0 \n",
       "L 1766 0 \n",
       "Q 1100 0 847 248 \n",
       "Q 594 497 594 1153 \n",
       "L 594 3053 \n",
       "L 172 3053 \n",
       "L 172 3500 \n",
       "L 594 3500 \n",
       "L 594 4494 \n",
       "L 1172 4494 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n",
       "L 1178 3500 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 3500 \n",
       "z\n",
       "M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 4134 \n",
       "L 603 4134 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n",
       "L 3122 2828 \n",
       "Q 2878 2963 2633 3030 \n",
       "Q 2388 3097 2138 3097 \n",
       "Q 1578 3097 1268 2742 \n",
       "Q 959 2388 959 1747 \n",
       "Q 959 1106 1268 751 \n",
       "Q 1578 397 2138 397 \n",
       "Q 2388 397 2633 464 \n",
       "Q 2878 531 3122 666 \n",
       "L 3122 134 \n",
       "Q 2881 22 2623 -34 \n",
       "Q 2366 -91 2075 -91 \n",
       "Q 1284 -91 818 406 \n",
       "Q 353 903 353 1747 \n",
       "Q 353 2603 823 3093 \n",
       "Q 1294 3584 2113 3584 \n",
       "Q 2378 3584 2631 3529 \n",
       "Q 2884 3475 3122 3366 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6b\" d=\"M 581 4863 \n",
       "L 1159 4863 \n",
       "L 1159 1991 \n",
       "L 2875 3500 \n",
       "L 3609 3500 \n",
       "L 1753 1863 \n",
       "L 3688 0 \n",
       "L 2938 0 \n",
       "L 1159 1709 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n",
       "L 3597 1613 \n",
       "L 953 1613 \n",
       "Q 991 1019 1311 708 \n",
       "Q 1631 397 2203 397 \n",
       "Q 2534 397 2845 478 \n",
       "Q 3156 559 3463 722 \n",
       "L 3463 178 \n",
       "Q 3153 47 2828 -22 \n",
       "Q 2503 -91 2169 -91 \n",
       "Q 1331 -91 842 396 \n",
       "Q 353 884 353 1716 \n",
       "Q 353 2575 817 3079 \n",
       "Q 1281 3584 2069 3584 \n",
       "Q 2775 3584 3186 3129 \n",
       "Q 3597 2675 3597 1894 \n",
       "z\n",
       "M 3022 2063 \n",
       "Q 3016 2534 2758 2815 \n",
       "Q 2500 3097 2075 3097 \n",
       "Q 1594 3097 1305 2825 \n",
       "Q 1016 2553 972 2059 \n",
       "L 3022 2063 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n",
       "L 2834 2853 \n",
       "Q 2591 2978 2328 3040 \n",
       "Q 2066 3103 1784 3103 \n",
       "Q 1356 3103 1142 2972 \n",
       "Q 928 2841 928 2578 \n",
       "Q 928 2378 1081 2264 \n",
       "Q 1234 2150 1697 2047 \n",
       "L 1894 2003 \n",
       "Q 2506 1872 2764 1633 \n",
       "Q 3022 1394 3022 966 \n",
       "Q 3022 478 2636 193 \n",
       "Q 2250 -91 1575 -91 \n",
       "Q 1294 -91 989 -36 \n",
       "Q 684 19 347 128 \n",
       "L 347 722 \n",
       "Q 666 556 975 473 \n",
       "Q 1284 391 1588 391 \n",
       "Q 1994 391 2212 530 \n",
       "Q 2431 669 2431 922 \n",
       "Q 2431 1156 2273 1281 \n",
       "Q 2116 1406 1581 1522 \n",
       "L 1381 1569 \n",
       "Q 847 1681 609 1914 \n",
       "Q 372 2147 372 2553 \n",
       "Q 372 3047 722 3315 \n",
       "Q 1072 3584 1716 3584 \n",
       "Q 2034 3584 2315 3537 \n",
       "Q 2597 3491 2834 3397 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-74\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(39.208984 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(66.992188 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6b\" transform=\"translate(121.972656 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(176.257812 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(237.78125 0)\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(276.990234 0)\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_13\"/>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- severity rule -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(19.90625 64.207765) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-76\" d=\"M 191 3500 \n",
       "L 800 3500 \n",
       "L 1894 563 \n",
       "L 2988 3500 \n",
       "L 3597 3500 \n",
       "L 2284 0 \n",
       "L 1503 0 \n",
       "L 191 3500 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n",
       "Q 2534 3019 2420 3045 \n",
       "Q 2306 3072 2169 3072 \n",
       "Q 1681 3072 1420 2755 \n",
       "Q 1159 2438 1159 1844 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1341 3275 1631 3429 \n",
       "Q 1922 3584 2338 3584 \n",
       "Q 2397 3584 2469 3576 \n",
       "Q 2541 3569 2628 3553 \n",
       "L 2631 2963 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n",
       "Q 1816 -950 1584 -1140 \n",
       "Q 1353 -1331 966 -1331 \n",
       "L 506 -1331 \n",
       "L 506 -850 \n",
       "L 844 -850 \n",
       "Q 1081 -850 1212 -737 \n",
       "Q 1344 -625 1503 -206 \n",
       "L 1606 56 \n",
       "L 191 3500 \n",
       "L 800 3500 \n",
       "L 1894 763 \n",
       "L 2988 3500 \n",
       "L 3597 3500 \n",
       "L 2059 -325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n",
       "L 544 3500 \n",
       "L 1119 3500 \n",
       "L 1119 1403 \n",
       "Q 1119 906 1312 657 \n",
       "Q 1506 409 1894 409 \n",
       "Q 2359 409 2629 706 \n",
       "Q 2900 1003 2900 1516 \n",
       "L 2900 3500 \n",
       "L 3475 3500 \n",
       "L 3475 0 \n",
       "L 2900 0 \n",
       "L 2900 538 \n",
       "Q 2691 219 2414 64 \n",
       "Q 2138 -91 1772 -91 \n",
       "Q 1169 -91 856 284 \n",
       "Q 544 659 544 1381 \n",
       "z\n",
       "M 1991 3584 \n",
       "L 1991 3584 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-73\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(52.099609 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-76\" transform=\"translate(113.623047 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(172.802734 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(234.326172 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(275.439453 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(303.222656 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-79\" transform=\"translate(342.431641 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(401.611328 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(433.398438 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-75\" transform=\"translate(474.511719 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(537.890625 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(565.673828 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_14\"/>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- learned impact -->\n",
       "      <g style=\"fill: #20382f\" transform=\"translate(7.2 138.111442) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n",
       "Q 1497 1759 1228 1600 \n",
       "Q 959 1441 959 1056 \n",
       "Q 959 750 1161 570 \n",
       "Q 1363 391 1709 391 \n",
       "Q 2188 391 2477 730 \n",
       "Q 2766 1069 2766 1631 \n",
       "L 2766 1759 \n",
       "L 2194 1759 \n",
       "z\n",
       "M 3341 1997 \n",
       "L 3341 0 \n",
       "L 2766 0 \n",
       "L 2766 531 \n",
       "Q 2569 213 2275 61 \n",
       "Q 1981 -91 1556 -91 \n",
       "Q 1019 -91 701 211 \n",
       "Q 384 513 384 1019 \n",
       "Q 384 1609 779 1909 \n",
       "Q 1175 2209 1959 2209 \n",
       "L 2766 2209 \n",
       "L 2766 2266 \n",
       "Q 2766 2663 2505 2880 \n",
       "Q 2244 3097 1772 3097 \n",
       "Q 1472 3097 1187 3025 \n",
       "Q 903 2953 641 2809 \n",
       "L 641 3341 \n",
       "Q 956 3463 1253 3523 \n",
       "Q 1550 3584 1831 3584 \n",
       "Q 2591 3584 2966 3190 \n",
       "Q 3341 2797 3341 1997 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n",
       "L 3513 0 \n",
       "L 2938 0 \n",
       "L 2938 2094 \n",
       "Q 2938 2591 2744 2837 \n",
       "Q 2550 3084 2163 3084 \n",
       "Q 1697 3084 1428 2787 \n",
       "Q 1159 2491 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1366 3272 1645 3428 \n",
       "Q 1925 3584 2291 3584 \n",
       "Q 2894 3584 3203 3211 \n",
       "Q 3513 2838 3513 2113 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n",
       "L 2906 4863 \n",
       "L 3481 4863 \n",
       "L 3481 0 \n",
       "L 2906 0 \n",
       "L 2906 525 \n",
       "Q 2725 213 2448 61 \n",
       "Q 2172 -91 1784 -91 \n",
       "Q 1150 -91 751 415 \n",
       "Q 353 922 353 1747 \n",
       "Q 353 2572 751 3078 \n",
       "Q 1150 3584 1784 3584 \n",
       "Q 2172 3584 2448 3432 \n",
       "Q 2725 3281 2906 2969 \n",
       "z\n",
       "M 947 1747 \n",
       "Q 947 1113 1208 752 \n",
       "Q 1469 391 1925 391 \n",
       "Q 2381 391 2643 752 \n",
       "Q 2906 1113 2906 1747 \n",
       "Q 2906 2381 2643 2742 \n",
       "Q 2381 3103 1925 3103 \n",
       "Q 1469 3103 1208 2742 \n",
       "Q 947 2381 947 1747 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-6d\" d=\"M 3328 2828 \n",
       "Q 3544 3216 3844 3400 \n",
       "Q 4144 3584 4550 3584 \n",
       "Q 5097 3584 5394 3201 \n",
       "Q 5691 2819 5691 2113 \n",
       "L 5691 0 \n",
       "L 5113 0 \n",
       "L 5113 2094 \n",
       "Q 5113 2597 4934 2840 \n",
       "Q 4756 3084 4391 3084 \n",
       "Q 3944 3084 3684 2787 \n",
       "Q 3425 2491 3425 1978 \n",
       "L 3425 0 \n",
       "L 2847 0 \n",
       "L 2847 2094 \n",
       "Q 2847 2600 2669 2842 \n",
       "Q 2491 3084 2119 3084 \n",
       "Q 1678 3084 1418 2786 \n",
       "Q 1159 2488 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1356 3278 1631 3431 \n",
       "Q 1906 3584 2284 3584 \n",
       "Q 2666 3584 2933 3390 \n",
       "Q 3200 3197 3328 2828 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n",
       "L 1159 -1331 \n",
       "L 581 -1331 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2969 \n",
       "Q 1341 3281 1617 3432 \n",
       "Q 1894 3584 2278 3584 \n",
       "Q 2916 3584 3314 3078 \n",
       "Q 3713 2572 3713 1747 \n",
       "Q 3713 922 3314 415 \n",
       "Q 2916 -91 2278 -91 \n",
       "Q 1894 -91 1617 61 \n",
       "Q 1341 213 1159 525 \n",
       "z\n",
       "M 3116 1747 \n",
       "Q 3116 2381 2855 2742 \n",
       "Q 2594 3103 2138 3103 \n",
       "Q 1681 3103 1420 2742 \n",
       "Q 1159 2381 1159 1747 \n",
       "Q 1159 1113 1420 752 \n",
       "Q 1681 391 2138 391 \n",
       "Q 2594 391 2855 752 \n",
       "Q 3116 1113 3116 1747 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-6c\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(27.783203 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(89.306641 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(150.585938 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(189.949219 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(253.328125 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-64\" transform=\"translate(314.851562 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(378.328125 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(410.115234 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-6d\" transform=\"translate(437.898438 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(535.310547 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(598.787109 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(660.066406 0)\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(715.046875 0)\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 87.626563 40.085035 \n",
       "L 508.620594 40.085035 \n",
       "L 508.620594 80.732058 \n",
       "L 87.626563 80.732058 \n",
       "z\n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: #3d6b5b\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 87.626563 113.988712 \n",
       "L 87.626563 113.988712 \n",
       "L 87.626563 154.635735 \n",
       "L 87.626563 154.635735 \n",
       "z\n",
       "\" clip-path=\"url(#pb590b0b9f6)\" style=\"fill: #298876\"/>\n",
       "   </g>\n",
       "   <g id=\"text_10\">\n",
       "    <!-- 5 -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(514.620594 63.167921) scale(0.1 -0.1)\">\n",
       "     <use xlink:href=\"#DejaVuSans-35\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"PathCollection_1\">\n",
       "    <defs>\n",
       "     <path id=\"maa84bb17d9\" d=\"M 0 1.870829 \n",
       "C 0.49615 1.870829 0.972045 1.673706 1.322876 1.322876 \n",
       "C 1.673706 0.972045 1.870829 0.49615 1.870829 0 \n",
       "C 1.870829 -0.49615 1.673706 -0.972045 1.322876 -1.322876 \n",
       "C 0.972045 -1.673706 0.49615 -1.870829 0 -1.870829 \n",
       "C -0.49615 -1.870829 -0.972045 -1.673706 -1.322876 -1.322876 \n",
       "C -1.673706 -0.972045 -1.870829 -0.49615 -1.870829 0 \n",
       "C -1.870829 0.49615 -1.673706 0.972045 -1.322876 1.322876 \n",
       "C -0.972045 1.673706 -0.49615 1.870829 0 1.870829 \n",
       "z\n",
       "\" style=\"stroke: #20382f\"/>\n",
       "    </defs>\n",
       "    <g>\n",
       "     <use xlink:href=\"#maa84bb17d9\" x=\"87.626563\" y=\"134.312224\" style=\"fill: #20382f; stroke: #20382f\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_11\">\n",
       "    <!-- 0 -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(93.626563 137.071599) scale(0.1 -0.1)\">\n",
       "     <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"text_12\">\n",
       "    <!-- High-impact tickets that missed deadline -->\n",
       "    <g style=\"fill: #20382f\" transform=\"translate(87.626563 19.3575) scale(0.16 -0.16)\">\n",
       "     <defs>\n",
       "      <path id=\"DejaVuSans-Bold-48\" d=\"M 588 4666 \n",
       "L 1791 4666 \n",
       "L 1791 2888 \n",
       "L 3566 2888 \n",
       "L 3566 4666 \n",
       "L 4769 4666 \n",
       "L 4769 0 \n",
       "L 3566 0 \n",
       "L 3566 1978 \n",
       "L 1791 1978 \n",
       "L 1791 0 \n",
       "L 588 0 \n",
       "L 588 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-69\" d=\"M 538 3500 \n",
       "L 1656 3500 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 3500 \n",
       "z\n",
       "M 538 4863 \n",
       "L 1656 4863 \n",
       "L 1656 3950 \n",
       "L 538 3950 \n",
       "L 538 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-67\" d=\"M 2919 594 \n",
       "Q 2688 288 2409 144 \n",
       "Q 2131 0 1766 0 \n",
       "Q 1125 0 706 504 \n",
       "Q 288 1009 288 1791 \n",
       "Q 288 2575 706 3076 \n",
       "Q 1125 3578 1766 3578 \n",
       "Q 2131 3578 2409 3434 \n",
       "Q 2688 3291 2919 2981 \n",
       "L 2919 3500 \n",
       "L 4044 3500 \n",
       "L 4044 353 \n",
       "Q 4044 -491 3511 -936 \n",
       "Q 2978 -1381 1966 -1381 \n",
       "Q 1638 -1381 1331 -1331 \n",
       "Q 1025 -1281 716 -1178 \n",
       "L 716 -306 \n",
       "Q 1009 -475 1290 -558 \n",
       "Q 1572 -641 1856 -641 \n",
       "Q 2406 -641 2662 -400 \n",
       "Q 2919 -159 2919 353 \n",
       "L 2919 594 \n",
       "z\n",
       "M 2181 2772 \n",
       "Q 1834 2772 1640 2515 \n",
       "Q 1447 2259 1447 1791 \n",
       "Q 1447 1309 1634 1061 \n",
       "Q 1822 813 2181 813 \n",
       "Q 2531 813 2725 1069 \n",
       "Q 2919 1325 2919 1791 \n",
       "Q 2919 2259 2725 2515 \n",
       "Q 2531 2772 2181 2772 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-68\" d=\"M 4056 2131 \n",
       "L 4056 0 \n",
       "L 2931 0 \n",
       "L 2931 347 \n",
       "L 2931 1625 \n",
       "Q 2931 2084 2911 2256 \n",
       "Q 2891 2428 2841 2509 \n",
       "Q 2775 2619 2662 2680 \n",
       "Q 2550 2741 2406 2741 \n",
       "Q 2056 2741 1856 2470 \n",
       "Q 1656 2200 1656 1722 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 4863 \n",
       "L 1656 4863 \n",
       "L 1656 2988 \n",
       "Q 1909 3294 2193 3439 \n",
       "Q 2478 3584 2822 3584 \n",
       "Q 3428 3584 3742 3212 \n",
       "Q 4056 2841 4056 2131 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-2d\" d=\"M 347 2297 \n",
       "L 2309 2297 \n",
       "L 2309 1388 \n",
       "L 347 1388 \n",
       "L 347 2297 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6d\" d=\"M 3781 2919 \n",
       "Q 3994 3244 4286 3414 \n",
       "Q 4578 3584 4928 3584 \n",
       "Q 5531 3584 5847 3212 \n",
       "Q 6163 2841 6163 2131 \n",
       "L 6163 0 \n",
       "L 5038 0 \n",
       "L 5038 1825 \n",
       "Q 5041 1866 5042 1909 \n",
       "Q 5044 1953 5044 2034 \n",
       "Q 5044 2406 4934 2573 \n",
       "Q 4825 2741 4581 2741 \n",
       "Q 4263 2741 4089 2478 \n",
       "Q 3916 2216 3909 1719 \n",
       "L 3909 0 \n",
       "L 2784 0 \n",
       "L 2784 1825 \n",
       "Q 2784 2406 2684 2573 \n",
       "Q 2584 2741 2328 2741 \n",
       "Q 2006 2741 1831 2477 \n",
       "Q 1656 2213 1656 1722 \n",
       "L 1656 0 \n",
       "L 531 0 \n",
       "L 531 3500 \n",
       "L 1656 3500 \n",
       "L 1656 2988 \n",
       "Q 1863 3284 2130 3434 \n",
       "Q 2397 3584 2719 3584 \n",
       "Q 3081 3584 3359 3409 \n",
       "Q 3638 3234 3781 2919 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-70\" d=\"M 1656 506 \n",
       "L 1656 -1331 \n",
       "L 538 -1331 \n",
       "L 538 3500 \n",
       "L 1656 3500 \n",
       "L 1656 2988 \n",
       "Q 1888 3294 2169 3439 \n",
       "Q 2450 3584 2816 3584 \n",
       "Q 3463 3584 3878 3070 \n",
       "Q 4294 2556 4294 1747 \n",
       "Q 4294 938 3878 423 \n",
       "Q 3463 -91 2816 -91 \n",
       "Q 2450 -91 2169 54 \n",
       "Q 1888 200 1656 506 \n",
       "z\n",
       "M 2400 2772 \n",
       "Q 2041 2772 1848 2508 \n",
       "Q 1656 2244 1656 1747 \n",
       "Q 1656 1250 1848 986 \n",
       "Q 2041 722 2400 722 \n",
       "Q 2759 722 2948 984 \n",
       "Q 3138 1247 3138 1747 \n",
       "Q 3138 2247 2948 2509 \n",
       "Q 2759 2772 2400 2772 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-61\" d=\"M 2106 1575 \n",
       "Q 1756 1575 1579 1456 \n",
       "Q 1403 1338 1403 1106 \n",
       "Q 1403 894 1545 773 \n",
       "Q 1688 653 1941 653 \n",
       "Q 2256 653 2472 879 \n",
       "Q 2688 1106 2688 1447 \n",
       "L 2688 1575 \n",
       "L 2106 1575 \n",
       "z\n",
       "M 3816 1997 \n",
       "L 3816 0 \n",
       "L 2688 0 \n",
       "L 2688 519 \n",
       "Q 2463 200 2181 54 \n",
       "Q 1900 -91 1497 -91 \n",
       "Q 953 -91 614 226 \n",
       "Q 275 544 275 1050 \n",
       "Q 275 1666 698 1953 \n",
       "Q 1122 2241 2028 2241 \n",
       "L 2688 2241 \n",
       "L 2688 2328 \n",
       "Q 2688 2594 2478 2717 \n",
       "Q 2269 2841 1825 2841 \n",
       "Q 1466 2841 1156 2769 \n",
       "Q 847 2697 581 2553 \n",
       "L 581 3406 \n",
       "Q 941 3494 1303 3539 \n",
       "Q 1666 3584 2028 3584 \n",
       "Q 2975 3584 3395 3211 \n",
       "Q 3816 2838 3816 1997 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-63\" d=\"M 3366 3391 \n",
       "L 3366 2478 \n",
       "Q 3138 2634 2908 2709 \n",
       "Q 2678 2784 2431 2784 \n",
       "Q 1963 2784 1702 2511 \n",
       "Q 1441 2238 1441 1747 \n",
       "Q 1441 1256 1702 982 \n",
       "Q 1963 709 2431 709 \n",
       "Q 2694 709 2930 787 \n",
       "Q 3166 866 3366 1019 \n",
       "L 3366 103 \n",
       "Q 3103 6 2833 -42 \n",
       "Q 2563 -91 2291 -91 \n",
       "Q 1344 -91 809 395 \n",
       "Q 275 881 275 1747 \n",
       "Q 275 2613 809 3098 \n",
       "Q 1344 3584 2291 3584 \n",
       "Q 2566 3584 2833 3536 \n",
       "Q 3100 3488 3366 3391 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-74\" d=\"M 1759 4494 \n",
       "L 1759 3500 \n",
       "L 2913 3500 \n",
       "L 2913 2700 \n",
       "L 1759 2700 \n",
       "L 1759 1216 \n",
       "Q 1759 972 1856 886 \n",
       "Q 1953 800 2241 800 \n",
       "L 2816 800 \n",
       "L 2816 0 \n",
       "L 1856 0 \n",
       "Q 1194 0 917 276 \n",
       "Q 641 553 641 1216 \n",
       "L 641 2700 \n",
       "L 84 2700 \n",
       "L 84 3500 \n",
       "L 641 3500 \n",
       "L 641 4494 \n",
       "L 1759 4494 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-20\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6b\" d=\"M 538 4863 \n",
       "L 1656 4863 \n",
       "L 1656 2216 \n",
       "L 2944 3500 \n",
       "L 4244 3500 \n",
       "L 2534 1894 \n",
       "L 4378 0 \n",
       "L 3022 0 \n",
       "L 1656 1459 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-65\" d=\"M 4031 1759 \n",
       "L 4031 1441 \n",
       "L 1416 1441 \n",
       "Q 1456 1047 1700 850 \n",
       "Q 1944 653 2381 653 \n",
       "Q 2734 653 3104 758 \n",
       "Q 3475 863 3866 1075 \n",
       "L 3866 213 \n",
       "Q 3469 63 3072 -14 \n",
       "Q 2675 -91 2278 -91 \n",
       "Q 1328 -91 801 392 \n",
       "Q 275 875 275 1747 \n",
       "Q 275 2603 792 3093 \n",
       "Q 1309 3584 2216 3584 \n",
       "Q 3041 3584 3536 3087 \n",
       "Q 4031 2591 4031 1759 \n",
       "z\n",
       "M 2881 2131 \n",
       "Q 2881 2450 2695 2645 \n",
       "Q 2509 2841 2209 2841 \n",
       "Q 1884 2841 1681 2658 \n",
       "Q 1478 2475 1428 2131 \n",
       "L 2881 2131 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-73\" d=\"M 3272 3391 \n",
       "L 3272 2541 \n",
       "Q 2913 2691 2578 2766 \n",
       "Q 2244 2841 1947 2841 \n",
       "Q 1628 2841 1473 2761 \n",
       "Q 1319 2681 1319 2516 \n",
       "Q 1319 2381 1436 2309 \n",
       "Q 1553 2238 1856 2203 \n",
       "L 2053 2175 \n",
       "Q 2913 2066 3209 1816 \n",
       "Q 3506 1566 3506 1031 \n",
       "Q 3506 472 3093 190 \n",
       "Q 2681 -91 1863 -91 \n",
       "Q 1516 -91 1145 -36 \n",
       "Q 775 19 384 128 \n",
       "L 384 978 \n",
       "Q 719 816 1070 734 \n",
       "Q 1422 653 1784 653 \n",
       "Q 2113 653 2278 743 \n",
       "Q 2444 834 2444 1013 \n",
       "Q 2444 1163 2330 1236 \n",
       "Q 2216 1309 1875 1350 \n",
       "L 1678 1375 \n",
       "Q 931 1469 631 1722 \n",
       "Q 331 1975 331 2491 \n",
       "Q 331 3047 712 3315 \n",
       "Q 1094 3584 1881 3584 \n",
       "Q 2191 3584 2531 3537 \n",
       "Q 2872 3491 3272 3391 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-64\" d=\"M 2919 2988 \n",
       "L 2919 4863 \n",
       "L 4044 4863 \n",
       "L 4044 0 \n",
       "L 2919 0 \n",
       "L 2919 506 \n",
       "Q 2688 197 2409 53 \n",
       "Q 2131 -91 1766 -91 \n",
       "Q 1119 -91 703 423 \n",
       "Q 288 938 288 1747 \n",
       "Q 288 2556 703 3070 \n",
       "Q 1119 3584 1766 3584 \n",
       "Q 2128 3584 2408 3439 \n",
       "Q 2688 3294 2919 2988 \n",
       "z\n",
       "M 2181 722 \n",
       "Q 2541 722 2730 984 \n",
       "Q 2919 1247 2919 1747 \n",
       "Q 2919 2247 2730 2509 \n",
       "Q 2541 2772 2181 2772 \n",
       "Q 1825 2772 1636 2509 \n",
       "Q 1447 2247 1447 1747 \n",
       "Q 1447 1247 1636 984 \n",
       "Q 1825 722 2181 722 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6c\" d=\"M 538 4863 \n",
       "L 1656 4863 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      <path id=\"DejaVuSans-Bold-6e\" d=\"M 4056 2131 \n",
       "L 4056 0 \n",
       "L 2931 0 \n",
       "L 2931 347 \n",
       "L 2931 1631 \n",
       "Q 2931 2084 2911 2256 \n",
       "Q 2891 2428 2841 2509 \n",
       "Q 2775 2619 2662 2680 \n",
       "Q 2550 2741 2406 2741 \n",
       "Q 2056 2741 1856 2470 \n",
       "Q 1656 2200 1656 1722 \n",
       "L 1656 0 \n",
       "L 538 0 \n",
       "L 538 3500 \n",
       "L 1656 3500 \n",
       "L 1656 2988 \n",
       "Q 1909 3294 2193 3439 \n",
       "Q 2478 3584 2822 3584 \n",
       "Q 3428 3584 3742 3212 \n",
       "Q 4056 2841 4056 2131 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "     </defs>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-48\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-69\" transform=\"translate(83.691406 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-67\" transform=\"translate(117.96875 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-68\" transform=\"translate(189.550781 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-2d\" transform=\"translate(260.742188 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-69\" transform=\"translate(302.246094 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6d\" transform=\"translate(336.523438 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-70\" transform=\"translate(440.722656 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-61\" transform=\"translate(512.304688 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-63\" transform=\"translate(579.785156 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(639.0625 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(686.865234 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(721.679688 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-69\" transform=\"translate(769.482422 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-63\" transform=\"translate(803.759766 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6b\" transform=\"translate(863.037109 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(926.916016 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(994.738281 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(1042.541016 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(1102.0625 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(1136.876953 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-68\" transform=\"translate(1184.679688 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-61\" transform=\"translate(1255.871094 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-74\" transform=\"translate(1323.351562 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(1371.154297 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6d\" transform=\"translate(1405.96875 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-69\" transform=\"translate(1510.167969 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(1544.445312 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-73\" transform=\"translate(1603.966797 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(1663.488281 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-64\" transform=\"translate(1731.310547 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-20\" transform=\"translate(1802.892578 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-64\" transform=\"translate(1837.707031 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(1909.289062 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-61\" transform=\"translate(1977.111328 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-64\" transform=\"translate(2044.591797 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6c\" transform=\"translate(2116.173828 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-69\" transform=\"translate(2150.451172 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-6e\" transform=\"translate(2184.728516 0)\"/>\n",
       "     <use xlink:href=\"#DejaVuSans-Bold-65\" transform=\"translate(2255.919922 0)\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pb590b0b9f6\">\n",
       "   <rect x=\"87.626563\" y=\"34.3575\" width=\"496.772957\" height=\"126.00577\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 810x266 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "score_policies = {\"severity_rule\": incumbent_scores, \"learned_impact\": learned_scores}\n",
    "case_rows = []\n",
    "timing_rows = []\n",
    "episode_rows = []\n",
    "for index, tickets in enumerate(evaluation_episodes):\n",
    "    grades = np.array([ticket[\"impact_grade\"] for ticket in tickets])\n",
    "    ordered_policies = list(score_policies) if index % 2 == 0 else list(reversed(score_policies))\n",
    "    for policy in ordered_policies:\n",
    "        for repeat in range(3):\n",
    "            started = perf_counter()\n",
    "            scores = score_policies[policy](tickets)\n",
    "            dispatches, peak_backlog, close_backlog = replay(tickets, scores)\n",
    "            elapsed_ms = (perf_counter() - started) * 1000\n",
    "            timing_rows.append({\n",
    "                \"episode\": index + 48,\n",
    "                \"policy\": policy,\n",
    "                \"phase\": \"first_episode_pass\" if repeat == 0 else \"warm_episode_repeat\",\n",
    "                \"repeat\": repeat,\n",
    "                \"wall_ms\": round(elapsed_ms, 3),\n",
    "            })\n",
    "            if repeat != 0:\n",
    "                continue\n",
    "            score_by_id = {ticket[\"ticket_id\"]: float(score) for ticket, score in zip(tickets, scores)}\n",
    "            ordinal_scores = np.empty(len(tickets))\n",
    "            ordinal_scores[policy_order(tickets, scores)] = np.arange(len(tickets), 0, -1)\n",
    "            episode_rows.append({\n",
    "                \"episode\": index + 48,\n",
    "                \"policy\": policy,\n",
    "                \"ndcg_at_10\": float(ndcg_score([grades], [ordinal_scores], k=RANKING_K)),\n",
    "                \"misses\": sum(row[\"missed_deadline\"] for row in dispatches),\n",
    "                \"high_impact_misses\": sum(\n",
    "                    row[\"missed_deadline\"] and row[\"high_impact\"] for row in dispatches\n",
    "                ),\n",
    "                \"peak_backlog\": peak_backlog,\n",
    "                \"close_backlog\": close_backlog,\n",
    "                \"constraint_violations\": count_violations(tickets, dispatches),\n",
    "            })\n",
    "            case_rows.extend({\n",
    "                **row,\n",
    "                \"episode\": index + 48,\n",
    "                \"policy\": policy,\n",
    "                \"priority_score\": score_by_id[row[\"ticket_id\"]],\n",
    "            } for row in dispatches)\n",
    "\n",
    "summaries = []\n",
    "for policy in score_policies:\n",
    "    entries = [row for row in episode_rows if row[\"policy\"] == policy]\n",
    "    summaries.append({\n",
    "        \"policy\": policy,\n",
    "        \"mean_ndcg_at_10\": round(float(np.mean([row[\"ndcg_at_10\"] for row in entries])), 3),\n",
    "        \"deadline_misses\": sum(row[\"misses\"] for row in entries),\n",
    "        \"high_impact_deadline_misses\": sum(row[\"high_impact_misses\"] for row in entries),\n",
    "        \"median_peak_backlog\": float(np.median([row[\"peak_backlog\"] for row in entries])),\n",
    "        \"constraint_violations\": sum(row[\"constraint_violations\"] for row in entries),\n",
    "    })\n",
    "paired_episodes = []\n",
    "for episode_id in range(48, 60):\n",
    "    pair = {row[\"policy\"]: row for row in episode_rows if row[\"episode\"] == episode_id}\n",
    "    paired_episodes.append({\n",
    "        \"episode\": episode_id,\n",
    "        \"ndcg_delta\": pair[\"learned_impact\"][\"ndcg_at_10\"] - pair[\"severity_rule\"][\"ndcg_at_10\"],\n",
    "        \"miss_delta\": pair[\"learned_impact\"][\"misses\"] - pair[\"severity_rule\"][\"misses\"],\n",
    "        \"high_impact_miss_delta\": (\n",
    "            pair[\"learned_impact\"][\"high_impact_misses\"] - pair[\"severity_rule\"][\"high_impact_misses\"]\n",
    "        ),\n",
    "    })\n",
    "assert len(case_rows) == 2 * sum(map(len, evaluation_episodes))\n",
    "assert all(row[\"constraint_violations\"] == 0 for row in summaries)\n",
    "for summary in summaries:\n",
    "    print(summary)\n",
    "print(\"Paired episode changes, learned minus rules:\", paired_episodes[:3])\n",
    "print(\"Fit time (ms):\", round(fit_ms, 3))\n",
    "print(\"Representative first/warm timings:\", timing_rows[:3])\n",
    "save(\"summary\", {\n",
    "    \"seed\": SEED,\n",
    "    \"technician_skills\": {name: sorted(skills) for name, skills in TECHNICIANS.items()},\n",
    "    \"training_episodes\": len(train_episodes),\n",
    "    \"evaluation_episodes\": len(evaluation_episodes),\n",
    "    \"fit_ms\": fit_ms,\n",
    "    \"policies\": summaries,\n",
    "    \"paired_episodes\": paired_episodes,\n",
    "})\n",
    "save(\"records\", {\n",
    "    \"dispatches\": case_rows,\n",
    "    \"episodes\": episode_rows,\n",
    "    \"timings\": timing_rows,\n",
    "    \"input_episodes\": evaluation_episodes,\n",
    "})\n",
    "chart(\n",
    "    \"High-impact tickets that missed deadline\",\n",
    "    [row[\"policy\"] for row in summaries],\n",
    "    [row[\"high_impact_deadline_misses\"] for row in summaries],\n",
    "    \"tickets\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-21",
   "metadata": {},
   "source": [
    "Interpret the two columns independently. NDCG rewards moving high-impact\n",
    "tickets up. Deadline misses still depend on repair durations, absolute clock\n",
    "time, and which skills are available. A policy can serve high-impact tickets\n",
    "sooner yet increase other misses. A follow-on replay could change just\n",
    "coverage in one trade and check whether that reverses the comparison.\n",
    "\n",
    "[scikit-learn ranking metrics](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.ndcg_score.html)\n",
    "· [SciPy linear assignment](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linear_sum_assignment.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lab-10-22",
   "metadata": {},
   "source": [
    "## Read the result\n",
    "\n",
    "Inspect the per-case records in `evidence/` before drawing a conclusion from an aggregate. Use the printed sample size, split and hardware when comparing it with another run.\n",
    "\n",
    "- [XGBoost: A Scalable Tree Boosting System](https://arxiv.org/abs/1603.02754)\n",
    "- [Google OR-Tools](https://developers.google.com/optimization)"
   ]
  }
 ],
 "metadata": {
  "course": {
   "lab": 10,
   "slug": "10-rank-a-technician-queue"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
