question 497 Production Readiness Capstone · medium
Turn trips into report rows
The dashboard's trip table needs one row per trip with readable, derived fields instead of raw TLC columns. Transform the trips without touching the originals.
Function
report_rows(trips, zones)tripsdicts with
trip_id, pickup_at, dropoff_at (YYYY-MM-DD HH:MM:SS), pickup_zone_id, dropoff_zone_id, trip_distance_miles, fare_amountRow
{"trip_id", "route": "<pickup borough> → <dropoff borough>", "minutes": whole minutes (rounded down), "fare_per_mile": fare / distance rounded to 2, or None when the distance is 0}Boroughsfrom
zones (zone ID → borough); a missing zone is UnknownReturnsthe rows in the same order; the trips are not changed
Examples
callreport_rows([{'trip_id': 16126, 'pickup_at': '2025-01-15 00:12:47', 'dropoff_at': '2025-01-15 00:41:06', 'pickup_zone_id': 186, 'dropoff_zone_id': 179, 'trip_distance_miles': 9.2, 'fare_amount': 40.8}], {186: 'Manhattan', 179: 'Queens'})returns[{'trip_id': 16126, 'route': 'Manhattan → Queens', 'minutes': 28, 'fare_per_mile': 4.43}]
callreport_rows([{'trip_id': 16132, 'pickup_at': '2025-01-15 00:39:15', 'dropoff_at': '2025-01-15 01:03:54', 'pickup_zone_id': 70, 'dropoff_zone_id': 148, 'trip_distance_miles': 10.43, 'fare_amount': 42.9}], {70: 'Queens', 148: 'Manhattan'})returns[{'trip_id': 16132, 'route': 'Queens → Manhattan', 'minutes': 24, 'fare_per_mile': 4.11}]
callreport_rows([], {})returns[]