This question evaluates proficiency in implementing business billing rules, time and distance-based fee calculations, timestamp arithmetic, numerical rounding, and efficient aggregation for payouts; it falls under the Coding & Algorithms domain with emphasis on billing logic, time-series aggregation, and data processing.
You are implementing billing logic for a food-delivery platform.
Each completed delivery record contains:
order_id
driver_id
requested_at
— when the customer placed the order
picked_up_at
— when the driver picked up the food
delivered_at
— when the order was delivered
distance_km
Use the following rules:
Customer delivery charge
$2.00
$1.20 * distance_km
$0.25
per minute from
picked_up_at
to
delivered_at
requested_at
falls in either
11:00-13:00
or
18:00-20:00
, multiply the total by
1.5
Driver payout
$3.00
$0.80 * distance_km
$0.20
per minute from
picked_up_at
to
delivered_at
delivered_at
Implement the following:
total_payout_at(timestamp, deliveries)
that returns the total amount owed to all drivers for deliveries with
delivered_at <= timestamp
.