Remove EaseKind impl in favor of transforming to sql in function

This commit is contained in:
Henrik Giesel 2021-01-11 17:10:17 +01:00
parent cbfe14ef4f
commit 7a7152fe27
5 changed files with 16 additions and 22 deletions

View File

@ -37,7 +37,7 @@ use crate::{
sched::timespan::{answer_button_time, time_span},
search::{
concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes,
BoolSeparator, Node, SearchNode, SortMode, StateKind, TemplateKind,
BoolSeparator, EaseKind, Node, SearchNode, SortMode, StateKind, TemplateKind,
},
stats::studied_today,
sync::{
@ -292,11 +292,11 @@ impl From<pb::FilterToSearchIn> for Node<'_> {
NamedFilter::AddedToday => Node::Search(SearchNode::AddedInDays(1)),
NamedFilter::StudiedToday => Node::Search(SearchNode::Rated {
days: 1,
ease: None,
ease: EaseKind::Reviewed,
}),
NamedFilter::AgainToday => Node::Search(SearchNode::Rated {
days: 1,
ease: Some(1),
ease: EaseKind::Rated(1),
}),
NamedFilter::New => Node::Search(SearchNode::State(StateKind::New)),
NamedFilter::Learn => Node::Search(SearchNode::State(StateKind::Learning)),

View File

@ -5,7 +5,7 @@ mod sqlwriter;
mod writer;
pub use cards::SortMode;
pub use parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind};
pub use parser::{EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind};
pub use writer::{
concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes,
BoolSeparator,

View File

@ -119,24 +119,12 @@ pub enum TemplateKind<'a> {
}
#[derive(Debug, PartialEq, Clone)]
pub(super) enum EaseKind {
pub enum EaseKind {
Rated(u8),
Reviewed,
Manually,
}
impl std::fmt::Display for EaseKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use EaseKind::*;
match self {
Rated(u) => write!(f, " and ease = {}", u),
Reviewed => write!(f, " and ease in (1, 2, 3, 4)"),
Manually => write!(f, " and ease = 0"),
}
}
}
/// Parse the input string into a list of nodes.
pub(super) fn parse(input: &str) -> Result<Vec<Node>> {
let input = input.trim();
@ -383,7 +371,7 @@ fn parse_rated(val: &str) -> ParseResult<SearchNode<'static>> {
if (1..5).contains(&u) {
EaseKind::Rated(u)
} else {
return Err(ParseError {})
return Err(ParseError {});
}
}
None => EaseKind::Reviewed,

View File

@ -1,7 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use super::parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind, EaseKind};
use super::parser::{EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind};
use crate::{
card::{CardQueue, CardType},
collection::Collection,
@ -219,12 +219,18 @@ impl SqlWriter<'_> {
let target_cutoff_ms = (today_cutoff - 86_400 * i64::from(days)) * 1_000;
write!(
self.sql,
"c.id in (select cid from revlog where id>{}{})",
"c.id in (select cid from revlog where id>{}",
target_cutoff_ms,
ease,
)
.unwrap();
match ease {
EaseKind::Rated(u) => write!(self.sql, " and ease = {})", u),
EaseKind::Reviewed => write!(self.sql, " and ease in (1, 2, 3, 4))"),
EaseKind::Manually => write!(self.sql, " and ease = 0)"),
}
.unwrap();
Ok(())
}

View File

@ -5,7 +5,7 @@ use crate::{
decks::DeckID as DeckIDType,
err::Result,
notetype::NoteTypeID as NoteTypeIDType,
search::parser::{parse, Node, PropertyKind, SearchNode, StateKind, TemplateKind, EaseKind},
search::parser::{parse, EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind},
};
use itertools::Itertools;
use std::mem;