-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tiered Dwell Time with Rates #658
Changes from all commits
f6142d4
864bdc6
f3b9017
c0d407f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"updated": 0, | ||
"version": "1.2.0", | ||
"data": { | ||
"policy": [ | ||
{ | ||
"name": "Tiered Dwell Time Example", | ||
"description": "First hour $2, second hour $4, every hour onwards $10", | ||
"policy_id": "2800cd0a-7827-4110-9713-b9e5bf29e9a1", | ||
"start_date": 1558389669540, | ||
"publish_date": 1558389669540, | ||
"end_date": null, | ||
"prev_policies": null, | ||
"provider_ids": [], | ||
"currency": "USD", | ||
"rules": [ | ||
{ | ||
"name": "> 2 hours", | ||
"rule_id": "9cd1768c-ab9e-484c-93f8-72a7078aa7b9", | ||
"rule_type": "time", | ||
"rule_units": "hours", | ||
"geographies": ["0c77c813-bece-4e8a-84fd-f99af777d198"], | ||
"statuses": { "available": [], "non_operational": [] }, | ||
"vehicle_types": ["bicycle", "scooter"], | ||
"maximum": 2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maximum in this case would be "If a vehicle surpasses this maximum, it's matched by this rule". Similarly, a minimum would be "If a vehicle is under this minimum, it's matched by this rule". I can't think of any good real You can think of the matching along the lines of:
|
||
"rate_amount": 1000, | ||
"rate_recurrence": "each_time_unit" | ||
}, | ||
{ | ||
"name": "1-2 Hours", | ||
"rule_id": "edd6a195-bb30-4eb5-a2cc-44e5a18798a2", | ||
"rule_type": "time", | ||
"rule_units": "hours", | ||
"geographies": ["0c77c813-bece-4e8a-84fd-f99af777d198"], | ||
"statuses": { "available": [], "non_operational": [] }, | ||
"vehicle_types": ["bicycle", "scooter"], | ||
"maximum": 1, | ||
"rate_amount": 400, | ||
"rate_recurrence": "each_time_unit" | ||
}, | ||
{ | ||
"name": "0-1 Hour", | ||
"rule_id": "6b6fe61b-dbe5-4367-8e35-84fb14d23c54", | ||
"rule_type": "time", | ||
"rule_units": "hours", | ||
"geographies": ["0c77c813-bece-4e8a-84fd-f99af777d198"], | ||
"statuses": { "available": [], "non_operational": [] }, | ||
"vehicle_types": ["bicycle", "scooter"], | ||
"maximum": 0, | ||
"rate_amount": 200, | ||
"rate_recurrence": "each_time_unit" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"updated": 0, | ||
"version": "1.2.0", | ||
"data": { | ||
"policy": [ | ||
{ | ||
"name": "Tiered Dwell Time Example", | ||
"description": "If parked for <1hr $2 upon exit, if parked for 1-2 hours $4 upon exit, if parked for longer than 2 hours $10 upon exit", | ||
"policy_id": "2800cd0a-7827-4110-9713-b9e5bf29e9a1", | ||
"start_date": 1558389669540, | ||
"publish_date": 1558389669540, | ||
"end_date": null, | ||
"prev_policies": null, | ||
"provider_ids": [], | ||
"currency": "USD", | ||
"rules": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to make sure I understand the process for interpreting these rules, so I'm going to walk through an example. Let's say we have a 1.25 hour long parking event. The total charge for that under this policy would be $4. So the excruciatingly detailed process for calculating that would be:
Does that all seem right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All sounds right to me! Short-circuiting should behave exactly how you described. |
||
{ | ||
"name": "> 2 hours", | ||
"rule_id": "9cd1768c-ab9e-484c-93f8-72a7078aa7b9", | ||
"rule_type": "time", | ||
"rule_units": "hours", | ||
"geographies": ["0c77c813-bece-4e8a-84fd-f99af777d198"], | ||
"statuses": { "available": [], "non_operational": [] }, | ||
"vehicle_types": ["bicycle", "scooter"], | ||
"maximum": 2, | ||
"rate_amount": 1000, | ||
"rate_recurrence": "once_on_unmatch" | ||
}, | ||
{ | ||
"name": "1-2 Hours", | ||
"rule_id": "edd6a195-bb30-4eb5-a2cc-44e5a18798a2", | ||
"rule_type": "time", | ||
"rule_units": "hours", | ||
"geographies": ["0c77c813-bece-4e8a-84fd-f99af777d198"], | ||
"statuses": { "available": [], "non_operational": [] }, | ||
"vehicle_types": ["bicycle", "scooter"], | ||
"maximum": 1, | ||
"rate_amount": 400, | ||
"rate_recurrence": "once_on_unmatch" | ||
}, | ||
{ | ||
"name": "0-1 Hour", | ||
"rule_id": "6b6fe61b-dbe5-4367-8e35-84fb14d23c54", | ||
"rule_type": "time", | ||
"rule_units": "hours", | ||
"geographies": ["0c77c813-bece-4e8a-84fd-f99af777d198"], | ||
"statuses": { "available": [], "non_operational": [] }, | ||
"vehicle_types": ["bicycle", "scooter"], | ||
"maximum": 0, | ||
"rate_amount": 200, | ||
"rate_recurrence": "once_on_unmatch" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure I understand the process for interpreting these rules, so I'm going to walk through an example. Let's say we have a 6.1 hour long parking event. The total charge for that under this policy as I understand it would be 2 + 4 + 10 * 5 = $56, right?
So the excruciatingly detailed process for calculating that would be:
each_time_unit
rule, so I need to figure out how many units of time to apply it tomaximum
of 2 and my event is longer than that, so this rule applies to my eventmaximum
of 2 so I subtract 2 from 6.1 to get 4.1 hours of this event this rule applies tomaximum
describes these last two operations, hoping for some clarification on thateach_time_unit
rules are always applied to whole time units, never fractional, so I round 4.1 up to 5 to get the total number of hours used to calculate this portion of the chargerate_amount
for this rule is 1000, I multiple 5 hours * 1000 = 5000 cents = $50maximum
field, meaning the first 2 hours. I replace my original parking event with one that is 2 hours long as I head to the next rule. This is standard practice foreach_time_unit
rules.each_time_unit
rule, so I need to figure out how many units of time to apply it tomaximum
of 1 and my event is longer than that, so this rule applies to my eventmaximum
of 1 so I subtract 1 from 2 to get 1 hour of this event this rule applies toeach_time_unit
rules are always applied to whole time units, never fractional, so I round 1 up to 1 to get the total number of hours used to calculate this portion of the charge (hoping there's no floating point issues causing the rounding to go to 2)rate_amount
for this rule is 400, I multiple 1 hour * 400 = 400 cents = $4maximum
field, meaning the first 1 hour. I replace my original parking event with one that is 1 hour long as I head to the next rule.each_time_unit
rule, so I need to figure out how many units of time to apply it tomaximum
of 0 and my event is longer than that, so this rule applies to my eventmaximum
of 0 so I subtract 0 from 1 to get 1 hour of this event this rule applies toeach_time_unit
rules are always applied to whole time units, never fractional, so I round 1 up to 1 to get the total number of hours used to calculate this portion of the charge (hoping there's no floating point issues causing the rounding to go to 2)rate_amount
for this rule is 200, I multiple 1 hour * 200 = 200 cents = $2maximum
field, meaning 0 hours.Does that seem right? If one of these rules had a
minimum
field, how would that factor in?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the methodology you described functionally works how I'd expect at the end of the day, and the logic checks out! However, I have perhaps a slightly more intuitive way of thinking about it. The most intuitive way I can think of evaluating policies with rates that specify
each_time_unit
, is by treatingeach_time_unit
tick as an event (note, not an MDS event, more of an event-driven-system kind of event). This would enable continuous charging throughout the duration of the parking, as opposed to waiting till the absolute duration of the park has been completed.Let's, for the sake of making this a bit easier to reason about, assume that the
time_unit
for each rule is the same, so we can evaluate the whole policy at once every hour on the dot. Because this iseach_time_unit
instead ofeach_complete_time_unit
, we will evaluate on first entry in addition to after each hour ticks.Continuous(ish) Evaluation Methodology for this Policy
I'm gonna approach this with some brevity here, but if you'd like me to dial into some more detail please let me know and I'm happy to!
@00:00 (right when first parked)
@01:00
@02:00
@03:00
@04:00
@05:00
@06:00
At the end of the day, there will be a charge for $2 + $4 + $10 + $10 + $10 + $10 + $10 = $56.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order for this to work the the comparison to
maximum
looks like it needs to be>=
? And same forminimum
?If you did have different units in the rules would you pre-process the rules into the same units in order to figure out your clock-ticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
>=
for maximums, and similarly<=
for minimums I think (let me update my other comment, I think I didn't include the=
component).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I had different units on the rules I'd probably specify an interval to re-evaluate of the lowest-duration unit referenced (e.g. if there were some rules with minutes and some with hours, I'd evaluate on a minutely basis). I'd then probably add some logic to ensure that double-fees won't get charged if a high-duration rule is hit again within that unit of its last occurrence, and instead results in a short-circuit without a charge.