Skip to content

Commit

Permalink
rename function and handle div by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinquaXD committed Jan 3, 2025
1 parent e732c6f commit b3cadea
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/driver/src/domain/competition/bad_tokens/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ impl Detector {
return None;
}

let is_unsupported = self.stats_indicates_unsupported(&stats);
let is_unsupported = self.stats_indicate_unsupported(&stats);
(!self.log_only && is_unsupported).then_some(Quality::Unsupported)
}

fn stats_indicates_unsupported(&self, stats: &TokenStatistics) -> bool {
let token_failure_ratio = stats.fails as f64 / stats.attempts as f64;
fn stats_indicate_unsupported(&self, stats: &TokenStatistics) -> bool {
let token_failure_ratio = match stats.attempts {
0 => return false,
attempts => f64::from(stats.fails) / f64::from(attempts)
};
stats.attempts >= self.required_measurements && token_failure_ratio >= self.failure_ratio
}

Expand Down Expand Up @@ -93,7 +96,7 @@ impl Detector {
});

// token neeeds to be frozen as unsupported for a while
if self.stats_indicates_unsupported(&stats)
if self.stats_indicate_unsupported(&stats)
&& stats
.flagged_unsupported_at
.is_none_or(|t| now.duration_since(t) > self.token_freeze_time)
Expand Down

0 comments on commit b3cadea

Please sign in to comment.