Add deck-specific limits to DeckNormal

This commit is contained in:
RumovZ 2022-07-08 20:52:06 +02:00
parent 9dcceff4af
commit e907ca220c
3 changed files with 33 additions and 15 deletions

View file

@ -69,8 +69,10 @@ message Deck {
uint32 extend_review = 3;
string description = 4;
bool markdown_description = 5;
optional uint32 review_limit = 6;
optional uint32 new_limit = 7;
reserved 6 to 11;
reserved 8 to 11;
}
message Filtered {
message SearchTerm {

View file

@ -5,7 +5,7 @@ use std::{collections::HashMap, iter::Peekable};
use id_tree::{InsertBehavior, Node, NodeId, Tree};
use super::Deck;
use super::{Deck, NormalDeck};
use crate::{
deckconfig::{DeckConfig, DeckConfigId},
prelude::*,
@ -19,19 +19,33 @@ pub(crate) struct RemainingLimits {
impl RemainingLimits {
pub(crate) fn new(deck: &Deck, config: Option<&DeckConfig>, today: u32, v3: bool) -> Self {
config
.map(|config| {
if let Ok(normal) = deck.normal() {
if let Some(config) = config {
return Self::new_for_normal_deck(deck, today, v3, normal, config);
}
}
Self::default()
}
fn new_for_normal_deck(
deck: &Deck,
today: u32,
v3: bool,
normal: &NormalDeck,
config: &DeckConfig,
) -> RemainingLimits {
let review_limit = normal.review_limit.unwrap_or(config.inner.reviews_per_day);
let new_limit = normal.new_limit.unwrap_or(config.inner.new_per_day);
let (new_today, mut rev_today) = deck.new_rev_counts(today);
if v3 {
// any reviewed new cards contribute to the review limit
rev_today += new_today;
}
RemainingLimits {
review: ((config.inner.reviews_per_day as i32) - rev_today).max(0) as u32,
new: ((config.inner.new_per_day as i32) - new_today).max(0) as u32,
Self {
review: (review_limit as i32 - rev_today).max(0) as u32,
new: (new_limit as i32 - new_today).max(0) as u32,
}
})
.unwrap_or_default()
}
pub(crate) fn cap_to(&mut self, limits: RemainingLimits) {

View file

@ -298,6 +298,8 @@ impl From<NormalDeckSchema11> for NormalDeck {
extend_review: deck.extend_rev.max(0) as u32,
markdown_description: deck.common.markdown_description,
description: deck.common.desc,
review_limit: None,
new_limit: None,
}
}
}