diff --git a/src/crawler.rs b/src/crawler.rs index 6742eb0d..059f4d49 100644 --- a/src/crawler.rs +++ b/src/crawler.rs @@ -230,7 +230,7 @@ impl Crawler { last_battle_time: Some(account_info.last_battle_time), partial_tank_stats, prio: false, - next_check_at: Some(NextCheckAt::from(account_info.last_battle_time).into()), + next_check_at: Some(NextCheckAt::new(account_info.last_battle_time).into()), }; let account_snapshot = database::AccountSnapshot::new(self.realm, &account_info, tank_last_battle_times); diff --git a/src/crawler/next_check_at.rs b/src/crawler/next_check_at.rs index a7968007..67b34128 100644 --- a/src/crawler/next_check_at.rs +++ b/src/crawler/next_check_at.rs @@ -3,25 +3,30 @@ use rand_distr::Exp1; use crate::prelude::*; -pub struct NextCheckAt(DateTime); - -impl NextCheckAt { - const MAX_EXP1_SAMPLE: f64 = 4.0; +pub struct NextCheckAt { + last_battle_time: DateTime, + offset: f64, + scale: f64, + max_exp1: f64, } -impl From for NextCheckAt { - fn from(last_battle_time: DateTime) -> Self { - let elapsed_secs = (now() - last_battle_time).num_seconds() as f64; - let sample = thread_rng() - .sample::(Exp1) - .min(Self::MAX_EXP1_SAMPLE); - let interval_secs = elapsed_secs * sample; - Self(last_battle_time + Duration::seconds(interval_secs as i64)) +impl NextCheckAt { + pub const fn new(last_battle_time: DateTime) -> Self { + Self { + last_battle_time, + offset: 0.0, + scale: 1.0, + max_exp1: 3.5, + } } } impl From for DateTime { - fn from(next_check_at: NextCheckAt) -> Self { - next_check_at.0 + fn from(this: NextCheckAt) -> Self { + let elapsed_secs = (now() - this.last_battle_time).num_seconds() as f64; + let sample = thread_rng().sample::(Exp1) * this.scale + this.offset; + let sample = sample.min(this.max_exp1); + let next_check_in = Duration::seconds((elapsed_secs * sample) as i64); + this.last_battle_time + next_check_in } }