spotlight_application / index.html
shashankadari's picture
Upload 7 files
32cddc6 verified
Raw History Blame Contribute Delete
22.4 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Spotlight PQGC Field Guide</title>
<meta name="description" content="How the Spotlight PQGC Databricks pipeline works end to end, in plain English: from SAP S/4 to the Spotlight app and back.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@600;700;800&family=IBM+Plex+Mono:wght@400;500;600&family=Public+Sans:ital,wght@0,400;0,600;0,700;1,400&display=swap">
<link rel="stylesheet" href="css/site.css">
</head>
<body>
<header class="topbar">
<div class="wrap">
<a class="brand" href="#top">Spotlight <span>PQGC</span></a>
<nav class="nav" aria-label="Sections">
<a href="#summary">Overview</a>
<a href="#flow">The loop</a>
<a href="#story">One order</a>
<a href="#runs">Run order</a>
<a href="#inventory">Notebooks</a>
<a href="#lineage">Data map</a>
<a href="#glossary">Glossary</a>
<a href="#findings">To fix</a>
<a href="3d.html" class="nav-3d">3D floor</a>
</nav>
</div>
</header>
<div class="hazard" aria-hidden="true"></div>
<main>
<!-- Hero -->
<section class="hero" id="top">
<div class="wrap">
<p class="eyebrow">PepsiCo North America · Databricks pipeline · Order fulfilment</p>
<h1>Spotlight PQGC, <mark>in plain English</mark></h1>
<p class="lede">This code keeps the Spotlight app current. On each run it copies the latest orders, deliveries, trucks, production plans and stock levels out of SAP. It works out which customer orders are at risk of shipping short and loads the answers into the database behind the app. When planners act on a risk in Spotlight, their changes go back to SAP.</p>
<div class="route" aria-label="Data route">
<span class="hop sap">SAP S/4</span><span class="arrow">→</span>
<span class="hop">Databricks lakehouse</span><span class="arrow">→</span>
<span class="hop">Azure SQL database</span><span class="arrow">→</span>
<span class="hop">Spotlight app</span><span class="arrow">→</span>
<span class="hop sap">back to SAP</span>
</div>
<div class="facts">
<span><b data-fact="notebooks">27</b>notebooks</span>
<span><b data-fact="lines">12,462</b>lines of code</span>
<span><b data-fact="sap">26</b>SAP sources</span>
<span><b data-fact="lake">59</b>Databricks tables</span>
<span><b data-fact="sql">21</b>app tables, procedures &amp; files</span>
</div>
</div>
</section>
<!-- One-minute version -->
<section id="summary">
<div class="wrap split">
<div class="prose">
<p class="eyebrow">The one-minute version</p>
<h2>What problem does it solve?</h2>
<p>Picture a beverage and food business with dozens of plants. Customers place orders, trucks move product between plants, and factories make more. Every day someone has to answer one question: <b>will each order ship complete and on time, and if not, which ones need attention first?</b></p>
<p>SAP holds all the raw facts, spread across dozens of tables. This project gathers them, joins them up, and turns them into simple answers for every order: a <b>fill rate</b>, a <b>dollar amount at risk</b>, a <b>confidence score</b> and a <b>traffic light</b>.</p>
<p>It runs as a chain of Databricks notebooks. Each notebook does one job and hands a table to the next. The final tables are copied into an Azure SQL database, which is what the Spotlight app reads. Planners act in the app, and a writeback step sends their changes to SAP, so the next run starts from the updated picture.</p>
<p class="muted">Nothing here has a screen of its own. The Spotlight app's front end, the job schedule and the SQL stored procedures are not in this folder. This guide covers the data engine that feeds them.</p>
</div>
<aside class="analogy" aria-label="Warehouse analogy">
<h3>In warehouse terms</h3>
<dl>
<dt>SAP S/4</dt><dd>The master ledger where every order, truck and pallet is recorded.</dd>
<dt>Extract notebooks</dt><dd>Clerks who copy only the pages that changed since the last shift.</dd>
<dt>Order-delivery detail</dt><dd>The tracking board: order → delivery → truck, on one line.</dd>
<dt>Coverage score</dt><dd>The stock forecaster: can this plant cover each of the next 14 days?</dd>
<dt>Traffic lights</dt><dd>The dispatcher's priority list.</dd>
<dt>Spotlight app</dt><dd>The control-tower screen planners work from.</dd>
<dt>Writeback</dt><dd>The dispatcher's instructions, sent back into the ledger.</dd>
</dl>
</aside>
</div>
</section>
<!-- The loop -->
<section id="flow">
<div class="wrap">
<p class="eyebrow">End to end · 8 stages</p>
<h2>The loop, stage by stage</h2>
<p class="prose">Each run moves left to right through these stages. Select a stage to see what it does and which notebooks do the work.</p>
<ol class="track" id="track"></ol>
<div class="loopback" aria-label="The loop closes">
<svg width="28" height="20" viewBox="0 0 28 20" aria-hidden="true"><path d="M26 4 H8 a6 6 0 0 0 0 12 h4" fill="none" stroke="var(--flow)" stroke-width="2"/><path d="M12 12 l4 4 -4 4" fill="none" stroke="var(--flow)" stroke-width="2" transform="translate(0,-4)"/></svg>
<span>Stage 08 feeds SAP, and SAP feeds stage 02 on the next run</span>
<span class="line" aria-hidden="true"></span>
</div>
<div class="stage-detail" id="stage-detail" aria-live="polite"></div>
<p class="cta3d"><a href="3d.html">Walk the loop in 3D</a><span>A three.js model of the whole process, with a guided tour.</span></p>
</div>
</section>
<!-- Follow one order -->
<section id="story">
<div class="wrap">
<p class="eyebrow">A worked example</p>
<h2>Follow one order through the system</h2>
<p class="prose"><span class="example-note">Illustrative example</span> The order, plant and figures below are invented to show the mechanics. The rules applied at each step are the real ones from the code.</p>
<ol class="story">
<li>
<span class="t">SAP</span>
<div>
<h4>A customer orders 600 cases</h4>
<p>A retailer's distribution centre orders 600 cases of a sports drink, shipping from plant 8123 on Thursday. SAP records sales order 0012345678 and confirms it can promise 540 of those cases.</p>
<p class="tag">Order type ZOR · ordered 600 cs · ATP 540 cs</p>
</div>
</li>
<li>
<span class="t">02</span>
<div>
<h4>The next run picks up the change</h4>
<p>The order-line extract sees the order changed after its last watermark and copies the line: 600 cases ordered (10 pallets of 60), 540 promised, 60 at risk. Once the warehouse creates a delivery and a truck is booked, the delivery and shipment extracts copy those too.</p>
<p class="tag">pgt_whd_ordr_item_extrct_tbl → pgt_whd_dlvry_extrct_tbl → pgt_whd_shpmt_extrct_tbl</p>
</div>
</li>
<li>
<span class="t">03</span>
<div>
<h4>It becomes one row with a status</h4>
<p>The order-delivery detail joins the line to its delivery, truck, carrier and customer hierarchy. A delivery exists and there is no block, so the status is RLSD (released). Until the truck actually leaves, the ship date is the planned goods-issue date.</p>
<p class="tag">ord_dely_detl_pgt · sap_stts = RLSD</p>
</div>
</li>
<li>
<span class="t">04</span>
<div>
<h4>The plant's coverage is scored</h4>
<p>Plant 8123 has 300 cases free and 100 on quality hold, which count as 75. Another 120 cases are on a truck from a sister plant (trusted at 80%) and 200 are planned for production (trusted at 50%). Measured against everything due out on Thursday, the plant scores 85% for that day.</p>
<p class="tag">plant_matnr_fcs_dly · FCS_PCT for Thursday = 85</p>
</div>
</li>
<li>
<span class="t">05</span>
<div>
<h4>The order gets its numbers and a light</h4>
<p>Fill rate is 90% (540 ÷ 600). Revenue at risk is $1,080 (60 cases × $18). Confidence is 85, taken from the plant's Thursday score. The order is short, so it can't be green or yellow. The plant's "max cut &amp; ship" setting decides between orange and red.</p>
<p class="tag">fact_order_pqgc → PQGC_SPOTLIGHT.FACT_ORDER_PQGC_DLT → FO_DLT_MRGE()</p>
</div>
</li>
<li>
<span class="t">07</span>
<div>
<h4>It shows up in Spotlight</h4>
<p>Stored procedures merge the changed orders into the app's tables, and the "Last Spotlight Refresh" clock moves forward. A planner filtering for orange and red orders now sees this one.</p>
<p class="tag">PQGC_SPOTLIGHT.Timestamp</p>
</div>
</li>
<li>
<span class="t">08</span>
<div>
<h4>A planner acts and SAP receives the change</h4>
<p>The planner's change goes into the app's writeback queue. The writeback notebook turns the queue into a CSV file for SAP S/4. Once SAP applies it, the fast-refresh notebook pushes the updated order back to the app, and the next full run starts the loop again.</p>
<p class="tag">PQGC_SPOTLIGHT.Writeback → SL_S4_Writeback_&lt;time&gt;.csv → SAP S/4</p>
</div>
</li>
</ol>
</div>
</section>
<!-- Run order -->
<section id="runs">
<div class="wrap">
<p class="eyebrow">Sequence</p>
<h2>How a run unfolds</h2>
<p class="prose">The job definition (Databricks Workflow) isn't in this folder. This order is worked out from what each notebook reads and writes, so a notebook always runs after the ones that feed it. Steps 04–06 can run in parallel.</p>
<div class="runs">
<div class="runbook">
<h3>Main refresh · process "PQGC_INCREMENTAL"</h3>
<ol>
<li><div><b>Note SAP data freshness</b><span>Timer-stamp notebook in start mode records the SAP data-pull time. <code>update timer stamp ASQL</code></span></div></li>
<li><div><b>Check sources, alert if stale</b><span><code>PQGC_BASE_TABLE_VALIDATION_CEN</code>, <code>_DF</code>, <code>PQGC_BASE_TABLE_VALIDATION</code></span></div></li>
<li><div><b>Tidy the big tables (pre)</b><span>At most every 6 hours. <code>Optimize drvd tables</code> stage=pre</span></div></li>
<li><div><b>Extract order lines, deliveries, purchase &amp; transfer orders</b><span><code>PGT_WHD_ORDR_ITEM…</code>, <code>PGT_WHD_DLVRY…</code>, <code>PGT_WHD_PO…</code></span></div></li>
<li><div><b>Extract truck shipments, merge the change lists</b><span>Needs step 04. <code>PGT_WHD_SHPMT…</code></span></div></li>
<li><div><b>Refresh production and stock on hand</b><span><code>PGT_WHD_PROD_ORDR…</code>, <code>PGT_WHD_PROD_PROCESS_ORDR…</code>, <code>MATDOC_INCREMENTAL</code></span></div></li>
<li><div><b>Stitch order-delivery detail</b><span>Passes its timestamp to later tasks. <code>Ord_dely_detl_pgt_cur</code></span></div></li>
<li><div><b>Score plant coverage for 14 days</b><span>Sends results to the app database. <code>plant_matnr_fcs_dly</code></span></div></li>
<li><div><b>Rate orders and order lines</b><span>Sends results to the app database and runs its merge procedures. <code>PQGC_FO_CUR</code>, <code>PQGC_FOL_CUR</code></span></div></li>
<li><div><b>Build the supply list</b><span><code>plnt_mtrl_scs_rptng</code></span></div></li>
<li><div><b>Score transfers with ML</b><span><code>PQGC_ML_SIT_Predictions</code>, <code>PQGC_ML_SOO_SPL_Predictions</code></span></div></li>
<li><div><b>Run the app's stored procedures</b><span><code>EXEC_SP_ASQL</code> with the job's <code>sp_list</code></span></div></li>
<li><div><b>Mark "Last Spotlight Refresh"</b><span><code>update timer stamp ASQL</code> process=Full</span></div></li>
<li><div><b>Tidy the big tables (post)</b><span><code>Optimize drvd tables</code> stage=post</span></div></li>
</ol>
</div>
<div class="runbook">
<h3>Writeback · process "Writeback"</h3>
<ol>
<li><div><b>Export planners' changes for SAP</b><span><code>SAPWritebackStatus</code> type=ATP or BEAM</span></div></li>
<li><div><b>Mark "Last SAP Writeback"</b><span><code>update timer stamp ASQL</code> process=Writeback</span></div></li>
</ol>
<h3 style="margin-top:1.5rem">Between full runs</h3>
<ol>
<li><div><b>Fast order refresh</b><span>Pushes SAP's latest order status straight to the app. <code>UPDATE_FO</code></span></div></li>
</ol>
<h3 style="margin-top:1.5rem">When something fails</h3>
<p style="font-size:.92rem">Most notebooks send a failure alert through an email web service, naming the notebook, environment and error. Alerts go to a single contractor address. The shipment extract, ML notebooks and fast refresh send no alert.</p>
</div>
</div>
</div>
</section>
<!-- Inventory -->
<section id="inventory">
<div class="wrap">
<p class="eyebrow">Inventory</p>
<h2>Every notebook, explained</h2>
<p class="prose">All 27 files in the project. Open one to see what it does step by step and which tables it reads and writes. Search finds table names too.</p>
<div class="controls">
<input type="search" id="inv-search" placeholder="Search notebooks or tables, e.g. fact_order_pqgc" aria-label="Search notebooks or tables">
<span class="count" id="inv-count" aria-live="polite"></span>
</div>
<div class="filters" id="inv-filters" role="group" aria-label="Filter by stage" style="margin-bottom:1rem"></div>
<div class="inv" id="inv"></div>
</div>
</section>
<!-- Lineage -->
<section id="lineage">
<div class="wrap">
<p class="eyebrow">Data map</p>
<h2>Where the data lives</h2>
<p class="prose">Data starts in SAP (left), is shaped in Databricks (middle), and ends up in the app's database (right). Pick a notebook to highlight what it reads and what it writes.</p>
<div class="lin-controls">
<label for="lin-select">Highlight notebook</label>
<select id="lin-select"></select>
<div class="legend"><span><i class="r"></i>reads</span><span><i class="w"></i>writes or runs</span></div>
</div>
<div class="board" id="board">
<div class="col" data-col="sap">
<h3>SAP sources</h3>
<p class="sub">SAP foundation views in <code>uc_&lt;env&gt;_snt_fdn_01</code>. Read-only.</p>
<div class="groups"></div>
</div>
<div class="col" data-col="lake">
<h3>Databricks tables</h3>
<p class="sub">Delta tables in schema <code>pbus_spotlight</code>, plus ML model files.</p>
<div class="groups"></div>
</div>
<div class="col" data-col="sql">
<h3>Spotlight app side</h3>
<p class="sub">Azure SQL schema <code>PQGC_SPOTLIGHT</code>, plus the writeback file for SAP.</p>
<div class="groups"></div>
</div>
</div>
</div>
</section>
<!-- Glossary -->
<section id="glossary">
<div class="wrap">
<p class="eyebrow">Glossary</p>
<h2>Words you'll see</h2>
<p class="prose">Codes and abbreviations from the notebooks. Entries marked "inferred from the code" are not spelled out anywhere in the code; they are a best reading from how each term is used.</p>
<dl class="gloss" id="gloss"></dl>
</div>
</section>
<!-- Findings -->
<section id="findings">
<div class="wrap">
<p class="eyebrow">Review notes</p>
<h2>Things to fix</h2>
<p class="prose">Problems found while reading the code. Each one was checked against the line shown.</p>
<div class="findings">
<div class="finding">
<span class="sev crit">Urgent</span>
<div>
<h4>The app database password is written in plain text</h4>
<p>The Azure SQL server, username and password are typed directly into the code. The lines that would read them from the secret store are commented out. One notebook also prints the full connection options, password included, into the job log on every run. Anyone with read access to the repo or the job logs has the login. Rotate the password and move the login into a Databricks secret scope.</p>
<p class="where">Common/ENV_VARIABLES.py:29–32 · writeback/PBNA_COMMON_PROCESS.py:205–208 · plant_matnr_fcs_dly.py:2421 · Common/Email.py (alert URL carries an access signature)</p>
</div>
</div>
<div class="finding">
<span class="sev crit">Urgent</span>
<div>
<h4>Failed runs are never recorded in the app's clock</h4>
<p>The SQL that marks a run as failed has a stray comma before <code>WHERE</code>, so it errors every time. When a refresh or writeback fails, the "last run" status planners see never shows the failure.</p>
<p class="where">writeback/update timer stamp ASQL.py:74</p>
</div>
</div>
<div class="finding">
<span class="sev warn">Fix soon</span>
<div>
<h4>Order-level revenue at risk uses the wrong formula</h4>
<p>It computes <code>ORD_QTY - ATP_QTY * NET_PRICE</code>, but should compute <code>(ORD_QTY - ATP_QTY) * NET_PRICE</code>. The line-level figure is correct; the order-level figure is not.</p>
<p class="where">PQGC_FO_CUR.py:556–558</p>
</div>
</div>
<div class="finding">
<span class="sev warn">Fix soon</span>
<div>
<h4>Coverage maths counts Day 8 supply twice</h4>
<p>The running supply total for Day 9 adds Day 8 twice, which makes the plant look better supplied from Day 9 onward.</p>
<p class="where">plant_matnr_fcs_dly.py:598</p>
</div>
</div>
<div class="finding">
<span class="sev warn">Fix soon</span>
<div>
<h4>Production-order supply comes from a table nothing fills</h4>
<p>The coverage score reads production-order (PPO) quantities from <code>plnt_mtrl_sply_typ_scs_cc</code>, which no notebook in this folder writes. PPO supply is probably empty or stale.</p>
<p class="where">plant_matnr_fcs_dly.py:607</p>
</div>
</div>
<div class="finding">
<span class="sev warn">Fix soon</span>
<div>
<h4>The purchase/transfer extract never moves its watermark forward</h4>
<p>Each run carries the old watermark forward but never sets a new one. Every run therefore reprocesses everything changed since 1 Jan 2025, and the runs get slower over time.</p>
<p class="where">PGT_WHD_PO_EXTRCT_TBL_SPLTGHT.py:88–111, 343–355</p>
</div>
</div>
<div class="finding">
<span class="sev warn">Fix soon</span>
<div>
<h4>A run-control update has no WHERE clause</h4>
<p>The order-delivery notebook overwrites the "last processed" time on every row of its run table, not just its own.</p>
<p class="where">Ord_dely_detl_pgt_cur.py:1018–1023</p>
</div>
</div>
<div class="finding">
<span class="sev warn">Fix soon</span>
<div>
<h4>Plant tolerance lookup ignores the plant</h4>
<p>The join that picks a plant's "max cut &amp; ship" threshold compares a column with itself (<code>cf.featid=cf.featid</code>), which is always true. Every location gets the same threshold, which can change orange and red lights.</p>
<p class="where">PQGC_FO_CUR.py:822</p>
</div>
</div>
<div class="finding">
<span class="sev ok">Tidy up</span>
<div>
<h4>Gaps in failure alerts</h4>
<p>The shipment extract has no error handling at all. The order-header alert is commented out. The writeback notebook's alert says "MATDOC_INCREMENTAL FAILED", and the process-order alert names the wrong notebook. All alerts go to one contractor's address.</p>
<p class="where">PGT_WHD_SHPMT_EXTRCT_TBL_SPLTGHT.py · PQGC_FO_CUR.py:1072 · writeback/SAPWritebackStatus.py:145 · Common/Email.py</p>
</div>
</div>
<div class="finding">
<span class="sev ok">Tidy up</span>
<div>
<h4>ML predictions are produced but never used</h4>
<p>The two ML notebooks write <code>mlpqgcsit</code> and <code>mlpqgcsoospl</code>, but nothing in this folder reads them. Confidence scores still use the fixed 80 / 60 / 50 / 40 weights.</p>
<p class="where">ML/PQGC_ML_SIT_Predictions.py:328 · ML/PQGC_ML_SOO_SPL_Predictions.py:227</p>
</div>
</div>
<div class="finding">
<span class="sev ok">Tidy up</span>
<div>
<h4>Notebooks depend on one person's workspace folder</h4>
<p>Shared files are loaded with <code>%run</code> from a contractor's personal workspace path. If that account is removed, every notebook breaks. Use repo-relative paths.</p>
<p class="where">Most notebooks, first cells</p>
</div>
</div>
</div>
</div>
</section>
</main>
<footer>
<div class="wrap">Built from the 27 notebooks in <code>Spotlight-PQGC/</code>. Credentials are deliberately left out of this guide. Notebook data lives in <code>js/data.js</code>.</div>
</footer>
<script src="js/data.js"></script>
<script src="js/app.js"></script>
</body>
</html>