AI Fleet: Driver Safety Dashboard
Regional safety managers had more lane-departure reports than they could investigate individually. I built the Driver Safety Dashboard for a customer proof of concept so they could decide which driver to review first and which stretch of road-facing footage warranted a closer look.
- Problem
- Two drivers could register the same number of departures over very different distances. Several departures close together could also describe one episode worth reviewing.
- Decision
- I built the review workflow around miles per departure and moved risk ordering into the API so the first page reflected the whole queue. Each grouped event kept the timestamps a reviewer could follow.
- Result
- I demonstrated the workflow to the customer. Reviewers could select a risk category, open a driver and inspect the departures grouped into an event.
- Context
- Sonatus - AI Fleet
- Period
- 2025–2026
- My focus & role
- Led engineering for the fleet proof of concept, built the data pipeline and dashboard, and moved risk ordering into the backend so it applied before pagination.
- Technology
- Apache Airflow · Python · pandas · Selenium · PostgreSQL · FastAPI · React · TypeScript
Driver risk summary
Concept interface - synthetic data · seven daysEach driver has one risk rating. Select a category to review its drivers.
Review 8 drivers
| Driver | Risk status | Region | Events | Details |
|---|---|---|---|---|
DRIVER-103 | Severe risk | south | 6 | |
DRIVER-105 | Severe risk | north | 4 | |
DRIVER-101 | High risk | north | 3 |
8 matching drivers · page 1 of 3
The safety review and my role
From a fleet summary to one driver’s record
I owned the engineering from data collection through the API to the React dashboard. I worked directly with the customer, the CEO and the CTO throughout the proof of concept. The customer described the decision that followed a flag. A regional safety manager found the road-facing footage for that time window in a separate system, checked what had happened and decided whether to send a clip to the driver’s coach.
I designed the review flow with Product, worked through the mockups with UX designers and agreed the API contracts with the backend team. I paired with another data and backend engineer on the fleet pipeline. I implemented risk ordering for the driver list and built the drawer that gave the reviewer an event start, a duration and the readings to investigate.
In a December review, the customer described a reason to change the date range. A driver with a good longer-term record could still have a difficult night. A manager could select that night’s dates and inspect the driver’s events. The consolidated feedback proposed automating the comparison with earlier performance. In the delivered dashboard, the manager chose each period to review.
Incident and mileage collection
Join daily mileage and individual departures by driver
SafetyDirect recorded individual lane departures. A Python job used Selenium and Chrome to read each driver’s dated report, including timestamps and odometer readings. Samsara supplied daily distance through its hours-of-service reports. The jobs used a shared driver ID so a departure recorded at one instant could be compared with the distance driven over the whole review period. FastAPI read those records from PostgreSQL for the React dashboard.
How mileage and lane departures meet in the driver queue
Architecture diagram- Samsara · daily driver mileageAn Airflow job imports distance by driver and report date.PostgreSQL · driver mileageDaily mileage provides the starting set of drivers for a date range.
- SafetyDirect · lane departuresAn Airflow job imports timestamped incidents. A dependent job groups nearby readings by driver.PostgreSQL · incidents and eventsIndividual readings and grouped windows remain available for different counts.
What a rerun could recover
The mileage API supplied a cursor for fetching the next page of one day’s report. Airflow jobs accepted a load date, so an earlier day could be requested again. Reprocessing a date updated existing departures by driver and timestamp, and mileage by driver and day. The pipeline recorded the processed dates and any gaps between them for each region and service center. A day could be marked as processed even if one driver’s source report was unavailable. The record could identify a missing day, but establishing coverage for a particular driver required checking their source report.
Driver risk and event evidence
How mileage and lane departures shaped the review queue
The API summed each driver’s mileage and counted individual departures over the requested dates. Fewer miles per departure meant departures were more frequent over the distance driven. The list started with drivers who had a mileage record. A driver with mileage and zero departures could still appear. A driver with recorded departures and no mileage entry for that period dropped out of the list entirely.
The risk rules used fixed cutoffs and, for one comparison, the fleet median of finite miles-per-departure ratios. Drivers with zero departures contributed no value to that median. The API calculated it before applying region and service-center filters. A reviewer could narrow the queue to a smaller area and keep the same fleet comparison for those dates.
Which drivers enter the fleet comparison?
Synthetic query exampleOne reporting period, five invented drivers. Choose a region to see which mileage records reach the review queue.
| Driver | Miles | Departures | Miles per incident |
|---|---|---|---|
| ANorth | 96 | 4 | 24 |
| BNorth | 120 | 0 | ∞ |
| CSouth | 192 | 4 | 48 |
| DSouth | 168 | 2 | 84 |
When six departures warrant a footage review
SafetyDirect had already identified each excessive lane departure. Our pipeline received its timestamp and odometer reading when available. Once the collection job finished, an Airflow job read recent departures from PostgreSQL and used pandas to put each driver’s observations in time order.
Six departures by one driver within fifteen minutes opened an event for review. Further departures extended that event while the gap between consecutive departures stayed within the continuation rule. The event ran from the first departure to the last. Its duration measured the span of the sequence. The input did not record how long the truck spent across the lane line on each crossing.
The event record kept the time of every member departure in a PostgreSQL JSONB array. The driver detail view used those timestamps to retrieve available odometer readings. A manager could see the sequence, find the corresponding stretch of road-facing footage and decide whether the driving called for coaching.
Which stretch of footage should a safety manager review?
Synthetic shift dataIn each example, the driver covers 90 miles during a shift. The timeline shows all 6 lane departures that shift. Switch their spacing to see when the system flags a stretch of driving for review.
6 lane departures · 1 event · 15 miles per departure
All six departures fall within 15 minutes. A safety manager could use 09:10 to 09:25 to find the corresponding road-facing footage.
Inspect departure times
09:10, 09:13, 09:16, 09:19, 09:22, 09:25.
A driver could cover few miles between departures over the course of a shift and still have no cluster of six. That driver could warrant attention in the risk queue even without a specific event to inspect. Managers also needed to know whether event processing had finished. During the proof of concept, a delay between incident collection and event generation once left the queue showing zero events across the fleet.
Six departures close together and six spread over fifteen minutes both met the opening rule. Their timing gave a reviewer different evidence. The detail view displayed event duration in whole minutes, so timestamps mattered for bursts shorter than a minute. The team later explored a severity score to compare these patterns. The delivered dashboard left the coaching decision with the safety manager after a footage review.
Queue ordering and filters
Sort the whole queue before showing a page
Sorting only the visible rows could leave a higher-risk driver on page two. I moved status sorting into the API. The table requested that order by default. The API ranked risk categories and broke ties within a category by grouped-event count. The browser applied a case-insensitive name search to those ordered rows before slicing out the requested page.
The table could use one response for its rows and summary. Selecting a risk category or searching for a name triggered a second request for totals scoped to the dates, region and service center. Even a name-only search triggered that call, although the browser already had the names and filtered them locally.
Date boundaries
What does the last day of a review include?
The October user guide described “last day” as the previous completed calendar day. In the later frontend, that preset sent yesterday’s date as the start and today’s date as the end. The list included both dates, so a reviewer looking back at yesterday could also see records already loaded for today.
When the customer asked for a “Today” option, they also wanted to know when the data run had finished. The safety table stamped “Last updated” when the browser finished fetching its rows. Refreshing the screen could advance that timestamp while the event job was still processing departures. I would show the last completed event load beside the date range so a manager could judge a quiet morning’s numbers before acting on them.
I fixed a frontend date bug that converted a locally selected calendar day through UTC and could send the previous day to the API. I put date-only formatting in a shared helper and tested predefined and custom ranges.
The backend snapshot shows a separate issue. The Driver Safety list counts incidents through the selected end date. The detail query for incidents and events includes the following calendar day as well. Sending identical dates from React can therefore produce different counts. I would give both queries the same inclusive start and exclusive end, with midnight after the last selected day as the upper bound. I would test a departure on each side of that boundary.
Project artifacts
Implementation screenshots
These redacted captures show how a reviewer moved from the risk queue to a driver’s events.
Driver Safety overview
Adapted implementation screenshot
Driver Safety event drawer
Adapted implementation screenshot
Customer delivery
How customer review changed the safety queue
I demonstrated the dashboard to the customer and deployed revisions during the proof of concept. I replaced the pie chart with a total beside the risk tiles so reviewers could see the size of the queue and select a group in the same place. I extended tests for sorting, request parameters, date ranges and summary rendering.
Decision record from the customer reviews
This reconstruction draws on the safety team’s feedback, the dashboard user guide, the backend handover and the implemented driver drawer.
- Who appears first. Reviewers asked to sort by risk status. I moved that ordering into the API, so the first driver on page one came from the full result set.
- What explains an event. Reviewers wanted each departure inside the event, including vehicle control readings. I reviewed the cost of further collection with Product and removed the speed and brake columns. The delivered drawer showed timestamps and the available odometer readings.
- Who follows up. The regional safety manager reviewed the footage and decided whether to involve a coach. The project documents left direct video retrieval and coaching scheduling as follow-up work.
The AI Fleet Service Priority Dashboard covers the maintenance team’s investigation from vehicle queues to diagnostic faults.