Port prop:rated to EaseKind

This commit is contained in:
Henrik Giesel 2021-01-14 17:58:21 +01:00
parent b57d0da12a
commit 3788cb8890
3 changed files with 16 additions and 7 deletions

View file

@ -87,7 +87,7 @@ pub enum PropertyKind {
Lapses(u32), Lapses(u32),
Ease(f32), Ease(f32),
Position(u32), Position(u32),
Rated(u32, Option<u8>), Rated(u32, EaseKind),
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
@ -433,7 +433,16 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode> {
} }
} }
None => EaseKind::AnyAnswerButton, None => EaseKind::AnyAnswerButton,
} };
PropertyKind::Rated(days, ease)
} else if key == "resched" {
let mut it = val.splitn(2, ':');
let n: u32 = it.next().unwrap().parse()?;
let days = n.max(1).min(365);
let ease = EaseKind::ManualReschedule;
PropertyKind::Rated(days, ease) PropertyKind::Rated(days, ease)
} else if key == "resched" { } else if key == "resched" {

View file

@ -116,7 +116,6 @@ 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)),
@ -218,7 +217,7 @@ impl SqlWriter<'_> {
fn write_rated(&mut self, days: u32, ease: &EaseKind, op: &str) -> 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; let day_before_cutoff_ms = (today_cutoff - 86_400 * i64::from(days - 1)) * 1_000;
write!( write!(
self.sql, self.sql,
@ -286,7 +285,7 @@ impl SqlWriter<'_> {
PropertyKind::Ease(ease) => { PropertyKind::Ease(ease) => {
write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32).unwrap() write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32).unwrap()
} }
PropertyKind::Rated(days, ease) => self.write_rated(*days, *ease, op)? PropertyKind::Rated(days, ease) => self.write_rated(*days, ease, op)?
} }
Ok(()) Ok(())

View file

@ -196,8 +196,9 @@ fn write_property(operator: &str, kind: &PropertyKind) -> String {
Ease(f) => format!("\"prop:ease{}{}\"", operator, f), Ease(f) => format!("\"prop:ease{}{}\"", operator, f),
Position(u) => format!("\"prop:pos{}{}\"", operator, u), Position(u) => format!("\"prop:pos{}{}\"", operator, u),
Rated(u, ease) => match ease { Rated(u, ease) => match ease {
Some(val) => format!("\"prop:rated{}{}:{}\"", operator, u, val), EaseKind::AnswerButton(val) => format!("\"prop:rated{}{}:{}\"", operator, u, val),
None => format!("\"prop:rated{}{}\"", operator, u), EaseKind::AnyAnswerButton => format!("\"prop:rated{}{}\"", operator, u),
EaseKind::ManualReschedule => format!("\"prop:resched{}{}\"", operator, u),
} }
} }
} }