Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Project: audit fulfillment delays without hiding the tail

Last updated: 5 Oct 20265 min read
project
IntermediateBy AITrove Editorial

Build a reproducible delivery-delay analysis that separates invalid timestamps, valid rare cases and route-mix effects.

Define the event contract

Create one row per shipment with stable ID, dispatch time, arrival time, route, service promise and source revision. Include 47 fixture shipments with one duplicate event, one missing arrival, one negative duration and one valid overnight delay. State whether open shipments are excluded, censored or reported separately. The profile must count each state before filtering.

Triage before summarizing

Quarantine impossible chronology and duplicate identity conflicts with reasons. Investigate the overnight delay but keep it as valid unless evidence shows a recording error. Compute mean, median, raw MAD and a threshold-exceedance rate on the valid completed set, with numerator and denominator. Compare the summary with and without a declared valid-tail exclusion only as a sensitivity result.

Check route mix

Split the analysis by established and new routes. Report counts and rates in each period, then use one fixed reference mix to compare performance. Reproduce an aggregation reversal with a controlled fixture and ensure the dashboard shows both the pooled operational result and the standardized within-route view. The reversal lesson provides a test case.

Deliver a review packet

Save raw fixture, data cutoff, code revision, validation report, quarantine ledger, summary output and a short decision memo. Include exact counts for eligible, complete, missing, invalid and valid tail records. Rerun from the frozen snapshot and compare output checksums. A reader should be able to trace the 139-minute case from source event through every summary without it silently disappearing.

Implementation

python
from statistics import median

def median_delay_by_route(shipments):
    grouped = {}
    for shipment in shipments:
        arrival = shipment["arrival_minute"]
        if arrival is None or arrival < shipment["dispatch_minute"]:
            continue
        grouped.setdefault(shipment["route"], []).append(arrival - shipment["dispatch_minute"])
    return {route: median(delays) for route, delays in grouped.items()}

Performance and operating cost

Grouping N shipments costs O(N) time and space; sorting route samples for medians costs O(N log N) in the worst case. Production code must also preserve rejected-row counts and reasons, which this focused summary function leaves to the validation stage.

Common Mistakes

  • Do not silently drop invalid rows without a quarantine ledger.
  • Do not present only a median when tail failures matter.
  • Do not attribute a pooled rate change solely to process quality without checking route mix.

Read next

Continue the workflow: Integer allocation and relaxation gaps for indivisible work.

Continue the workflow: Project: audit missing delivery scans before reporting service rates.

Continue the workflow: Project: release a support breach monitoring packet.

ai-data
data-science
Storage details