pub fn calculate_confidence(highest_score: f64, second_score: f64, count: usize) -> f64 {
if highest_score == 0.0 {
return 0.0;
}
if second_score == 0.0 {
return highest_score;
}
debug_assert!(highest_score <= 1.0);
debug_assert!(highest_score >= 0.0);
debug_assert!(second_score <= 1.0);
debug_assert!(second_score >= 0.0);
let confident_rate = (3.0 / count as f64) + 0.015;
let rate = (highest_score - second_score) / second_score;
if rate > confident_rate {
1.0
} else {
rate / confident_rate
}
}