Loading problem...
A mobility analytics team wants a monthly utilization KPI for its driver network.
Table: drivers
Table: rides
Table: accepted_rides
Task: For each month of calendar year 2020, return the percentage of available drivers who were working.
Definitions:
Data quality rule:
Metric:
Output requirements:
Supported submission environments:
drivers:
| driver_id | join_date |
|-----------|------------|
| 10 | 2019-12-10 |
| 8 | 2020-01-13 |
| 5 | 2020-02-16 |
| 7 | 2020-03-08 |
| 1 | 2020-10-24 |
rides:
| ride_id | user_id | requested_at |
|---------|---------|--------------|
| 1 | 55 | 2020-03-04 |
| 2 | 66 | 2020-03-18 |
| 3 | 77 | 2020-06-03 |
| 4 | 88 | 2020-11-02 |
| 5 | 99 | 2020-11-09 |
| 6 | 44 | 2020-12-09 |
| 7 | 33 | 2021-01-02 |
accepted_rides:
| ride_id | driver_id | ride_distance | ride_duration |
|---------|-----------|---------------|---------------|
| 1 | 10 | 8 | 15 |
| 2 | 10 | 5 | 11 |
| 3 | 8 | 12 | 21 |
| 4 | 1 | 20 | 30 |
| 5 | 7 | 17 | 28 |
| 6 | 5 | 7 | 12 |
| 7 | 8 | 9 | 16 |[
{"month":1,"working_percentage":0.0},
{"month":2,"working_percentage":0.0},
{"month":3,"working_percentage":25.0},
{"month":4,"working_percentage":0.0},
{"month":5,"working_percentage":0.0},
{"month":6,"working_percentage":25.0},
{"month":7,"working_percentage":0.0},
{"month":8,"working_percentage":0.0},
{"month":9,"working_percentage":0.0},
{"month":10,"working_percentage":0.0},
{"month":11,"working_percentage":40.0},
{"month":12,"working_percentage":20.0}
]March has 4 available drivers and 1 distinct working driver (10), so 25.00. In November, 5 drivers are available and 2 distinct drivers worked (1 and 7), so 40.00. The 2021 ride is ignored for the 2020 report.
drivers:
| driver_id | join_date |
|-----------|------------|
| 42 | 2021-03-01 |
rides:
| ride_id | user_id | requested_at |
|---------|---------|--------------|
| 100 | 9 | 2020-06-10 |
accepted_rides:
| ride_id | driver_id | ride_distance | ride_duration |
|---------|-----------|---------------|---------------|
| 100 | 42 | 11 | 18 |[
{"month":1,"working_percentage":0.0},
{"month":2,"working_percentage":0.0},
{"month":3,"working_percentage":0.0},
{"month":4,"working_percentage":0.0},
{"month":5,"working_percentage":0.0},
{"month":6,"working_percentage":0.0},
{"month":7,"working_percentage":0.0},
{"month":8,"working_percentage":0.0},
{"month":9,"working_percentage":0.0},
{"month":10,"working_percentage":0.0},
{"month":11,"working_percentage":0.0},
{"month":12,"working_percentage":0.0}
]No driver is available during 2020, so each month has denominator 0 and therefore reports 0.00 by definition.
drivers:
| driver_id | join_date |
|-----------|------------|
| 1 | 2019-11-01 |
| 2 | 2020-07-15 |
rides:
| ride_id | user_id | requested_at |
|---------|---------|--------------|
| 21 | 500 | 2020-07-01 |
| 22 | 501 | 2020-07-20 |
| 23 | 502 | 2020-07-22 |
accepted_rides:
| ride_id | driver_id | ride_distance | ride_duration |
|---------|-----------|---------------|---------------|
| 21 | 2 | 10 | 20 |
| 22 | 2 | 4 | 9 |
| 23 | 1 | 8 | 14 |[
{"month":1,"working_percentage":0.0},
{"month":2,"working_percentage":0.0},
{"month":3,"working_percentage":0.0},
{"month":4,"working_percentage":0.0},
{"month":5,"working_percentage":0.0},
{"month":6,"working_percentage":0.0},
{"month":7,"working_percentage":100.0},
{"month":8,"working_percentage":0.0},
{"month":9,"working_percentage":0.0},
{"month":10,"working_percentage":0.0},
{"month":11,"working_percentage":0.0},
{"month":12,"working_percentage":0.0}
]For July, both drivers are available by month end. Ride 21 is ignored for driver 2 because it is before that driver's join_date. Rides 22 and 23 make both drivers working in July, giving 2/2 = 100.00.
Constraints