mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Add day limits to DeckNormal
This commit is contained in:
parent
40b0416461
commit
2ce1b313bf
4 changed files with 39 additions and 3 deletions
|
@ -64,6 +64,10 @@ message Deck {
|
||||||
bytes other = 255;
|
bytes other = 255;
|
||||||
}
|
}
|
||||||
message Normal {
|
message Normal {
|
||||||
|
message DayLimit {
|
||||||
|
uint32 limit = 1;
|
||||||
|
uint32 today = 2;
|
||||||
|
}
|
||||||
int64 config_id = 1;
|
int64 config_id = 1;
|
||||||
uint32 extend_new = 2;
|
uint32 extend_new = 2;
|
||||||
uint32 extend_review = 3;
|
uint32 extend_review = 3;
|
||||||
|
@ -71,8 +75,10 @@ message Deck {
|
||||||
bool markdown_description = 5;
|
bool markdown_description = 5;
|
||||||
optional uint32 review_limit = 6;
|
optional uint32 review_limit = 6;
|
||||||
optional uint32 new_limit = 7;
|
optional uint32 new_limit = 7;
|
||||||
|
DayLimit review_limit_today = 8;
|
||||||
|
DayLimit new_limit_today = 9;
|
||||||
|
|
||||||
reserved 8 to 11;
|
reserved 12 to 15;
|
||||||
}
|
}
|
||||||
message Filtered {
|
message Filtered {
|
||||||
message SearchTerm {
|
message SearchTerm {
|
||||||
|
|
|
@ -105,6 +105,7 @@ pub fn write_backend_proto_rs() {
|
||||||
"Deck.Filtered.SearchTerm.Order",
|
"Deck.Filtered.SearchTerm.Order",
|
||||||
"#[derive(strum::EnumIter)]",
|
"#[derive(strum::EnumIter)]",
|
||||||
)
|
)
|
||||||
|
.type_attribute("Deck.Normal.DayLimit", "#[derive(Copy)]")
|
||||||
.type_attribute("HelpPageLinkRequest.HelpPage", "#[derive(strum::EnumIter)]")
|
.type_attribute("HelpPageLinkRequest.HelpPage", "#[derive(strum::EnumIter)]")
|
||||||
.type_attribute("CsvMetadata.Delimiter", "#[derive(strum::EnumIter)]")
|
.type_attribute("CsvMetadata.Delimiter", "#[derive(strum::EnumIter)]")
|
||||||
.type_attribute(
|
.type_attribute(
|
||||||
|
|
|
@ -8,9 +8,32 @@ use id_tree::{InsertBehavior, Node, NodeId, Tree};
|
||||||
use super::{Deck, NormalDeck};
|
use super::{Deck, NormalDeck};
|
||||||
use crate::{
|
use crate::{
|
||||||
deckconfig::{DeckConfig, DeckConfigId},
|
deckconfig::{DeckConfig, DeckConfigId},
|
||||||
|
pb::decks::deck::normal::DayLimit,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
impl NormalDeck {
|
||||||
|
/// The deck's review limit for today or its general one, if any is configured.
|
||||||
|
pub fn day_review_limit(&self, today: u32) -> Option<u32> {
|
||||||
|
self.review_limit_today
|
||||||
|
.and_then(|day_limit| day_limit.limit(today))
|
||||||
|
.or(self.review_limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The deck's new limit for today or its general one, if any is configured.
|
||||||
|
pub fn day_new_limit(&self, today: u32) -> Option<u32> {
|
||||||
|
self.new_limit_today
|
||||||
|
.and_then(|day_limit| day_limit.limit(today))
|
||||||
|
.or(self.new_limit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DayLimit {
|
||||||
|
pub fn limit(&self, today: u32) -> Option<u32> {
|
||||||
|
(self.today == today).then(|| self.limit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub(crate) struct RemainingLimits {
|
pub(crate) struct RemainingLimits {
|
||||||
pub review: u32,
|
pub review: u32,
|
||||||
|
@ -34,8 +57,12 @@ impl RemainingLimits {
|
||||||
normal: &NormalDeck,
|
normal: &NormalDeck,
|
||||||
config: &DeckConfig,
|
config: &DeckConfig,
|
||||||
) -> RemainingLimits {
|
) -> RemainingLimits {
|
||||||
let review_limit = normal.review_limit.unwrap_or(config.inner.reviews_per_day);
|
let review_limit = normal
|
||||||
let new_limit = normal.new_limit.unwrap_or(config.inner.new_per_day);
|
.day_review_limit(today)
|
||||||
|
.unwrap_or(config.inner.reviews_per_day);
|
||||||
|
let new_limit = normal
|
||||||
|
.day_new_limit(today)
|
||||||
|
.unwrap_or(config.inner.new_per_day);
|
||||||
let (new_today, mut rev_today) = deck.new_rev_counts(today);
|
let (new_today, mut rev_today) = deck.new_rev_counts(today);
|
||||||
if v3 {
|
if v3 {
|
||||||
// any reviewed new cards contribute to the review limit
|
// any reviewed new cards contribute to the review limit
|
||||||
|
|
|
@ -306,6 +306,8 @@ impl From<NormalDeckSchema11> for NormalDeck {
|
||||||
description: deck.common.desc,
|
description: deck.common.desc,
|
||||||
review_limit: deck.review_limit,
|
review_limit: deck.review_limit,
|
||||||
new_limit: deck.new_limit,
|
new_limit: deck.new_limit,
|
||||||
|
review_limit_today: None,
|
||||||
|
new_limit_today: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue