mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
Display median ease in Stats instead of mean
This commit is contained in:
parent
595c255ca3
commit
fc6103ddda
1 changed files with 21 additions and 12 deletions
|
@ -10,37 +10,46 @@ impl GraphsContext {
|
||||||
/// (SM-2, FSRS)
|
/// (SM-2, FSRS)
|
||||||
pub(super) fn eases(&self) -> (Eases, Eases) {
|
pub(super) fn eases(&self) -> (Eases, Eases) {
|
||||||
let mut eases = Eases::default();
|
let mut eases = Eases::default();
|
||||||
let mut card_with_ease_count: usize = 0;
|
let mut ease_values = Vec::new();
|
||||||
let mut difficulty = Eases::default();
|
let mut difficulty = Eases::default();
|
||||||
let mut card_with_difficulty_count: usize = 0;
|
let mut difficulty_values = Vec::new();
|
||||||
for card in &self.cards {
|
for card in &self.cards {
|
||||||
if let Some(state) = card.memory_state {
|
if let Some(state) = card.memory_state {
|
||||||
*difficulty
|
*difficulty
|
||||||
.eases
|
.eases
|
||||||
.entry(percent_to_bin(state.difficulty() * 100.0))
|
.entry(percent_to_bin(state.difficulty() * 100.0))
|
||||||
.or_insert_with(Default::default) += 1;
|
.or_insert_with(Default::default) += 1;
|
||||||
difficulty.average += state.difficulty();
|
difficulty_values.push(state.difficulty());
|
||||||
card_with_difficulty_count += 1;
|
|
||||||
} else if matches!(card.ctype, CardType::Review | CardType::Relearn) {
|
} else if matches!(card.ctype, CardType::Review | CardType::Relearn) {
|
||||||
*eases
|
*eases
|
||||||
.eases
|
.eases
|
||||||
.entry((card.ease_factor / 10) as u32)
|
.entry((card.ease_factor / 10) as u32)
|
||||||
.or_insert_with(Default::default) += 1;
|
.or_insert_with(Default::default) += 1;
|
||||||
eases.average += card.ease_factor as f32;
|
ease_values.push(card.ease_factor as f32);
|
||||||
card_with_ease_count += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if card_with_ease_count != 0 {
|
|
||||||
eases.average = eases.average / 10.0 / card_with_ease_count as f32;
|
eases.average = median(&mut ease_values) / 10.0;
|
||||||
}
|
difficulty.average = median(&mut difficulty_values) * 100.0;
|
||||||
if card_with_difficulty_count != 0 {
|
|
||||||
difficulty.average = difficulty.average * 100.0 / card_with_difficulty_count as f32;
|
|
||||||
}
|
|
||||||
|
|
||||||
(eases, difficulty)
|
(eases, difficulty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper function to calculate the median of a vector
|
||||||
|
fn median(data: &mut Vec<f32>) -> f32 {
|
||||||
|
if data.is_empty() {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
data.sort_by(|a, b| a.partial_cmp(b).unwrap());
|
||||||
|
let mid = data.len() / 2;
|
||||||
|
if data.len() % 2 == 0 {
|
||||||
|
(data[mid - 1] + data[mid]) / 2.0
|
||||||
|
} else {
|
||||||
|
data[mid]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Bins the number into a bin of 0, 5, .. 95
|
/// Bins the number into a bin of 0, 5, .. 95
|
||||||
pub(super) fn percent_to_bin(x: f32) -> u32 {
|
pub(super) fn percent_to_bin(x: f32) -> u32 {
|
||||||
if x == 100.0 {
|
if x == 100.0 {
|
||||||
|
|
Loading…
Reference in a new issue