Fix first_rating_count & learn_cost (#2688)

* fix first_rating_count & learn_cost

* Update CONTRIBUTORS

* cargo clippy --fix

* cargo fmt
This commit is contained in:
Jarrett Ye 2023-09-27 16:31:40 +08:00 committed by GitHub
parent d2f392ff9f
commit 05499297e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -138,7 +138,7 @@ Monty Evans <montyevans@gmail.com>
Nil Admirari <https://github.com/nihil-admirari>
Michael Winkworth <github.com/SteelColossus>
Mateusz Wojewoda <kawa1.11@o2.pl>
Jarrett Ye <jarrett.ye@outlook.com>
Jarrett Ye <jarrett.ye@outlook.com>
Sam Waechter <github.com/swektr>
Michael Eliachevitch <m.eliachevitch@posteo.de>

View File

@ -76,12 +76,15 @@ impl Collection {
let first_rating_count = revlogs
.iter()
.filter(|r| {
r.review_kind == RevlogReviewKind::Learning
&& r.last_interval == 0
&& r.button_chosen >= 1
.group_by(|r| r.cid)
.into_iter()
.map(|(_cid, group)| {
group
.into_iter()
.find(|r| r.review_kind == RevlogReviewKind::Learning && r.button_chosen >= 1)
})
.counts_by(|r| r.button_chosen);
.filter(|r| r.is_some())
.counts_by(|r| r.unwrap().button_chosen);
let total_first = first_rating_count.values().sum::<usize>() as f64;
let first_rating_prob = if total_first > 0.0 {
let mut arr = [0.0; 4];
@ -136,11 +139,10 @@ impl Collection {
let learn_cost = {
let revlogs_filter = revlogs
.iter()
.filter(|r| r.review_kind == RevlogReviewKind::Learning && r.last_interval == 0)
.filter(|r| r.review_kind == RevlogReviewKind::Learning && r.button_chosen >= 1)
.map(|r| r.taken_millis);
let count = revlogs_filter.clone().count() as f64;
if count > 0.0 {
revlogs_filter.sum::<u32>() as f64 / count / 1000.0
if total_first > 0.0 {
revlogs_filter.sum::<u32>() as f64 / total_first / 1000.0
} else {
return Err(AnkiError::FsrsInsufficientData);
}