mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Implement functioning prop:rated
This commit is contained in:
parent
ce55dc4a75
commit
b57d0da12a
1 changed files with 24 additions and 12 deletions
|
@ -116,6 +116,7 @@ impl SqlWriter<'_> {
|
||||||
|
|
||||||
fn write_search_node_to_sql(&mut self, node: &SearchNode) -> Result<()> {
|
fn write_search_node_to_sql(&mut self, node: &SearchNode) -> Result<()> {
|
||||||
use normalize_to_nfc as norm;
|
use normalize_to_nfc as norm;
|
||||||
|
use std::cmp::max;
|
||||||
match node {
|
match node {
|
||||||
// note fields related
|
// note fields related
|
||||||
SearchNode::UnqualifiedText(text) => self.write_unqualified(&self.norm_note(text)),
|
SearchNode::UnqualifiedText(text) => self.write_unqualified(&self.norm_note(text)),
|
||||||
|
@ -144,7 +145,7 @@ impl SqlWriter<'_> {
|
||||||
write!(self.sql, "c.did = {}", did).unwrap();
|
write!(self.sql, "c.did = {}", did).unwrap();
|
||||||
}
|
}
|
||||||
SearchNode::NoteType(notetype) => self.write_note_type(&norm(notetype))?,
|
SearchNode::NoteType(notetype) => self.write_note_type(&norm(notetype))?,
|
||||||
SearchNode::Rated { days, ease } => self.write_rated(*days, ease)?,
|
SearchNode::Rated { days, ease } => self.write_rated(*days, ease, "<")?,
|
||||||
|
|
||||||
SearchNode::Tag(tag) => self.write_tag(&norm(tag))?,
|
SearchNode::Tag(tag) => self.write_tag(&norm(tag))?,
|
||||||
SearchNode::State(state) => self.write_state(state)?,
|
SearchNode::State(state) => self.write_state(state)?,
|
||||||
|
@ -214,9 +215,11 @@ impl SqlWriter<'_> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_rated(&mut self, days: u32, ease: &EaseKind) -> Result<()> {
|
fn write_rated(&mut self, days: u32, ease: &EaseKind, op: &str) -> Result<()> {
|
||||||
let today_cutoff = self.col.timing_today()?.next_day_at;
|
let today_cutoff = self.col.timing_today()?.next_day_at;
|
||||||
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;
|
||||||
|
let day_before_cutoff_ms = (today_cutoff - 86_400 * (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>{}",
|
||||||
|
@ -224,6 +227,17 @@ impl SqlWriter<'_> {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// We use positive numbers for negative offsets
|
||||||
|
// which is why operators are reversed
|
||||||
|
match op {
|
||||||
|
"<" => write!(self.sql, "{} {}", ">", target_cutoff_ms),
|
||||||
|
">" => write!(self.sql, "{} {}", "<", day_before_cutoff_ms),
|
||||||
|
"<=" => write!(self.sql, "{} {}", ">", day_before_cutoff_ms),
|
||||||
|
">=" => write!(self.sql, "{} {}", "<", target_cutoff_ms),
|
||||||
|
"=" => write!(self.sql, "between {} and {}", target_cutoff_ms, day_before_cutoff_ms),
|
||||||
|
_ /* "!=" */ => write!(self.sql, "not between {} and {}", target_cutoff_ms, day_before_cutoff_ms),
|
||||||
|
}.unwrap();
|
||||||
|
|
||||||
match ease {
|
match ease {
|
||||||
EaseKind::AnswerButton(u) => write!(self.sql, " and ease = {})", u),
|
EaseKind::AnswerButton(u) => write!(self.sql, " and ease = {})", u),
|
||||||
EaseKind::AnyAnswerButton => write!(self.sql, " and ease > 0)"),
|
EaseKind::AnyAnswerButton => write!(self.sql, " and ease > 0)"),
|
||||||
|
@ -255,7 +269,7 @@ impl SqlWriter<'_> {
|
||||||
previewrepeat = CardQueue::PreviewRepeat as i8,
|
previewrepeat = CardQueue::PreviewRepeat as i8,
|
||||||
cutoff = timing.next_day_at,
|
cutoff = timing.next_day_at,
|
||||||
days = days
|
days = days
|
||||||
)
|
).unwrap()
|
||||||
}
|
}
|
||||||
PropertyKind::Position(pos) => {
|
PropertyKind::Position(pos) => {
|
||||||
write!(
|
write!(
|
||||||
|
@ -264,19 +278,17 @@ impl SqlWriter<'_> {
|
||||||
t = CardType::New as u8,
|
t = CardType::New as u8,
|
||||||
op = op,
|
op = op,
|
||||||
pos = pos
|
pos = pos
|
||||||
)
|
).unwrap()
|
||||||
}
|
}
|
||||||
PropertyKind::Interval(ivl) => write!(self.sql, "ivl {} {}", op, ivl),
|
PropertyKind::Interval(ivl) => write!(self.sql, "ivl {} {}", op, ivl).unwrap(),
|
||||||
PropertyKind::Reps(reps) => write!(self.sql, "reps {} {}", op, reps),
|
PropertyKind::Reps(reps) => write!(self.sql, "reps {} {}", op, reps).unwrap(),
|
||||||
PropertyKind::Lapses(days) => write!(self.sql, "lapses {} {}", op, days),
|
PropertyKind::Lapses(days) => write!(self.sql, "lapses {} {}", op, days).unwrap(),
|
||||||
PropertyKind::Ease(ease) => {
|
PropertyKind::Ease(ease) => {
|
||||||
write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32)
|
write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32).unwrap()
|
||||||
}
|
|
||||||
PropertyKind::Rated(days, ease) => {
|
|
||||||
write!(self.sql, "")
|
|
||||||
}
|
}
|
||||||
|
PropertyKind::Rated(days, ease) => self.write_rated(*days, *ease, op)?
|
||||||
}
|
}
|
||||||
.unwrap();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue