Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort FSRSItems by RevlogId for training #3660

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ git = "https://github.com/ankitects/linkcheck.git"
rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca"

[workspace.dependencies.fsrs]
version = "=1.4.7"
version = "=1.5.0"
# git = "https://github.com/open-spaced-repetition/fsrs-rs.git"
# rev = "58ca25ed2bc4bb1dc376208bbcaed7f5a501b941"
# path = "../open-spaced-repetition/fsrs-rs"
Expand Down
2 changes: 1 addition & 1 deletion cargo/licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@
},
{
"name": "fsrs",
"version": "1.4.7",
"version": "1.5.0",
"authors": "Open Spaced Repetition",
"repository": "https://github.com/open-spaced-repetition/fsrs-rs",
"license": "BSD-3-Clause",
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/fsrs/memory_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub(crate) fn fsrs_item_for_memory_state(
ease_factor: f32,
}
if let Some(mut output) = reviews_for_fsrs(entries, next_day_at, false, ignore_revlogs_before) {
let mut item = output.fsrs_items.pop().unwrap();
let mut item = output.fsrs_items.pop().unwrap().1;
if output.revlogs_complete {
Ok(Some(FsrsItemForMemoryState {
item,
Expand Down
17 changes: 10 additions & 7 deletions rslib/src/scheduler/fsrs/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ fn fsrs_items_for_training(
i.fsrs_items
})
.collect_vec();
revlogs.sort_by_cached_key(|r| r.reviews.len());
// Sort by RevlogId
revlogs.sort_by_key(|(revlog_id, _)| revlog_id.0);
// Extract only the FSRSItems after sorting
let revlogs = revlogs.into_iter().map(|(_, item)| item).collect_vec();
(revlogs, review_count)
}

Expand All @@ -246,7 +249,7 @@ pub(crate) struct ReviewsForFsrs {
/// review entries prior to a card being reset).
pub filtered_revlogs: Vec<RevlogEntry>,
/// FSRS items derived from the filtered revlogs.
pub fsrs_items: Vec<FSRSItem>,
pub fsrs_items: Vec<(RevlogId, FSRSItem)>,
/// True if there is enough history to derive memory state from history
/// alone. If false, memory state will be derived from SM2.
pub revlogs_complete: bool,
Expand Down Expand Up @@ -360,11 +363,11 @@ pub(crate) fn reviews_for_fsrs(
let skip = if training { 1 } else { 0 };
// Convert the remaining entries into separate FSRSItems, where each item
// contains all reviews done until then.
let items: Vec<FSRSItem> = entries
let items: Vec<(RevlogId, FSRSItem)> = entries
.iter()
.enumerate()
.skip(skip)
.map(|(outer_idx, _)| {
.map(|(outer_idx, entry)| {
let reviews = entries
.iter()
.take(outer_idx + 1)
Expand All @@ -374,9 +377,9 @@ pub(crate) fn reviews_for_fsrs(
delta_t: delta_ts[inner_idx],
})
.collect();
FSRSItem { reviews }
(entry.id, FSRSItem { reviews })
})
.filter(|item| !training || item.reviews.last().unwrap().delta_t > 0)
.filter(|(_, item)| !training || item.reviews.last().unwrap().delta_t > 0)
.collect_vec();
if items.is_empty() {
None
Expand Down Expand Up @@ -445,7 +448,7 @@ pub(crate) mod tests {
ignore_before: TimestampMillis,
) -> Option<Vec<FSRSItem>> {
reviews_for_fsrs(revlog.to_vec(), NEXT_DAY_AT, training, ignore_before)
.map(|i| i.fsrs_items)
.map(|i| i.fsrs_items.into_iter().map(|(_, item)| item).collect_vec())
}

pub(crate) fn convert(revlog: &[RevlogEntry], training: bool) -> Option<Vec<FSRSItem>> {
Expand Down