DEV Community

Cover image for Computing Truck Turnaround Time from Gate Events: A Simple Data Model
Suraj Informatics
Suraj Informatics

Posted on Originally published at surajinformatics.com

Computing Truck Turnaround Time from Gate Events: A Simple Data Model

Plants that automate their gates with RFID or ANPR end up with a stream of events: a vehicle was seen at the gate, stood on the weighbridge, docked at bay 4, left. Turning that stream into a useful truck turnaround time (TAT) report is a small but surprisingly fiddly data problem. Here is a simple model that works.

The events

Each reader, camera or weighbridge terminal emits an event with the same shape:

from dataclasses import dataclass
from datetime import datetime

@dataclass
class GateEvent:
    visit_id: str      # one truck visit (gate pass / trip number)
    vehicle: str       # plate or RFID tag
    stage: str         # REPORTED, GATE_IN, WEIGH_1, BAY_CALL, DOCK_IN, DOCK_OUT, WEIGH_2, GATE_OUT
    ts: datetime
Enter fullscreen mode Exit fullscreen mode

The key design choice is visit_id. Using the vehicle number alone breaks as soon as the same truck makes two trips in a day.

Stage durations

ORDER = ["REPORTED", "GATE_IN", "WEIGH_1", "BAY_CALL", "DOCK_IN", "DOCK_OUT", "WEIGH_2", "GATE_OUT"]

def stage_durations(events):
    ts = {e.stage: e.ts for e in events}
    out = {}
    for a, b in zip(ORDER, ORDER[1:]):
        if a in ts and b in ts:
            out[f"{a}->{b}"] = (ts[b] - ts[a]).total_seconds() / 60
    if "REPORTED" in ts and "GATE_OUT" in ts:
        out["TAT"] = (ts["GATE_OUT"] - ts["REPORTED"]).total_seconds() / 60
    return out
Enter fullscreen mode Exit fullscreen mode

Note that TAT starts at REPORTED, not GATE_IN. Time spent queuing outside the gate is real turnaround time, even if the gate register never sees it. An ANPR camera a little way up the approach road is the easiest way to capture it.

Things that go wrong in real data

  • Missing events. A tag is not read at one stage. Report the visit as incomplete rather than guessing.
  • Duplicate reads. Readers fire several times as a truck passes. Keep the first read per stage per visit.
  • Clock drift. Sync every device to one NTP source, or stage durations turn negative.
  • Value-adding vs waiting. Only DOCK_IN->DOCK_OUT is loading. Everything else is waiting, and that is where the savings are.

Why it matters

Once each stage has a duration, you can group by shift, product, transporter or gate and see exactly where trucks lose time. This is the approach behind the stage-wise TAT dashboards in GATIVRA, the plant logistics platform from Suraj Informatics.

For the business side (what TAT means, the formula and seven ways to reduce it), see the full guide: TAT in Logistics: What Truck Turnaround Time Means and How to Cut It.

Top comments (0)