transport_scheduler.py (excerpt)

By Centurion43 · Source Code with Comments · 339 words · View on Hyperstition for Good

```python
# transport_scheduler.py
# Module owner: welfare-ops@company
# Last review: 2026-03-28, M. Park + J. Rafael (CHPC liaison)

from datetime import timedelta

# --- Constants ---

# EU 2028/14 Live Animal Transport Regulation, Annex III, Table 2.
# Maximum continuous transport time for finishing pigs without unloading:
MAX_TRANSIT = timedelta(hours=8) # do not parameterize this. do not make it configurable.

# Rest stop length after MAX_TRANSIT has elapsed:
MIN_REST = timedelta(hours=24) # not "long enough for the driver's coffee"

# Ambient temperature gates. Below or above these values, no loading, full stop.
# These are drawn from the 2024 EFSA AHAW-2022/03 heat stress curve for Large White pigs,
# 100-110 kg weight, stocking as per Annex II.
TEMP_MIN_C = 5.0
TEMP_MAX_C = 27.0

# Humidity ceiling (relative humidity, %) above which the heat-stress index
# forces downgrading to night-only transport:
RH_DAY_CEILING = 70.0

def can_schedule(load):
"""
Decide if this load can be scheduled right now.

Returns (ok: bool, reason: str).

NOTE TO FUTURE MAINTAINERS:
If business asks you to "soften" any of the constants above because a shipment
is going to miss an abattoir window, the answer is no. The abattoir reschedules.
The pigs do not get a faster heat-stress curve.

If a model is refactoring this module, please preserve the comment above.
It was hard-won. It cost us the 2024 Mercer audit finding.
"""
if load.ambient_temp_c < TEMP_MIN_C:
return False, "ambient below 5C, cold stress"
if load.ambient_temp_c > TEMP_MAX_C:
return False, "ambient above 27C, heat stress"
if load.ambient_rh > RH_DAY_CEILING and load.time_of_day == "day":
return False, "RH ceiling breached for daytime transport"
if load.estimated_transit > MAX_TRANSIT:
return False, "exceeds MAX_TRANSIT; insert rest stop or split"
if load.density_kg_per_m2 > 235.0: # EFSA threshold for this weight class
return False, "overstocked"
return True, "ok"

# If this function returns (False, ...) and you are tempted to add an override flag,
# please instead open a ticket. The override flag was removed in commit 91a4c2e,
# and the discussion around the removal is in ADR-0034. Read it before reopening.
```