fix(pizzint): score the Pentagon Pizza Index on deviation from normal, not absolute busyness, and credit it to World Monitor

Author: koala73Created Sep 27, 2026Updated Sep 27, 2026

Problem

The Pentagon Pizza Index showed DEFCON 2, "FAST PACE - ARMED FORCES READY" on an ordinary Sunday afternoon (2026-09-27, 14:38 EDT). The index is meant to flag unusual late or off-hours activity near the Pentagon. Instead it scores absolute busyness, so any busy mealtime pushes DEFCON up.

Evidence (production, 2026-09-27 18:38Z, BestTime fallback)

Venue Live Forecast for this hour % of usual Panel shows
Extreme Pizza 70 45 156% SPIKE 70%
District Pizza Palace 0 40 0% QUIET 0%
Nighthawk Brewery & Pizza 65 35 186% SPIKE 65%
Pizzato Pizza 100 100 100% HIGH 100%

DEFCON = mean live busyness of open venues (58.75) + 10 per spike (2 × 10) = 78.75, which is ≥ 70 → DEFCON 2.

What is wrong, with locations

  1. DEFCON uses absolute busyness, not deviation from normal. scripts/ais-relay.cjs in seedPizzint (grep const avgPop):
    • avgPop is the mean of currentPopularity over open venues, and adjusted = avgPop + 10 × activeSpikes.
    • The fixed thresholds are 85 / 70 / 50 / 25.
    • A venue that is exactly as busy as usual (Pizzato: 100 vs forecast 100) pushes DEFCON up as much as a real anomaly would.
    • percentageOfUsual is computed and published but never used.
    • This flaw predates BestTime. The same formula runs on PizzINT's own data, and it ignores the defcon_level / overall_index PizzINT returns.
  2. Spikes come from a single reading. pizzintLocationFromBestTime flags isSpike when live − forecast ≥ 25 points (PIZZINT_BESTTIME_SPIKE_DELTA) on one 10-minute reading.
    • A busy lunch easily clears this: Extreme Pizza +25, Nighthawk +30.
    • Nothing requires the deviation to persist.
    • Nothing weights the time of day. The index's premise is surges when venues are normally quiet (late night, weekends); a lunch rush is expected.
  3. Panel labels read absolute busyness as alarm levels. src/components/PizzIntIndicator.ts (getStatusClass / getStatusLabel):
    • The levels are HIGH at current_popularity ≥ 70, ELEVATED at ≥ 40 and NOMINAL at ≥ 15.
    • So Pizzato at exactly its usual level shows HIGH 100%.
    • SPIKE 70% shows live busyness as a percentage, which reads as "70% above normal". Extreme Pizza is actually at 156% of usual.
  4. The footer credits BestTime as the source (PizzIntIndicator.ts, the .pizzint-source a update added in 8d18ea812). The index, the spike rule and the DEFCON mapping are World Monitor's algorithm; BestTime and PizzINT only supply venue busyness.
  5. "Live 0 while open" is not handled. District Pizza Palace reports venue_open: Open, live 0, forecast 40. That is more likely a missing live signal than an empty restaurant. Today it counts as an open venue at 0 and pulls the average down.

Desired behavior

One documented index, the same for both data sources (PizzINT when it is up, BestTime otherwise), that measures deviation from each venue's normal for that hour:

  • Per-venue anomaly: use the ratio and the difference against that hour's forecast / usual, e.g. percentageOfUsual plus a minimum point delta, so a quiet venue going from 5 to 10 does not count as 200%.
    • A venue at or below its forecast contributes nothing, however busy it is.
  • Persistence: a venue counts as spiking only after its anomaly holds for ≥ 2 consecutive readings (≥ 20 min). This needs the previous observation, which the relay already has in intelligence:pizzint:seed:v1.
  • DEFCON from anomalies, not busyness: base it on how many venues are anomalous and by how much.
    • A normal mealtime (every venue near its forecast) must read DEFCON 5.
    • Several venues well above their forecast together, sustained, raises it.
    • Document the exact mapping in code and in docs/ (or the panel's methodology page, if one exists).
  • Unknown live signal: a venue reporting open, live 0 and forecast ≥ 20 is "no live signal". It is excluded from the open count and the averages, and the panel shows it as NO DATA, not QUIET 0%.
  • Panel labels: show deviation, e.g. SPIKE +56% / 156% of usual, and NORMAL near the forecast. Do not show absolute busyness as HIGH or ELEVATED.
  • Attribution: show the footer as the World Monitor index with the data provider named, e.g. Index: World Monitor · venue data: BestTime (or PizzINT). Localize the new strings in src/locales/*.json, following the existing components.pizzint.* keys.

Decide in the PR, with the reasoning written down, whether to keep using PizzINT's own defcon_level when PizzINT is up. The recommendation is no: one algorithm for both sources, so the level does not jump when the source switches.

Acceptance criteria

The relay tests live in tests/pizzint-seed-publication.test.mjs, which already has a harness() with a fake clock, fake BestTime replies and a PizzINT source. Add these cases:

  • Normal Sunday lunch: the four readings above, but every venue within ±10 of its forecast, publish DEFCON 5, with no spikes.
  • The 2026-09-27 readings in the table: publish no higher than DEFCON 4 on the first reading (no persistence yet). If the two above-forecast venues hold for a second consecutive reading, the documented rule sets the level; state the resulting level in the test name.
  • Late-night surge: three venues at ≥ 2× forecast, each by ≥ 25 points, for two consecutive readings, publish DEFCON ≤ 3.
  • Single-reading blip: one venue +40 on one reading, then back to forecast, never raises DEFCON.
  • Open with live 0: a venue with venue_open: Open, live 0 and forecast 40 is excluded from the open count and the averages, and is marked as no live signal.
  • Same rule for PizzINT: PizzINT-shaped input (percentage_of_usual, current_popularity) goes through the same anomaly rule and yields the same DEFCON for equivalent readings.
  • Existing guarantees hold: no live reading publishes nothing, and credentials never appear in logs or payload.

Panel tests (tests/dom/pizzint-source.test.mts, run with npx vitest run --config vitest.dom.config.mts):

  • A venue exactly at its usual level shows NORMAL, not HIGH.
  • A spiking venue shows its deviation, not its absolute busyness.
  • The footer names World Monitor as the index and BestTime or PizzINT as the data provider, matching the payload's data source.

Plus:

  • The algorithm is documented next to the code and in user-facing docs.
  • npm run typecheck, npm run lint:boundaries and node --test tests/*relay*.test.mjs tests/pizzint*.test.mjs pass.
  • The PR includes screenshots of the panel for a normal-hours state and a spike state (AGENTS.md UI-evidence rule). Use test data and label the tested commit.

Verification after deploy

  • railway logs --service ais-relay | grep PizzINT during a weekday lunch shows DEFCON 5 or 4, not 2.
  • The intelligence:pizzint:seed:v1 payload carries the new per-venue fields, and /api/health pizzint stays OK.

Context

  • Producer: scripts/ais-relay.cjs (seedPizzint, pizzintLocationFromBestTime, fetchPizzintBestTimeLocations) on the Railway service ais-relay, every 10 min. It writes intelligence:pizzint:seed:v1 (TTL 30 min) and seed-meta:intelligence:pizzint.
  • Reader: server/worldmonitor/intelligence/v1/get-pizzint-status.ts, then src/services/pizzint.ts and src/components/PizzIntIndicator.ts. The proto is proto/worldmonitor/intelligence/v1/intelligence.proto. Adding fields means make generate; never hand-edit src/generated/.
  • Background:
    • PizzINT's own backend has been down since 2026-09-25.
    • #8671 added the BestTime live-busyness fallback for the 4 Pentagon-area venues BestTime can forecast. Domino's and Papa Johns are too low-volume.
    • #8674 logs rejected BestTime requests.
    • BestTime live data exists only during opening hours; overnight the fallback correctly publishes nothing.

Out of scope

  • The geopolitical tension pairs; see #8676.
  • Adding venues. BestTime refused Domino's and Papa Johns.