A jobsite safety platform for utility field crews, built in about 30 hours at SwampHacks XII for the PlanIT Control challenge.
Utility crews get hurt by hazards that were knowable the night before: lightning, extreme heat, flooding, soft soil. The data exists, but it lives in a dozen places and nobody turns it into a decision. OmniRisk closes that gap, from tomorrow's forecast all the way to the equipment switch.
- Live dashboard: https://omnirisking-it-all-at-swamphacks.us
- API: https://api.omnirisking-it-all-at-swamphacks.us (
/docslists every route;contracts/api.mdis the source of truth)
- One risk picture per site. The dashboard watches 50 real power plant sites across Florida and the Gulf states (25 in Florida, plus Texas, Alabama, Georgia, Louisiana and Mississippi), merging weather, heat, rain, soil moisture, river, FEMA flood zone, lightning, wind and wildlife data, ranked by a 0 to 10 machine learning hazard index with the three reasons behind it.
- Stop work rules. A lightning strike within 10 miles opens a 30 minute stop work countdown that restarts on every new strike, and only a supervisor PIN ends it. Heat index alerts fire at 103 °F (warning) and 115 °F (danger, with a 15 minute rest break sent to the beacon), river sites get flood warnings after heavy rain, standing water confirms a flood, and gusts raise wind alerts at 28 mph (aerial lifts down) and 40 mph (the job stops).
- 6 PM briefings. Every evening at 6 PM in each site's local time, each site gets a next day briefing in English and Spanish, and a supervisor can run it on demand.
- Crew phone page. Crew check in and out, see the hazards that matter for their safety with what to do, and photograph hazards: AI tags the photo and pins it to the site map by distance and direction.
- A physical beacon on site. A Raspberry Pi 5, an RP2040 sensor pod and an Arduino UNO. It sees a lightning flash with its own photoresistor, cuts the equipment motor, runs the countdown, speaks the alert, shows the hazard index on a 29 LED gauge, and keeps enforcing its rules with no internet. A supervisor PIN on the IR remote restores power.
- A Roblox digital twin. A physically simulated storm walks in toward the site. Every strike inside 10 miles reaches the real beacon, the in world beacon mirrors the real one, and a player who walks into the work zone appears on the muster list.
Four pieces talk through written contracts in contracts/ (event shapes, serial lines, websocket messages, REST routes), which let four people build in parallel.
flowchart LR
subgraph Feeds["Public data"]
OM["Open-Meteo forecast and flood API"]
NWS["NWS alerts"]
INAT["iNaturalist"]
FEMA["FEMA flood zones"]
end
subgraph Cloud["Vultr: Docker and Caddy"]
API["FastAPI backend<br/>rules engine and scheduler"]
ML["LightGBM hazard index<br/>and SHAP reasons"]
GEM["Gemini<br/>briefings and photo tags"]
end
DB[("Tiger Data<br/>TimescaleDB")]
WEB["React web app<br/>Dashboard, Hub, Crew phone"]
PI["Raspberry Pi 5 gateway"]
POD["RP2040 sensor pod"]
UNO["Arduino UNO beacon head"]
FAN["Fan motor via L293D"]
RBX["Roblox site twin<br/>World and Bridge"]
Feeds --> API
API <--> DB
API --> ML
API --> GEM
API <-->|REST and websocket| WEB
API <-->|websocket| PI
RBX -->|HTTPS /sim/*| API
POD -->|USB serial| PI
PI -->|USB serial| UNO
PI -->|GPIO 18| FAN
FastAPI with asyncpg on Tiger Data (TimescaleDB hypertables for conditions and events). APScheduler runs the feeds (Open-Meteo forecast and NWS alerts every 15 minutes, the Open-Meteo river flood API hourly, iNaturalist every 6 hours), scores the hazard index daily at 05:00 UTC, and runs each site's briefing at 18:00 in its own time zone. Auth0 JWTs carry a supervisor role claim for releases. Websockets connect the dashboard (/ws/site/{id}) and the Pi (/ws/gateway/{id}); the Roblox Bridge posts to /sim/* and polls GET /sites/{id}/device. It runs in Docker on Vultr behind Caddy with Let's Encrypt.
Distance to a strike uses the haversine formula, with
The lightning rule. A strike
When the clock runs out the beacon stays locked out until a supervisor PIN (on the dashboard or the beacon's remote), so the equipment never restarts on its own.
Heat index, from the National Weather Service Rothfusz regression, with
Floods. River sites get a flood warning when the 24 hour rain total exceeds 50 mm or the river discharge exceeds 2.5 times its 90 day mean,
Wind. Gusts of 28 mph or more raise a wind warning and 40 mph or more a wind danger. Heat, flood and wind alerts refresh while the condition lasts and expire an hour after it ends.
Every site gets a 0 to 10 hazard index for tomorrow with the three weather reasons that pushed it up. Training code is in ml/, serving code in backend/app/intel/, and the full numbers in ml/report/metrics.md.
flowchart TB
EIA["EIA-860M: the 50 largest plants<br/>25 in Florida, 25 across the Gulf states"] --> W["Open-Meteo archive, 2016 to 2024<br/>daily weather per site"]
NOAA["NOAA Storm Events<br/>within 40 km, same day"] --> L["Site-day labels<br/>164,400 site-days"]
OSHA["OSHA severe injuries<br/>outdoor, within 25 km"] --> L
W --> F["20 features"]
STATIC["FEMA flood zone, coastal, river, lat, lon"] --> F
F --> S{"Split by time"}
L --> S
S -->|"2016 to 2022"| T["LightGBM training"]
S -->|"2023"| V["Early stopping, isotonic calibration, decile cuts"]
S -->|"2024"| X["Held out test year"]
V --> P["Live: tomorrow's forecast to probability,<br/>index and three SHAP reasons"]
What it predicts. The unit is a site-day: given tomorrow's weather at one of the 50 plants, how likely is a hazard that can hurt a crew. Every site and day from 2016 to 2024 is one example,
- a NOAA Storm Events record (heat, lightning, flood, flash flood, coastal flood, thunderstorm wind, high or strong wind, tornado, hail, tropical storm, hurricane) with coordinates within 40 km of the site,
- a zone-based Storm Events record (mostly heat) whose county matches the site's county,
- an OSHA severe injury report flagged outdoor (construction or electric utility NAICS, or a narrative mentioning heat, lightning, storm, flood, mud, trench, pole, line, or bucket truck) within 25 km.
Sites and features. Sites are the 25 largest plants in Florida and the 25 largest in GA, AL, MS, LA and TX from EIA-860M (generator rows summed per plant). The 20 features are the day's weather from Open-Meteo (historical reanalysis for training, the forecast for scoring): max, apparent max and min temperature, max humidity, precipitation and rain, 3 and 7 day precipitation, soil moisture, gusts and wind, a heat feature, the month and the day of year as
Model. Gradient boosted trees (LightGBM). Each round adds a tree to the log-odds score,
with 31 leaf trees, at least 50 samples per leaf and 80% of features per tree. Positives are rare, so they are weighted by
Training stopped early on the 2023 validation year's average precision, at 182 trees.
How it is tested. Split by time, never at random: train 2016 to 2022, validate and calibrate 2023, test once on 2024. A random split would let the same storm leak into training and test through neighboring sites and days. Every metric is also reported for the rule a supervisor would write by hand (heat index at least 103 °F, or 3 day rain at least 75 mm, or gusts at least 60 km/h).
| 2024 test year (18,300 site-days, 5.8% positive) | Model (LightGBM, isotonic calibration) | Baseline rule |
|---|---|---|
| PR AUC (average precision) | 0.246 | 0.084 |
| ROC AUC | 0.817 | 0.594 |
| Brier score (lower is better) | 0.049 | 0.136 |
| Precision / recall | 0.211 at 50% recall | 0.149 at 29% recall |
Average precision is
Calibration. The class weights distort the raw scores, so an isotonic regression fit on 2023 maps them back to probabilities. It finds the non-decreasing function
stored as points in schema.json and applied with linear interpolation. Predicted probabilities track what actually happened up to about 0.3, which is where nearly every site-day falls; above 0.5 there are only a handful of days per bin and the model is overconfident.
The 0 to 10 index. The calibrated probability
so a 7 means tomorrow looks riskier than 70% of the site-days the model was validated on.
The three reasons. SHAP (TreeExplainer) splits each prediction into feature contributions, the Shapley values
Same-signal features are summed (heat index, apparent max and max temperature; rain and precipitation; gusts and wind), and the three largest weather contributions are shown as plain values ("3 day rain 111 mm", "Gusts 49 km/h"). Location features stay in the model but are never shown as a reason.
What it is not. The label is at county and day resolution, so the model cannot know whether a particular crew was exposed; it is a ranking tool for deciding where to look first, not a forecast of injury. Zone-based heat events are matched to counties by name and are undercounted. OSHA reports are placed by zip code, which can be several kilometers off, and the outdoor flag is a keyword match. Location ranks high in the SHAP chart, so part of what the model learned is which sites have historically been riskier, not only which weather is. The heat feature is the day's maximum apparent temperature, not the NWS heat index formula, because the daily data cannot pair the afternoon high with afternoon humidity. Training weather is reanalysis and scoring weather is a forecast, so tomorrow's index inherits the forecast's error. The baseline rule is in every table so you can see how much the model adds.
The 6 PM briefings (English and Spanish), the one sentence explanation of each index, and hazard photo tagging use Gemini with JSON response schemas. Every number in generated text is checked against the numbers in its input. With
otherwise it retries once, then falls back to a template built from the input alone, so a briefing can never state a number that is not in the data. Calls go through a small queue that retries rate limits and server errors.
Code is in firmware/: pod/, controlbox/ and gateway/; the wiring is in docs/hardware-guide.md and the serial lines in contracts/serial.md.
Sensor pod (RP2040-Zero, MicroPython). Core 1 samples the photoresistor at 5 kHz. At boot it measures the resting light, mean
in 16 bit ADC counts. A flash needs two samples in a row above
Flash to bang. When thunder is heard (a microphone page on the twin laptop, or a USB mic on the Pi), the distance is
so 10 miles is a gap of about 46.9 s, roughly 4.69 s per mile. Pairs must fall between 0.3 and 60 s. Offline with no microphone, a flash alone fails safe to a stop work with the distance unknown.
Beacon head (Arduino UNO). It drives the LCD1602 text screen, the 4 digit countdown (a 74HC595 shift register, one digit lit every 2 ms) and a 29 LED WS2812B strip. The strip is the gauge: a white bar climbs from LED10 toward LED1 with the hazard index, and LED25 to LED29 show the status color (green, yellow, red, strobing red in a stop work). The countdown on the display, the LCD and the dashboard all come from the UNO's own once a second echo, so they never disagree. The serial link runs at 9600 baud on purpose: one byte takes longer than the strip update's 1 ms interrupt pause, so no command is ever lost.
Gateway (Raspberry Pi 5, Python asyncio). It runs the local rules, holds the equipment interlock on GPIO 18 through an L293D driver (low stops the motor, and the pin is held low if the program stops or crashes), speaks with Piper text to speech offline in English and Spanish, and handles the remote: crew numbers check in, OK plus the 4 digit PIN plus OK releases a stop work. Offline it keeps enforcing everything, queues its events and replays them in order with their original timestamps when it reconnects. A stop work survives a reboot, and a release made on the dashboard while the beacon was offline is applied when it comes back.
stateDiagram-v2
[*] --> AllClear
AllClear --> StopWork: strike within 10 mi
StopWork --> StopWork: new strike within 10 mi, countdown restarts
StopWork --> LockedOut: 30 min with no strike
StopWork --> AllClear: supervisor PIN or dashboard release
LockedOut --> AllClear: supervisor PIN or dashboard release
AllClear --> StopWork: offline flash with no mic, fail safe
Code is in sim/: the World in sim/src/World, the Bridge to the backend in sim/src/Bridge, and the place in sim/place/PlanITSwamp.rbxl.
The twin's lightning is simulated physics, not a script. A storm cell starts about 20 miles out and moves toward the site,
and its cloud to ground flash rate rises and falls over its life
Strike times are a non-homogeneous Poisson process, drawn by thinning: candidates arrive every
and 5% are "bolts from the blue", 5 to 10 miles ahead of the storm. Each strike's distance and bearing to the site are computed from its position, never typed in. Thunder arrives after
its loudness falls as
sequenceDiagram
participant R as Roblox twin
participant B as Backend
participant G as Pi gateway
participant U as UNO and fan
participant D as Dashboard
R->>B: POST /sim/strike (bearing, miles)
B->>B: within 16,093 m, open or extend stop work
B-->>D: websocket alert
B->>G: STOPWORK 1800 s
G->>U: GPIO 18 low, fan stops, countdown starts
G->>G: speaks "Lightning detected, 8 miles"
U-->>G: COUNT once a second
Note over R,D: every strike within 10 mi restarts the 30 minutes
G->>G: remote OK, PIN, OK
G->>U: GPIO 18 high, fan restarts
G->>B: PIN accepted
B-->>D: stop work cleared by "Supervisor PIN at beacon"
The twin also drives weather, floods (the water depth reaches the beacon as if its own probe were wet), wind, heat and an alligator sighting, and players inside the work zone appear on the muster list.
A React and TypeScript app (Vite, Tailwind): the Dashboard (map, ranked site list, status of every data feed and the beacon), the Hub for each site (the factor web from categories down to live readings with trends and forecasts, the hazard index and its reasons, muster, the 48 hour conditions chart, hazard reports, briefings, and the compliance log of every stop work), a phone first crew page (sign in, check in, condition cards with what to do, hazard photos, English and Spanish), and Auth0 sign in with a supervisor role for releases.
| Folder | What | Built by |
|---|---|---|
backend/app/core |
database, fetchers, rules, scheduler, websockets, auth, gateway endpoint, sim ingest | Viet, Chris |
backend/app/intel |
hazard index scoring, briefings, Gemini photo tagging | Chris |
ml |
training pipeline and report | Chris |
web |
dashboard, Hub, crew phone page | Cam |
sim/src/World, sim/place |
Roblox place, scenarios, lightning, zone, beacon visuals, scene | Slavik, storm model by Viet |
sim/src/Bridge |
Luau HTTP bridge to the backend | Viet |
firmware/gateway, firmware/pod, firmware/controlbox |
Pi gateway, sensor pod, beacon head | Chris (software), Slavik (hardware build) |
contracts |
the interfaces every piece speaks | Chris |
deploy |
Docker Compose, Caddy, server notes | Chris |
docs |
the build guides | everyone |
- Backend locally: fill
.envfrom.env.example(contracts/env.mdsays who sets what), thenscripts/dev.sh backend. The schema creates itself on first boot anddata/sites.csvis loaded on every boot.python -m app.core.seed(frombackend/) adds the demo crew and two sample reports. - Backend in Docker:
docker compose -f deploy/docker-compose.yml up -d --build backend web. - End to end test: with the real Pi offline,
python -m app.core.e2e <base_url>frombackend/strikes the beacon site twice, checks the fake gateway gets STOPWORK and the countdown moved, then clears it with the PIN. - Beacon: the Pi setup, the on device tests and a laptop simulator of the pod and UNO (
devsim.py) are infirmware/gateway/README.md; flashing the pod and the UNO is infirmware/pod/README.mdandfirmware/controlbox/README.md. - Roblox: open
sim/place/PlanITSwamp.rbxlin Studio, paste the sim token into the Bridge's attributes, enable HTTP requests, and press Play.lune run sim/test/harness.luau sim/place/PlanITSwamp.rbxlruns every scenario outside Studio. Seesim/CLAUDE.md. - Training:
ml/downloads the data, builds the labels and features, and trains (download.py,labels.py,weather.py,features.py,train.py); it writes the model intobackend/app/intel/model/and the report intoml/report/.
main is demo ready and only receives merges from dev. dev is integration. Work on feature/<area>-<thing> off dev, merge back often. See CLAUDE.md.
- Building a hazard label from county and zip code level records without leaking the same storm into both training and test data.
- Keeping the beacon fully functional offline, then syncing its events once it reconnects, including a release made on the dashboard while the beacon was offline.
- Getting Roblox, the backend and physical sensors to agree in real time, and making the twin's lightning physically correct instead of scripted.
- Real hardware: a DC motor's electrical kick could garble the LCD mid write (the UNO now resyncs and redraws it every 5 seconds), a power bank sagged the Pi's 5 V under load and browned out the speaker (it runs on wall power), and the only spare servo was a continuous rotation type that cannot hold a position, so the LED strip became the gauge.
More sites and regions, real lightning network feeds, document ingestion (site PDFs and inspection records feeding each site's hazard history), wind and wildlife warnings on the beacon itself, a published twin that anyone can join from a phone, a microphone on the beacon so flash to bang works fully offline, pilots with utility crews, and a hardened beacon enclosure.