0

We have millions of drivers earning tips. A driver can choose to get notified about their tips earned hourly, or every 6-hours, or every 12-hours, or daily. Essentially, we can have 4 time windows to aggregate driver tips by (1, 6, 12 and 24). A driver can fall into one of those windows.

Data Model

{drive_id, driver_id, aggregation_window_preference, tip_earned}

Sample Input:

Time: 00:00 - {drive_id: 1, driver_id: d1, aggregation_window_preference: 6, tip_earned: 1.00}
Time: 00:15 - {drive_id: 2, driver_id: d2, aggregation_window_preference: 12, tip_earned: 3.00}
Time: 07:00 - {drive_id: 3, driver_id: d1, aggregation_window_preference: 6, tip_earned: 2.00}
Time: 07:15 - {drive_id: 4, driver_id: d3, aggregation_window_preference: 24, tip_earned: 4.00}
Time: 08:00 - {drive_id: 5, driver_id: d3, aggregation_window_preference: 24, tip_earned: 1.00}
Time: 08:30 - {drive_id: 6, driver_id: d2, aggregation_window_preference: 12, tip_earned: 2.00}
Time: 09:00 - {drive_id: 7, driver_id: d2, aggregation_window_preference: 12, tip_earned: 3.00}
Time: 10:30 - {drive_id: 8, driver_id: d1, aggregation_window_preference: 6, tip_earned: 1.00}

Sample Output

Time: 06:00 - {driver_id: 1, tips_earned: 1.00}

Time: 12:00 - {driver_id: 1, tips_earned: 3.00}

Time: 12:00 - {driver_id: 2, tips_earned: 8.00}

Time: 24:00 - {driver_id: 3, tips_earned: 5.00}

I realize that problem that I am trying to solve is pretty much similar to this stackoverflow post.

What makes this question a bit different is -

  1. The answer aggregates tips by multiple windows. Drivers fall into disjoint time windows. For example - driver, d3, needs to be notified only every 24 hours. How do we ensure that a driver d3 is NOT notified hourly, every 6 hours, or every 12-hours?

Thanks!

My question is an extension to this question https://stackoverflow.com/a/71833148/21061133. I tried searching stackoverflow but did not find an answer that solves my problem.

0 Answers0