{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "g1-md-intro",
   "metadata": {},
   "source": [
    "# 01 \u2014 Benefits Analysis\n",
    "\n",
    "**Study:** Forrester *Total Economic Impact\u2122 Of CX Cloud \u2014 Cost Savings\n",
    "And Business Benefits Enabled By Genesys And Salesforce* (December 2025)\n",
    "\n",
    "Quantify the four benefit categories Forrester identified for the\n",
    "composite organization (\\$2.5B revenue, 600 CX agents / 400 concurrent\n",
    "licenses, 80,000 weekly interactions @ 12 min), push them into Athena,\n",
    "and verify the totals match the published study\n",
    "(Benefits PV \u2248 **\\$14.84M**)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-setup",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "We add the project root to `sys.path` so the notebook can import `core` and\n",
    "the study's local modules without `pip install -e .`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01-bootstrap",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys, pathlib                       # path shim: works on a fresh kernel\n",
    "for _p in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents]:\n",
    "    if (_p / \"pyproject.toml\").exists():\n",
    "        sys.path.insert(0, str(_p)); break\n",
    "\n",
    "from core.bootstrap import init\n",
    "\n",
    "pal = init(study=\"202512_GenesysCX\")\n",
    "client, seed, config = pal.client, pal.seed_data, pal.config\n",
    "\n",
    "STUDY = pal.root / 'studies' / '202512_GenesysCX'\n",
    "ROOT  = pal.root\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "g1-code-imports",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"padding:10px 14px;border-left:4px solid #0277bd;background:#e1f5fe;color:#1a1a1a;border-radius:4px;margin:6px 0;\">Study: <b>202512_GenesysCX</b> \u2022 discount rate 10% \u2022 3-year horizon</div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from core.calculations import npv, risk_adjust_benefit\n",
    "from core.notebook_helpers import charts, display, tables\n",
    "display.alert(\n",
    "    f'Study: <b>{config.STUDY_SLUG}</b> \u2022 discount rate {config.DISCOUNT_RATE:.0%} '\n",
    "    f'\u2022 {config.ANALYSIS_YEARS}-year horizon',\n",
    "    'info',\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-benefits-table",
   "metadata": {},
   "source": [
    "## Benefits \u2014 what the published study quantifies\n",
    "\n",
    "Forrester quantifies four benefit categories for the composite. The MTTR,\n",
    "self-service deflection and revenue-lift assumptions are documented in the\n",
    "`notes` field of every seed row (full PDF cell references \u2014 A1\u2013A4, B1\u2013B8,\n",
    "C1\u2013C6, D1\u2013D3 \u2014 preserved for the audit trail):\n",
    "\n",
    "| Ref | Benefit | Y1 | Y2 | Y3 | Risk Adj |\n",
    "|---|---|---|---|---|---|\n",
    "| At | Retirement of legacy systems with CX Cloud adoption | \\$680K | \\$930K | \\$930K | 5% |\n",
    "| Bt | Self-service savings (40 FTEs reallocated) | \\$2.33M | \\$2.33M | \\$2.33M | 15% |\n",
    "| Ct | CX agent efficiency (MTTR 12\u219210 min, 60k weekly interactions) | \\$2.91M | \\$2.91M | \\$2.91M | 10% |\n",
    "| Dt | Incremental sales from agent assist (1.5% lift \u00d7 8% margin \u00d7 \\$500M) | \\$0.6M | \\$0.6M | \\$0.6M | 5% |\n",
    "\n",
    "All four are seeded in `seed_data.BENEFITS` with full source notes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "g1-code-benefits-table",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "</style>\n",
       "<table id=\"T_f87c4\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th id=\"T_f87c4_level0_col0\" class=\"col_heading level0 col0\" >field_key</th>\n",
       "      <th id=\"T_f87c4_level0_col1\" class=\"col_heading level0 col1\" >label</th>\n",
       "      <th id=\"T_f87c4_level0_col2\" class=\"col_heading level0 col2\" >category</th>\n",
       "      <th id=\"T_f87c4_level0_col3\" class=\"col_heading level0 col3\" >risk_adjustment</th>\n",
       "      <th id=\"T_f87c4_level0_col4\" class=\"col_heading level0 col4\" >Year 1</th>\n",
       "      <th id=\"T_f87c4_level0_col5\" class=\"col_heading level0 col5\" >Year 1 (RA)</th>\n",
       "      <th id=\"T_f87c4_level0_col6\" class=\"col_heading level0 col6\" >Year 2</th>\n",
       "      <th id=\"T_f87c4_level0_col7\" class=\"col_heading level0 col7\" >Year 2 (RA)</th>\n",
       "      <th id=\"T_f87c4_level0_col8\" class=\"col_heading level0 col8\" >Year 3</th>\n",
       "      <th id=\"T_f87c4_level0_col9\" class=\"col_heading level0 col9\" >Year 3 (RA)</th>\n",
       "      <th id=\"T_f87c4_level0_col10\" class=\"col_heading level0 col10\" >Total</th>\n",
       "      <th id=\"T_f87c4_level0_col11\" class=\"col_heading level0 col11\" >Total (RA)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_f87c4_level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
       "      <td id=\"T_f87c4_row0_col0\" class=\"data row0 col0\" >legacy_retirement</td>\n",
       "      <td id=\"T_f87c4_row0_col1\" class=\"data row0 col1\" >Retirement of legacy systems with CX Cloud adoption</td>\n",
       "      <td id=\"T_f87c4_row0_col2\" class=\"data row0 col2\" >Cost Savings</td>\n",
       "      <td id=\"T_f87c4_row0_col3\" class=\"data row0 col3\" >0.050000</td>\n",
       "      <td id=\"T_f87c4_row0_col4\" class=\"data row0 col4\" >$680,000</td>\n",
       "      <td id=\"T_f87c4_row0_col5\" class=\"data row0 col5\" >$646,000</td>\n",
       "      <td id=\"T_f87c4_row0_col6\" class=\"data row0 col6\" >$930,000</td>\n",
       "      <td id=\"T_f87c4_row0_col7\" class=\"data row0 col7\" >$883,500</td>\n",
       "      <td id=\"T_f87c4_row0_col8\" class=\"data row0 col8\" >$930,000</td>\n",
       "      <td id=\"T_f87c4_row0_col9\" class=\"data row0 col9\" >$883,500</td>\n",
       "      <td id=\"T_f87c4_row0_col10\" class=\"data row0 col10\" >$2,540,000</td>\n",
       "      <td id=\"T_f87c4_row0_col11\" class=\"data row0 col11\" >$2,413,000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_f87c4_level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
       "      <td id=\"T_f87c4_row1_col0\" class=\"data row1 col0\" >self_service_savings</td>\n",
       "      <td id=\"T_f87c4_row1_col1\" class=\"data row1 col1\" >Cost savings from reallocated workers and avoided seasonal hires with increased customer self-service</td>\n",
       "      <td id=\"T_f87c4_row1_col2\" class=\"data row1 col2\" >Productivity</td>\n",
       "      <td id=\"T_f87c4_row1_col3\" class=\"data row1 col3\" >0.150000</td>\n",
       "      <td id=\"T_f87c4_row1_col4\" class=\"data row1 col4\" >$2,329,600</td>\n",
       "      <td id=\"T_f87c4_row1_col5\" class=\"data row1 col5\" >$1,980,160</td>\n",
       "      <td id=\"T_f87c4_row1_col6\" class=\"data row1 col6\" >$2,329,600</td>\n",
       "      <td id=\"T_f87c4_row1_col7\" class=\"data row1 col7\" >$1,980,160</td>\n",
       "      <td id=\"T_f87c4_row1_col8\" class=\"data row1 col8\" >$2,329,600</td>\n",
       "      <td id=\"T_f87c4_row1_col9\" class=\"data row1 col9\" >$1,980,160</td>\n",
       "      <td id=\"T_f87c4_row1_col10\" class=\"data row1 col10\" >$6,988,800</td>\n",
       "      <td id=\"T_f87c4_row1_col11\" class=\"data row1 col11\" >$5,940,480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_f87c4_level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
       "      <td id=\"T_f87c4_row2_col0\" class=\"data row2 col0\" >agent_efficiency</td>\n",
       "      <td id=\"T_f87c4_row2_col1\" class=\"data row2 col1\" >CX agent efficiency gains</td>\n",
       "      <td id=\"T_f87c4_row2_col2\" class=\"data row2 col2\" >Productivity</td>\n",
       "      <td id=\"T_f87c4_row2_col3\" class=\"data row2 col3\" >0.100000</td>\n",
       "      <td id=\"T_f87c4_row2_col4\" class=\"data row2 col4\" >$2,912,000</td>\n",
       "      <td id=\"T_f87c4_row2_col5\" class=\"data row2 col5\" >$2,620,800</td>\n",
       "      <td id=\"T_f87c4_row2_col6\" class=\"data row2 col6\" >$2,912,000</td>\n",
       "      <td id=\"T_f87c4_row2_col7\" class=\"data row2 col7\" >$2,620,800</td>\n",
       "      <td id=\"T_f87c4_row2_col8\" class=\"data row2 col8\" >$2,912,000</td>\n",
       "      <td id=\"T_f87c4_row2_col9\" class=\"data row2 col9\" >$2,620,800</td>\n",
       "      <td id=\"T_f87c4_row2_col10\" class=\"data row2 col10\" >$8,736,000</td>\n",
       "      <td id=\"T_f87c4_row2_col11\" class=\"data row2 col11\" >$7,862,400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_f87c4_level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
       "      <td id=\"T_f87c4_row3_col0\" class=\"data row3 col0\" >agent_assist_sales</td>\n",
       "      <td id=\"T_f87c4_row3_col1\" class=\"data row3 col1\" >Incremental sales from agent assist capabilities</td>\n",
       "      <td id=\"T_f87c4_row3_col2\" class=\"data row3 col2\" >Revenue</td>\n",
       "      <td id=\"T_f87c4_row3_col3\" class=\"data row3 col3\" >0.050000</td>\n",
       "      <td id=\"T_f87c4_row3_col4\" class=\"data row3 col4\" >$600,000</td>\n",
       "      <td id=\"T_f87c4_row3_col5\" class=\"data row3 col5\" >$570,000</td>\n",
       "      <td id=\"T_f87c4_row3_col6\" class=\"data row3 col6\" >$600,000</td>\n",
       "      <td id=\"T_f87c4_row3_col7\" class=\"data row3 col7\" >$570,000</td>\n",
       "      <td id=\"T_f87c4_row3_col8\" class=\"data row3 col8\" >$600,000</td>\n",
       "      <td id=\"T_f87c4_row3_col9\" class=\"data row3 col9\" >$570,000</td>\n",
       "      <td id=\"T_f87c4_row3_col10\" class=\"data row3 col10\" >$1,800,000</td>\n",
       "      <td id=\"T_f87c4_row3_col11\" class=\"data row3 col11\" >$1,710,000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x10382ae10>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = tables.benefits_table(seed.BENEFITS)\n",
    "df.style.format({col: '${:,.0f}' for col in df.columns if col not in ('field_key','label','category','risk_adjustment')})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-source-notes",
   "metadata": {},
   "source": [
    "### Where each benefit comes from\n",
    "\n",
    "The seed-data notes capture the per-line Forrester math so the model\n",
    "stays auditable. Surface them next to the headline numbers:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "g1-code-source-notes",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_eab42_row0_col0, #T_eab42_row0_col1, #T_eab42_row0_col2, #T_eab42_row0_col3, #T_eab42_row0_col4, #T_eab42_row1_col0, #T_eab42_row1_col1, #T_eab42_row1_col2, #T_eab42_row1_col3, #T_eab42_row1_col4, #T_eab42_row2_col0, #T_eab42_row2_col1, #T_eab42_row2_col2, #T_eab42_row2_col3, #T_eab42_row2_col4, #T_eab42_row3_col0, #T_eab42_row3_col1, #T_eab42_row3_col2, #T_eab42_row3_col3, #T_eab42_row3_col4 {\n",
       "  text-align: left;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_eab42\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th id=\"T_eab42_level0_col0\" class=\"col_heading level0 col0\" >Ref</th>\n",
       "      <th id=\"T_eab42_level0_col1\" class=\"col_heading level0 col1\" >Benefit</th>\n",
       "      <th id=\"T_eab42_level0_col2\" class=\"col_heading level0 col2\" >Risk Adj</th>\n",
       "      <th id=\"T_eab42_level0_col3\" class=\"col_heading level0 col3\" >3-yr Nominal</th>\n",
       "      <th id=\"T_eab42_level0_col4\" class=\"col_heading level0 col4\" >Source / formula</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_eab42_level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
       "      <td id=\"T_eab42_row0_col0\" class=\"data row0 col0\" >At</td>\n",
       "      <td id=\"T_eab42_row0_col1\" class=\"data row0 col1\" >Retirement of legacy systems with CX Cloud adoption</td>\n",
       "      <td id=\"T_eab42_row0_col2\" class=\"data row0 col2\" >5%</td>\n",
       "      <td id=\"T_eab42_row0_col3\" class=\"data row0 col3\" >$2,540,000</td>\n",
       "      <td id=\"T_eab42_row0_col4\" class=\"data row0 col4\" >PDF A1\u2013A4. Telephony $250k Y1 ramping to $500k (legacy sunset completes mid-Y1) + WFM/recording/transcription apps $100k + reduced dev effort $230k (2,400 hrs @ $94) + reduced platform mgmt $100k (1,500 hrs @ $65). Risk adj 5%.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_eab42_level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
       "      <td id=\"T_eab42_row1_col0\" class=\"data row1 col0\" >Bt</td>\n",
       "      <td id=\"T_eab42_row1_col1\" class=\"data row1 col1\" >Cost savings from reallocated workers and avoided seasonal hires with increased customer self-service</td>\n",
       "      <td id=\"T_eab42_row1_col2\" class=\"data row1 col2\" >15%</td>\n",
       "      <td id=\"T_eab42_row1_col3\" class=\"data row1 col3\" >$6,988,800</td>\n",
       "      <td id=\"T_eab42_row1_col4\" class=\"data row1 col4\" >PDF B1\u2013B8. Self-service completion 15%\u219225% on 80k weekly interactions \u2192 8,000 deflected/week \u2192 40 FTEs @ $58,240 fully burdened. Risk adj 15%. (PDF B7 formula cites B2 where the 12-min interaction length is meant; 40 FTEs is correct.)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_eab42_level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
       "      <td id=\"T_eab42_row2_col0\" class=\"data row2 col0\" >Ct</td>\n",
       "      <td id=\"T_eab42_row2_col1\" class=\"data row2 col1\" >CX agent efficiency gains</td>\n",
       "      <td id=\"T_eab42_row2_col2\" class=\"data row2 col2\" >10%</td>\n",
       "      <td id=\"T_eab42_row2_col3\" class=\"data row2 col3\" >$8,736,000</td>\n",
       "      <td id=\"T_eab42_row2_col4\" class=\"data row2 col4\" >PDF C1\u2013C6. MTTR 12\u219210 min on 60k agent-handled interactions per week \u2192 104,000 hrs/yr @ $28 fully burdened. Risk adj 10%.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_eab42_level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
       "      <td id=\"T_eab42_row3_col0\" class=\"data row3 col0\" >Dt</td>\n",
       "      <td id=\"T_eab42_row3_col1\" class=\"data row3 col1\" >Incremental sales from agent assist capabilities</td>\n",
       "      <td id=\"T_eab42_row3_col2\" class=\"data row3 col2\" >5%</td>\n",
       "      <td id=\"T_eab42_row3_col3\" class=\"data row3 col3\" >$1,800,000</td>\n",
       "      <td id=\"T_eab42_row3_col4\" class=\"data row3 col4\" >PDF D1\u2013D3. $500M revenue impacted (20% of $2.5B) \u00d7 1.5% lift \u00d7 8% gross margin. Risk adj 5%.</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x10609c290>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "notes_df = pd.DataFrame([\n",
    "    {\n",
    "        'Ref': ref,\n",
    "        'Benefit': b['label'],\n",
    "        'Risk Adj': f\"{b['risk_adjustment']:.0%}\",\n",
    "        '3-yr Nominal': sum(b['year_values'].values()),\n",
    "        'Source / formula': b['notes'],\n",
    "    }\n",
    "    for ref, b in zip(['At', 'Bt', 'Ct', 'Dt'], seed.BENEFITS)\n",
    "])\n",
    "notes_df.style.format({'3-yr Nominal': '${:,.0f}'}).set_properties(**{'text-align': 'left'})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-validation",
   "metadata": {},
   "source": [
    "## Local validation against the PDF\n",
    "\n",
    "Re-derive the per-benefit risk-adjusted PV (`value \u00d7 (1 \u2212 risk_adj)` per\n",
    "year, NPV at 10%) and confirm we land on Forrester's **\\$14,840,638**\n",
    "total within rounding."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "g1-code-validation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "</style>\n",
       "<table id=\"T_44a00\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th id=\"T_44a00_level0_col0\" class=\"col_heading level0 col0\" >Benefit</th>\n",
       "      <th id=\"T_44a00_level0_col1\" class=\"col_heading level0 col1\" >Y1 (RA)</th>\n",
       "      <th id=\"T_44a00_level0_col2\" class=\"col_heading level0 col2\" >Y2 (RA)</th>\n",
       "      <th id=\"T_44a00_level0_col3\" class=\"col_heading level0 col3\" >Y3 (RA)</th>\n",
       "      <th id=\"T_44a00_level0_col4\" class=\"col_heading level0 col4\" >PV</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_44a00_level0_row0\" class=\"row_heading level0 row0\" >0</th>\n",
       "      <td id=\"T_44a00_row0_col0\" class=\"data row0 col0\" >Retirement of legacy systems with CX Cloud adoption</td>\n",
       "      <td id=\"T_44a00_row0_col1\" class=\"data row0 col1\" >$646,000</td>\n",
       "      <td id=\"T_44a00_row0_col2\" class=\"data row0 col2\" >$883,500</td>\n",
       "      <td id=\"T_44a00_row0_col3\" class=\"data row0 col3\" >$883,500</td>\n",
       "      <td id=\"T_44a00_row0_col4\" class=\"data row0 col4\" >$1,981,225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_44a00_level0_row1\" class=\"row_heading level0 row1\" >1</th>\n",
       "      <td id=\"T_44a00_row1_col0\" class=\"data row1 col0\" >Cost savings from reallocated workers and avoided seasonal hires with increased customer self-service</td>\n",
       "      <td id=\"T_44a00_row1_col1\" class=\"data row1 col1\" >$1,980,160</td>\n",
       "      <td id=\"T_44a00_row1_col2\" class=\"data row1 col2\" >$1,980,160</td>\n",
       "      <td id=\"T_44a00_row1_col3\" class=\"data row1 col3\" >$1,980,160</td>\n",
       "      <td id=\"T_44a00_row1_col4\" class=\"data row1 col4\" >$4,924,365</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_44a00_level0_row2\" class=\"row_heading level0 row2\" >2</th>\n",
       "      <td id=\"T_44a00_row2_col0\" class=\"data row2 col0\" >CX agent efficiency gains</td>\n",
       "      <td id=\"T_44a00_row2_col1\" class=\"data row2 col1\" >$2,620,800</td>\n",
       "      <td id=\"T_44a00_row2_col2\" class=\"data row2 col2\" >$2,620,800</td>\n",
       "      <td id=\"T_44a00_row2_col3\" class=\"data row2 col3\" >$2,620,800</td>\n",
       "      <td id=\"T_44a00_row2_col4\" class=\"data row2 col4\" >$6,517,542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_44a00_level0_row3\" class=\"row_heading level0 row3\" >3</th>\n",
       "      <td id=\"T_44a00_row3_col0\" class=\"data row3 col0\" >Incremental sales from agent assist capabilities</td>\n",
       "      <td id=\"T_44a00_row3_col1\" class=\"data row3 col1\" >$570,000</td>\n",
       "      <td id=\"T_44a00_row3_col2\" class=\"data row3 col2\" >$570,000</td>\n",
       "      <td id=\"T_44a00_row3_col3\" class=\"data row3 col3\" >$570,000</td>\n",
       "      <td id=\"T_44a00_row3_col4\" class=\"data row3 col4\" >$1,417,506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_44a00_level0_row4\" class=\"row_heading level0 row4\" >4</th>\n",
       "      <td id=\"T_44a00_row4_col0\" class=\"data row4 col0\" >TOTAL</td>\n",
       "      <td id=\"T_44a00_row4_col1\" class=\"data row4 col1\" >$5,816,960</td>\n",
       "      <td id=\"T_44a00_row4_col2\" class=\"data row4 col2\" >$6,054,460</td>\n",
       "      <td id=\"T_44a00_row4_col3\" class=\"data row4 col3\" >$6,054,460</td>\n",
       "      <td id=\"T_44a00_row4_col4\" class=\"data row4 col4\" >$14,840,637</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x107c35610>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = []\n",
    "for b in seed.BENEFITS:\n",
    "    rf = b['risk_adjustment']\n",
    "    yr = [b['year_values'][str(y)] for y in (1, 2, 3)]\n",
    "    yr_ra = [risk_adjust_benefit(v, rf) for v in yr]\n",
    "    pv = npv(yr_ra, config.DISCOUNT_RATE)\n",
    "    rows.append({\n",
    "        'Benefit': b['label'],\n",
    "        'Y1 (RA)': yr_ra[0],\n",
    "        'Y2 (RA)': yr_ra[1],\n",
    "        'Y3 (RA)': yr_ra[2],\n",
    "        'PV': pv,\n",
    "    })\n",
    "df_check = pd.DataFrame(rows)\n",
    "df_check.loc[len(df_check)] = ['TOTAL', df_check['Y1 (RA)'].sum(), df_check['Y2 (RA)'].sum(), df_check['Y3 (RA)'].sum(), df_check['PV'].sum()]\n",
    "df_check.style.format({c: '${:,.0f}' for c in df_check.columns if c != 'Benefit'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "g1-code-pv-check",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"padding:10px 14px;border-left:4px solid #2e7d32;background:#e8f5e9;color:#1a1a1a;border-radius:4px;margin:6px 0;\">Computed Benefits PV: <b>$14,840,637</b><br>Forrester target:     <b>$14,840,638</b><br>\u0394 = $-1 (rounding)</div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "expected_pv = seed.PUBLISHED['total_benefits_pv']   # 14,840,638\n",
    "computed_pv = df_check.iloc[-1]['PV']\n",
    "delta = computed_pv - expected_pv\n",
    "kind = 'success' if abs(delta) < 100 else 'warning'\n",
    "display.alert(\n",
    "    f'Computed Benefits PV: <b>${computed_pv:,.0f}</b><br>'\n",
    "    f'Forrester target:     <b>${expected_pv:,.0f}</b><br>'\n",
    "    f'\u0394 = ${delta:,.0f} (rounding)',\n",
    "    kind,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-visualize",
   "metadata": {},
   "source": [
    "## Visualize\n",
    "\n",
    "Horizontal bar chart of risk-adjusted three-year totals \u2014 mirrors the\n",
    "*Benefits (Three-Year)* exhibit on PDF p.6 of the published study."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "g1-code-bar",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "marker": {
          "color": "#2E7D32"
         },
         "orientation": "h",
         "text": [
          "$2.4M",
          "$5.9M",
          "$7.9M",
          "$1.7M"
         ],
         "textposition": "auto",
         "type": "bar",
         "x": [
          2413000,
          5940480,
          7862400,
          1710000
         ],
         "y": [
          "Retirement of legacy systems with CX Cloud adoption",
          "Cost savings from reallocated workers and avoided seasonal hires with increased customer self-service",
          "CX agent efficiency gains",
          "Incremental sales from agent assist capabilities"
         ]
        }
       ],
       "layout": {
        "font": {
         "color": "#1F2937",
         "family": "Helvetica, Arial, sans-serif"
        },
        "legend": {
         "font": {
          "color": "#1F2937",
          "family": "Helvetica, Arial, sans-serif"
         }
        },
        "margin": {
         "b": 40,
         "l": 40,
         "r": 20,
         "t": 60
        },
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermap": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermap"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "#E5ECF6",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "#E5ECF6",
          "polar": {
           "angularaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "radialaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "yaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "zaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "caxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          }
         }
        },
        "title": {
         "font": {
          "color": "#1F2937",
          "family": "Helvetica Neue, Arial, sans-serif"
         },
         "text": "Benefits (Three-Year)"
        },
        "xaxis": {
         "tickformat": "$,.0f"
        },
        "yaxis": {
         "autorange": "reversed"
        }
       }
      },
      "image/png": "[encoded data, 54552 characters]"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "charts.benefits_bar(seed.BENEFITS).show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-where-tokens",
   "metadata": {},
   "source": [
    "### Heads-up: three of these benefits depend on AI consumption\n",
    "\n",
    "Benefits **Bt** (self-service uplift), **Ct** (AI coaching / agent\n",
    "efficiency) and **Dt** (agent-assist sales) are all delivered through\n",
    "Genesys AI capabilities that are **billed via AI Experience tokens**.\n",
    "The published study modelled \\$0 of token consumption \u2014 costs notebook\n",
    "(`02_costs.ipynb`) adds the line back, and `03_business_case.ipynb`\n",
    "exposes a sensitivity sweep so you can see what the AI cost does to NPV."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-push",
   "metadata": {},
   "source": [
    "## Push to Athena (optional)\n",
    "\n",
    "When `config.TOOL_PUBLIC_ID` is set (filled in by `00_provision.ipynb`),\n",
    "persist the seed values to the live TEI tool. Otherwise this cell is a\n",
    "no-op so the notebook still runs offline."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "g1-code-push",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"padding:10px 14px;border-left:4px solid #0277bd;background:#e1f5fe;color:#1a1a1a;border-radius:4px;margin:6px 0;\">No PALLADIUM_GENESYSCX_TOOL_PUBLIC_ID set \u2014 skipped Athena push. Run <code>00_provision.ipynb</code> to provision the tool.</div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "if config.TOOL_PUBLIC_ID:\n",
    "    from core.tei_client import TEIClient\n",
    "\n",
    "    client = TEIClient()\n",
    "    client.update_values(config.TOOL_PUBLIC_ID, seed.BENEFITS)\n",
    "    display.alert(f'Pushed {len(seed.BENEFITS)} benefit rows to '\n",
    "                  f'tool <code>{config.TOOL_PUBLIC_ID}</code>.', 'success')\n",
    "else:\n",
    "    display.alert(\n",
    "        'No PALLADIUM_GENESYSCX_TOOL_PUBLIC_ID set \u2014 skipped Athena push. '\n",
    "        'Run <code>00_provision.ipynb</code> to provision the tool.',\n",
    "        'info',\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "g1-md-next",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "Continue with [`02_costs.ipynb`](02_costs.ipynb) \u2192"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
