Enhance FMCSA flagger: for-hire as deficiency, zero fleet detection

- For-hire carriers now flagged with issues (BOC-3/UCR/insurance needed)
- Zero trucks/drivers flagged as stale data
- For-hire + MCS-150 overdue = critical severity
- Actionable flags count excludes zero_fleet (informational only)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-29 00:19:00 -05:00
parent e510cefb88
commit 5bf364aced

View file

@ -125,6 +125,8 @@ def flag_carriers(dry_run: bool = False) -> dict:
# For-hire carrier — needs BOC-3, UCR, insurance
if for_hire:
flags.append("for_hire_carrier")
issues.append("For-hire carrier — BOC-3, UCR registration, and liability insurance required")
severity = "major" if severity == "none" else severity
stats["for_hire"] += 1
# Hazmat — needs PHMSA registration
@ -134,8 +136,25 @@ def flag_carriers(dry_run: bool = False) -> dict:
severity = "major" if severity in ("none", "minor") else severity
stats["hazmat"] += 1
# Determine campaign eligibility
deficiency_count = len([f for f in flags if f not in ("for_hire_carrier",)])
# Zero trucks/drivers — possibly inactive or data stale
if (trucks is not None and trucks == 0) or (drivers is not None and drivers == 0):
flags.append("zero_fleet")
issues.append("Zero trucks or drivers on file — update your MCS-150 if still operating")
stats.setdefault("zero_fleet", 0)
stats["zero_fleet"] += 1
# New entrant (registered in last 18 months) — needs safety audit prep
# add_date is stored as text like "01-JAN-25"
# We can't easily parse all formats here, so use mcs150_parsed as a proxy
# for recent registration if the carrier has very few inspections
# Determine campaign eligibility — any real issue makes them eligible
# For-hire + MCS-150 overdue = critical (they need everything)
if for_hire and "mcs150_overdue" in flags:
severity = "critical"
actionable_flags = [f for f in flags if f != "zero_fleet"]
deficiency_count = len(actionable_flags)
campaign_eligible = deficiency_count > 0 and bool(email)
if campaign_eligible: