Anki/rslib/src/decks/counts.rs
Abdo 5cde4b6941
Remove v1/v2 support from the backend (#2727)
* Remove v1/v2 support from deck list

* Remove v1/v2 support from most routines and show error

* Remove scheduler_version from preferences

* Fix formatting

* Remove v1/v2 conditionals from Python code

* Fix legacy importer

* Remove legacy hooks

* Add missing scheduler checks

* Remove V2 logic from deck options screen

* Remove the review_did_undo hook

* Restore ability to open old options with shift (dae)
2023-10-14 10:50:59 +10:00

53 lines
1.5 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::collections::HashMap;
use crate::prelude::*;
#[derive(Debug)]
pub(crate) struct DueCounts {
pub new: u32,
pub review: u32,
/// interday+intraday
pub learning: u32,
pub intraday_learning: u32,
pub interday_learning: u32,
pub total_cards: u32,
}
impl Deck {
/// Return the studied counts if studied today.
/// May be negative if user has extended limits.
pub(crate) fn new_rev_counts(&self, today: u32) -> (i32, i32) {
if self.common.last_day_studied == today {
(self.common.new_studied, self.common.review_studied)
} else {
(0, 0)
}
}
}
impl Collection {
/// Get due counts for decks at the given timestamp.
pub(crate) fn due_counts(
&mut self,
days_elapsed: u32,
learn_cutoff: u32,
) -> Result<HashMap<DeckId, DueCounts>> {
self.storage.due_counts(days_elapsed, learn_cutoff)
}
pub(crate) fn counts_for_deck_today(
&mut self,
did: DeckId,
) -> Result<anki_proto::scheduler::CountsForDeckTodayResponse> {
let today = self.current_due_day(0)?;
let mut deck = self.storage.get_deck(did)?.or_not_found(did)?;
deck.reset_stats_if_day_changed(today);
Ok(anki_proto::scheduler::CountsForDeckTodayResponse {
new: deck.common.new_studied,
review: deck.common.review_studied,
})
}
}