This repository has been archived by the owner on Mar 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Trainer: try and set the
due
field on account
- Loading branch information
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use rand::prelude::*; | ||
use rand_distr::Exp1; | ||
|
||
use crate::prelude::*; | ||
|
||
pub struct NextCheckAt(DateTime); | ||
|
||
impl NextCheckAt { | ||
const MAX_EXP1_SAMPLE: f64 = 4.0; | ||
} | ||
|
||
impl From<DateTime> 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::<f64, _>(Exp1) | ||
.min(Self::MAX_EXP1_SAMPLE); | ||
let interval_secs = elapsed_secs * sample; | ||
Self(last_battle_time + Duration::seconds(interval_secs as i64)) | ||
} | ||
} | ||
|
||
impl From<NextCheckAt> for DateTime { | ||
fn from(next_check_at: NextCheckAt) -> Self { | ||
next_check_at.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters