-
Notifications
You must be signed in to change notification settings - Fork 28
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
sim-lib: Allows amount and interval ranges in manual activity definition #153
sim-lib: Allows amount and interval ranges in manual activity definition #153
Conversation
I think that we should get some refactoring in before we make this type of change.
|
Sure, no rush on my end |
cc19a99
to
ec8670c
Compare
ec8670c
to
fe7bef6
Compare
sim-lib/src/defined_activity.rs
Outdated
@@ -37,7 +39,11 @@ impl DestinationGenerator for DefinedPaymentActivity { | |||
|
|||
impl PaymentGenerator for DefinedPaymentActivity { | |||
fn next_payment_wait(&self) -> Duration { | |||
self.wait | |||
let wait = Duration::from_secs(self.wait.value() as u64); |
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.
This is the only bit I'm not super happy about, given we'll be building a Duration
object every time we call next_payment_wait
, even for fixed wait payments. However, changing this would imply changing the generic for ValueOrRange, and I think potentially more code bolilerplate.
I don't think this is too bad, but I'm open to change it if you find it is.
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.
We could have a RangePaymentActivity
impl of PaymentGenerator
which deals exclusively with the range case?
We can stil parse everything as-is here, but then create either RangePaymentActivity
or DefinedPaymentActivity
when we switch over from ActiviyParser
-> ActivityDefinition
. Might cause a little bit of trait object agony in main
, but we should be mostly okay in lib
🤞
That might also be quite boiler-platey, but could be worth considering!
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 don't know if that would be even more complex.
We have two fields that can be either a range or a value (but only one of them has the initialization issue), how do we deal with the combination of these?
DefinedPaymentActivity
would need to have wait: Duration, amount: ValueOrRange<u64>
while RangePaymentActivity
would have wait: ValueOrRange<u16>, amount: ValueOrRange<u64>
. That's really counterintuitive. The alternative would be to only allow either both or none to be ranges, but that's limiting the functionality.
None of the solutions I've been trying to come up with have been satisfying for one reason or another (nor even having a two-argument generic, since deserialization becomes a mess). I've been checking the constructor of Duration
and, honestly, it doesn't look that bad (specially considering that we are constructing with nanos=0
): https://doc.rust-lang.org/src/core/time.rs.html#199-207
So I would bite the bullet with this one, but I'm happy to be convinced of an alternative solution if you could find something I'm missing
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.
Managed to completely miss this comment - sorry!!
DefinedPaymentActivity would need to have wait: Duration, amount: ValueOrRange while RangePaymentActivity would have wait: ValueOrRange, amount: ValueOrRange. That's really counterintuitive. The alternative would be to only allow either both or none to be ranges, but that's limiting the functionality.
Good point, didn't think about the inbetween case where we only want a range for one of them! Agreed, let's just go ahead w/ what we have here.
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.
np, I'll update it with the most recent comments
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.
Thanks for picking this one back up!
sim-lib/src/defined_activity.rs
Outdated
@@ -37,7 +39,11 @@ impl DestinationGenerator for DefinedPaymentActivity { | |||
|
|||
impl PaymentGenerator for DefinedPaymentActivity { | |||
fn next_payment_wait(&self) -> Duration { | |||
self.wait | |||
let wait = Duration::from_secs(self.wait.value() as u64); |
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.
We could have a RangePaymentActivity
impl of PaymentGenerator
which deals exclusively with the range case?
We can stil parse everything as-is here, but then create either RangePaymentActivity
or DefinedPaymentActivity
when we switch over from ActiviyParser
-> ActivityDefinition
. Might cause a little bit of trait object agony in main
, but we should be mostly okay in lib
🤞
That might also be quite boiler-platey, but could be worth considering!
fe7bef6
to
3cb1443
Compare
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.
3cb1443
to
a6c40a4
Compare
CI failure is unrelated |
Fixed in #186. Also is this ready for a look? |
Amounts and intervals in activities can now be fixed values (e.g. 1000) or ranges (e.g. [500, 1000]). If a range is provided, the value will be sampled uniformly at random from it.
a6c40a4
to
f1a3275
Compare
Rebased to make CI green again. This should be review-ready. |
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.
tACK, such a nice feature to add 😻
use super::DefinedPaymentActivity; | ||
use super::*; |
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.
nit: can remove DefinedPaymentActivity
if we're using *
Values in activities can now be fixed values (e.g. 1000) or ranges (e.g. [500, 1000]).
If a range is provided, the value will be sampled uniformly at random from it.
Close #43