mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Move some methods into decks/counts.rs
This commit is contained in:
parent
9dac8e2b5f
commit
d2337e4cd3
2 changed files with 28 additions and 25 deletions
|
@ -1,7 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
use crate::{
|
||||||
use crate::{collection::Collection, decks::DeckId, error::Result};
|
backend_proto as pb, collection::Collection, decks::DeckId, error::Result, prelude::*,
|
||||||
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -11,6 +12,18 @@ pub(crate) struct DueCounts {
|
||||||
pub learning: u32,
|
pub learning: 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 {
|
impl Collection {
|
||||||
/// Get due counts for decks at the given timestamp.
|
/// Get due counts for decks at the given timestamp.
|
||||||
pub(crate) fn due_counts(
|
pub(crate) fn due_counts(
|
||||||
|
@ -26,4 +39,17 @@ impl Collection {
|
||||||
limit_to,
|
limit_to,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn counts_for_deck_today(
|
||||||
|
&mut self,
|
||||||
|
did: DeckId,
|
||||||
|
) -> Result<pb::CountsForDeckTodayOut> {
|
||||||
|
let today = self.current_due_day(0)?;
|
||||||
|
let mut deck = self.storage.get_deck(did)?.ok_or(AnkiError::NotFound)?;
|
||||||
|
deck.reset_stats_if_day_changed(today);
|
||||||
|
Ok(pb::CountsForDeckTodayOut {
|
||||||
|
new: deck.common.new_studied,
|
||||||
|
review: deck.common.review_studied,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,16 +125,6 @@ impl Deck {
|
||||||
self.usn = usn;
|
self.usn = usn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rendered_description(&self) -> String {
|
pub fn rendered_description(&self) -> String {
|
||||||
if let DeckKind::Normal(normal) = &self.kind {
|
if let DeckKind::Normal(normal) = &self.kind {
|
||||||
if normal.markdown_description {
|
if normal.markdown_description {
|
||||||
|
@ -239,19 +229,6 @@ impl Collection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn counts_for_deck_today(
|
|
||||||
&mut self,
|
|
||||||
did: DeckId,
|
|
||||||
) -> Result<pb::CountsForDeckTodayOut> {
|
|
||||||
let today = self.current_due_day(0)?;
|
|
||||||
let mut deck = self.storage.get_deck(did)?.ok_or(AnkiError::NotFound)?;
|
|
||||||
deck.reset_stats_if_day_changed(today);
|
|
||||||
Ok(pb::CountsForDeckTodayOut {
|
|
||||||
new: deck.common.new_studied,
|
|
||||||
review: deck.common.review_studied,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_deck_stats_single<F>(
|
fn update_deck_stats_single<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
today: u32,
|
today: u32,
|
||||||
|
|
Loading…
Reference in a new issue