Port prop:rated to EaseKind
This commit is contained in:
parent
b57d0da12a
commit
3788cb8890
@ -87,7 +87,7 @@ pub enum PropertyKind {
|
||||
Lapses(u32),
|
||||
Ease(f32),
|
||||
Position(u32),
|
||||
Rated(u32, Option<u8>),
|
||||
Rated(u32, EaseKind),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
@ -433,7 +433,16 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode> {
|
||||
}
|
||||
}
|
||||
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)
|
||||
} else if key == "resched" {
|
||||
|
@ -116,7 +116,6 @@ impl SqlWriter<'_> {
|
||||
|
||||
fn write_search_node_to_sql(&mut self, node: &SearchNode) -> Result<()> {
|
||||
use normalize_to_nfc as norm;
|
||||
use std::cmp::max;
|
||||
match node {
|
||||
// note fields related
|
||||
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<()> {
|
||||
let today_cutoff = self.col.timing_today()?.next_day_at;
|
||||
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!(
|
||||
self.sql,
|
||||
@ -286,7 +285,7 @@ impl SqlWriter<'_> {
|
||||
PropertyKind::Ease(ease) => {
|
||||
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(())
|
||||
|
@ -196,8 +196,9 @@ fn write_property(operator: &str, kind: &PropertyKind) -> String {
|
||||
Ease(f) => format!("\"prop:ease{}{}\"", operator, f),
|
||||
Position(u) => format!("\"prop:pos{}{}\"", operator, u),
|
||||
Rated(u, ease) => match ease {
|
||||
Some(val) => format!("\"prop:rated{}{}:{}\"", operator, u, val),
|
||||
None => format!("\"prop:rated{}{}\"", operator, u),
|
||||
EaseKind::AnswerButton(val) => format!("\"prop:rated{}{}:{}\"", operator, u, val),
|
||||
EaseKind::AnyAnswerButton => format!("\"prop:rated{}{}\"", operator, u),
|
||||
EaseKind::ManualReschedule => format!("\"prop:resched{}{}\"", operator, u),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user