Remove EaseKind impl in favor of transforming to sql in function
This commit is contained in:
parent
cbfe14ef4f
commit
7a7152fe27
@ -37,7 +37,7 @@ use crate::{
|
|||||||
sched::timespan::{answer_button_time, time_span},
|
sched::timespan::{answer_button_time, time_span},
|
||||||
search::{
|
search::{
|
||||||
concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes,
|
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,
|
stats::studied_today,
|
||||||
sync::{
|
sync::{
|
||||||
@ -292,11 +292,11 @@ impl From<pb::FilterToSearchIn> for Node<'_> {
|
|||||||
NamedFilter::AddedToday => Node::Search(SearchNode::AddedInDays(1)),
|
NamedFilter::AddedToday => Node::Search(SearchNode::AddedInDays(1)),
|
||||||
NamedFilter::StudiedToday => Node::Search(SearchNode::Rated {
|
NamedFilter::StudiedToday => Node::Search(SearchNode::Rated {
|
||||||
days: 1,
|
days: 1,
|
||||||
ease: None,
|
ease: EaseKind::Reviewed,
|
||||||
}),
|
}),
|
||||||
NamedFilter::AgainToday => Node::Search(SearchNode::Rated {
|
NamedFilter::AgainToday => Node::Search(SearchNode::Rated {
|
||||||
days: 1,
|
days: 1,
|
||||||
ease: Some(1),
|
ease: EaseKind::Rated(1),
|
||||||
}),
|
}),
|
||||||
NamedFilter::New => Node::Search(SearchNode::State(StateKind::New)),
|
NamedFilter::New => Node::Search(SearchNode::State(StateKind::New)),
|
||||||
NamedFilter::Learn => Node::Search(SearchNode::State(StateKind::Learning)),
|
NamedFilter::Learn => Node::Search(SearchNode::State(StateKind::Learning)),
|
||||||
|
@ -5,7 +5,7 @@ mod sqlwriter;
|
|||||||
mod writer;
|
mod writer;
|
||||||
|
|
||||||
pub use cards::SortMode;
|
pub use cards::SortMode;
|
||||||
pub use parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind};
|
pub use parser::{EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind};
|
||||||
pub use writer::{
|
pub use writer::{
|
||||||
concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes,
|
concatenate_searches, negate_search, normalize_search, replace_search_term, write_nodes,
|
||||||
BoolSeparator,
|
BoolSeparator,
|
||||||
|
@ -119,24 +119,12 @@ pub enum TemplateKind<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub(super) enum EaseKind {
|
pub enum EaseKind {
|
||||||
Rated(u8),
|
Rated(u8),
|
||||||
Reviewed,
|
Reviewed,
|
||||||
Manually,
|
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.
|
/// Parse the input string into a list of nodes.
|
||||||
pub(super) fn parse(input: &str) -> Result<Vec<Node>> {
|
pub(super) fn parse(input: &str) -> Result<Vec<Node>> {
|
||||||
let input = input.trim();
|
let input = input.trim();
|
||||||
@ -383,7 +371,7 @@ fn parse_rated(val: &str) -> ParseResult<SearchNode<'static>> {
|
|||||||
if (1..5).contains(&u) {
|
if (1..5).contains(&u) {
|
||||||
EaseKind::Rated(u)
|
EaseKind::Rated(u)
|
||||||
} else {
|
} else {
|
||||||
return Err(ParseError {})
|
return Err(ParseError {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => EaseKind::Reviewed,
|
None => EaseKind::Reviewed,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// 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 super::parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind, EaseKind};
|
use super::parser::{EaseKind, Node, PropertyKind, SearchNode, StateKind, TemplateKind};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
@ -219,12 +219,18 @@ impl SqlWriter<'_> {
|
|||||||
let target_cutoff_ms = (today_cutoff - 86_400 * i64::from(days)) * 1_000;
|
let target_cutoff_ms = (today_cutoff - 86_400 * i64::from(days)) * 1_000;
|
||||||
write!(
|
write!(
|
||||||
self.sql,
|
self.sql,
|
||||||
"c.id in (select cid from revlog where id>{}{})",
|
"c.id in (select cid from revlog where id>{}",
|
||||||
target_cutoff_ms,
|
target_cutoff_ms,
|
||||||
ease,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use crate::{
|
|||||||
decks::DeckID as DeckIDType,
|
decks::DeckID as DeckIDType,
|
||||||
err::Result,
|
err::Result,
|
||||||
notetype::NoteTypeID as NoteTypeIDType,
|
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 itertools::Itertools;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
Loading…
Reference in New Issue
Block a user