Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

drayage-watch

A working demo of carrier and terminal charge exposure for a drayage fleet.

Several tariff windows can apply to one imported container, and dispatch teams routinely track them in the same spreadsheet column:

  • Demurrage — the loaded box sits inside the terminal past its free days. The carrier window starts at vessel discharge and stops at the out-gate.

  • Per diem (detention) — the box sits outside the terminal, in the motor carrier's possession, past its free days. Billed by the ocean carrier. The clock starts at the out-gate and stops when the equipment is returned.

  • Combined demurrage and detention — one carrier allowance can run from discharge of the full unit through gate-in of the empty. Maersk Colombia uses this model; the out-gate does not reset or stop it.

  • Storage — the terminal bills yard occupancy on its own allowance. At SPRC Cartagena it runs in parallel with the Maersk carrier charge until out-gate.

The start and end milestones come from each tariff schedule, not from a fixed status branch. Carrier and terminal charges can overlap; two applicable schedules from the same issuer and charge cannot. Collapsing all of these windows into one clock is why a monthly invoice tends to exceed a spreadsheet estimate.

The second thing this demo shows is tiering. Terminal tariffs escalate: the second week of demurrage is not priced like the first. A flat days × rate estimate is roughly right on the boxes that are fine and badly wrong on the boxes that are already in trouble — which are the only ones that matter. The seven-day chart on the front page climbs for exactly this reason.

Screens

Demo: dispatch board, fleet map, and the move planner

One page. Money owed today, what the next seven days add if nothing moves, a charge-prioritized daily dispatch plan, the fleet's current terminal/customer positions, the fleet sorted worst-first, and a planner that prices a move on a chosen date against letting the box drift.

Two markets are seeded — US Southeast (Savannah, Miami) and Colombian Caribbean (Cartagena, Barranquilla) — because allowances vary by issuer, country or port scope, equipment, and effective date.

Tariff data

Schedules live as versioned YAML in api/app/tariffs/. The selector matches the container's carrier, country or terminal scope, equipment type and size, and the schedule validity window. A malformed fixture fails when the module loads, and ambiguous schedules from one issuer for one charge fail rather than being picked silently.

The Maersk Colombia import schedule and SPRC storage schedule are cited snapshots with source_url and retrieved_on metadata. The Savannah and Miami schedules are illustrative migrations of the original demo values and carry illustrative: true through the API and UI. Tariffs change; reverify the cited source before using any value outside this portfolio demo.

Running it

Requires Python 3.11+, Node 20+, Docker, and uv.

# database -> localhost:5432
cp api/.env.example api/.env
docker compose up -d --wait db

# osrm  -> localhost:5001 (US) and localhost:5002 (CO); builds datasets on first run
osrm/build.sh us
osrm/build.sh co
docker compose up -d --wait osrm-us osrm-co

# api  -> http://localhost:8000  (docs at /docs)
cd api
uv sync --all-extras --dev
uv run python seed.py
uv run uvicorn app.main:app --reload

# web  -> http://localhost:5173
cd ../web
npm ci
npm run dev

osrm/build.sh downloads the Geofabrik extracts (about 1.3 GB, once) and builds both truck-routing datasets in Docker; see osrm/README.md. The API works without OSRM — only /api/travel-times, /api/plan, and route drawing answer 503 until the services are up.

The seed builds dates relative to today, so the demo never goes stale. It uses a fixed random seed, so you get the same fleet every run.

With PostGIS running and seeded, verify with cd api && uv run pytest -q and cd web && npm run build.

What's inside

api/
  app/rules.py     scoped tariff selection and tiered assessment, no framework
  app/tariffs/     versioned YAML schedules, sources, and strict loader
  app/dispatch.py  pure OR-Tools pickup/delivery sequencing
  app/models.py    Container, Customer, Terminal, Truck (SQLAlchemy + PostGIS)
  app/main.py      assessed fleet, planning, simulation, and GeoJSON endpoints
  app/osrm.py      OSRM HTTP client: one service per market, no ORM imports
  seed.py          27 containers, including Colombian dry and reefer equipment
  tests/           rules, dispatch, PostGIS map, and mocked-OSRM coverage
osrm/
  build.sh         reproducible per-market dataset builds (Geofabrik -> MLD)
  profiles/        vendored car.lua base and the truck.lua derived from it
web/
  src/App.jsx      headline figures, seven-day curve, map, and fleet board
  src/components/  BleedCurve, DayPlan, FleetMap, ContainerBoard, MovePlanner

rules.py has no imports from the web framework or the ORM. It takes dates and returns money, which is what makes it testable and what makes the tests worth reading.

Endpoints

Method Path What it does
GET /api/containers?market=US Fleet, assessed and sorted worst-first
GET /api/summary?market=US Totals, counts, and the seven-day curve
GET /api/map?market=US Active containers and terminals as GeoJSON
GET /api/travel-times?market=US Terminal-to-customer truck minutes, one row per terminal
POST /api/plan Charge-prioritized pickup/delivery sequences for one market
POST /api/plan/route Selected truck sequence as OSRM GeoJSON geometry
POST /api/containers/{id}/simulate Cost of moving on a date vs. drifting

Scope

This is a demo, and it is honest about it:

  • Maersk Colombia and SPRC values are dated, cited snapshots. Savannah and Miami values are illustrative stand-ins, marked in YAML, API responses, and the UI. Published tariffs and customer-specific contracts change.
  • Calendar days, not working days. Several terminals exclude weekends and holidays from demurrage free time; that belongs in rules.py and isn't there.
  • PostGIS stores terminal and customer points in SRID 4326. The map places terminal boxes at the terminal and out-gated boxes at their customer; it is a deterministic demo dataset, not live tracking.
  • Truck travel times come from two local OSRM services (one per market) built from OpenStreetMap with a vehicle profile for a tractor + 40' container. They are road-network estimates without live traffic. The two US corridors (Savannah and South Florida) are separate clips, so cross-region pairs return null.
  • Daily sequencing uses OR-Tools pickup/delivery constraints, capacity one, seeded appointment windows, 20-minute service times, and market-local shifts. It minimizes the daily charge exposure a movement can actually stop first and truck minutes second; avoided charges are recalculated at the actual clock-stopping date so a stop after midnight uses the next calendar day's tariff tier.
  • This is tactical prioritization, not a production optimizer: there are no live terminal appointment feeds, traffic, vessel schedules, chassis constraints, driver breaks, auth, or multi-process deployment.

Production versions of this problem live against terminal appointment systems and the carrier's own TMS, which is where the interesting work actually is.

Stack

FastAPI · SQLAlchemy 2 · Pydantic v2 · PostGIS · OSRM (MLD, truck profile) · OR-Tools · React 18 · Leaflet · Vite

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages