Add note interval column
This commit is contained in:
parent
31155f2dcd
commit
8779fb5ede
@ -8,6 +8,7 @@ browsing-answer = Answer
|
|||||||
browsing-any-cards-mapped-to-nothing-will = Any cards mapped to nothing will be deleted. If a note has no remaining cards, it will be lost. Are you sure you want to continue?
|
browsing-any-cards-mapped-to-nothing-will = Any cards mapped to nothing will be deleted. If a note has no remaining cards, it will be lost. Are you sure you want to continue?
|
||||||
browsing-any-flag = Any Flag
|
browsing-any-flag = Any Flag
|
||||||
browsing-average-ease = Average Ease
|
browsing-average-ease = Average Ease
|
||||||
|
browsing-average-interval = Average Interval
|
||||||
browsing-browser-appearance = Browser Appearance
|
browsing-browser-appearance = Browser Appearance
|
||||||
browsing-browser-options = Browser Options
|
browsing-browser-options = Browser Options
|
||||||
browsing-buried = Buried
|
browsing-buried = Buried
|
||||||
|
@ -720,6 +720,7 @@ class NoteState(ItemState):
|
|||||||
("noteDue", tr.statistics_due_date()),
|
("noteDue", tr.statistics_due_date()),
|
||||||
("noteEase", tr.browsing_average_ease()),
|
("noteEase", tr.browsing_average_ease()),
|
||||||
("noteFld", tr.browsing_sort_field()),
|
("noteFld", tr.browsing_sort_field()),
|
||||||
|
("noteIvl", tr.browsing_average_interval()),
|
||||||
("noteLapses", tr.scheduling_lapses()),
|
("noteLapses", tr.scheduling_lapses()),
|
||||||
("noteMod", tr.search_note_modified()),
|
("noteMod", tr.search_note_modified()),
|
||||||
("noteReps", tr.scheduling_reviews()),
|
("noteReps", tr.scheduling_reviews()),
|
||||||
|
@ -811,22 +811,23 @@ message SortOrder {
|
|||||||
enum Kind {
|
enum Kind {
|
||||||
NOTE_CARDS = 0;
|
NOTE_CARDS = 0;
|
||||||
NOTE_CREATION = 1;
|
NOTE_CREATION = 1;
|
||||||
NOTE_DUE = 17;
|
NOTE_DUE = 2;
|
||||||
NOTE_EASE = 2;
|
NOTE_EASE = 3;
|
||||||
NOTE_FIELD = 3;
|
NOTE_FIELD = 4;
|
||||||
NOTE_LAPSES = 4;
|
NOTE_INTERVAL = 5;
|
||||||
NOTE_MOD = 5;
|
NOTE_LAPSES = 6;
|
||||||
NOTE_REPS = 6;
|
NOTE_MOD = 7;
|
||||||
NOTE_TAGS = 7;
|
NOTE_REPS = 8;
|
||||||
NOTETYPE = 8;
|
NOTE_TAGS = 9;
|
||||||
CARD_MOD = 9;
|
NOTETYPE = 10;
|
||||||
CARD_REPS = 10;
|
CARD_MOD = 11;
|
||||||
CARD_DUE = 11;
|
CARD_REPS = 12;
|
||||||
CARD_EASE = 12;
|
CARD_DUE = 13;
|
||||||
CARD_LAPSES = 13;
|
CARD_EASE = 14;
|
||||||
CARD_INTERVAL = 14;
|
CARD_LAPSES = 15;
|
||||||
CARD_DECK = 15;
|
CARD_INTERVAL = 16;
|
||||||
CARD_TEMPLATE = 16;
|
CARD_DECK = 17;
|
||||||
|
CARD_TEMPLATE = 18;
|
||||||
}
|
}
|
||||||
Kind kind = 1;
|
Kind kind = 1;
|
||||||
bool reverse = 2;
|
bool reverse = 2;
|
||||||
|
@ -27,6 +27,7 @@ impl From<String> for browser_table::Column {
|
|||||||
"noteDue" => browser_table::Column::NoteDue,
|
"noteDue" => browser_table::Column::NoteDue,
|
||||||
"noteEase" => browser_table::Column::NoteEase,
|
"noteEase" => browser_table::Column::NoteEase,
|
||||||
"noteFld" => browser_table::Column::NoteField,
|
"noteFld" => browser_table::Column::NoteField,
|
||||||
|
"noteIvl" => browser_table::Column::NoteInterval,
|
||||||
"noteLapses" => browser_table::Column::NoteLapses,
|
"noteLapses" => browser_table::Column::NoteLapses,
|
||||||
"noteMod" => browser_table::Column::NoteMod,
|
"noteMod" => browser_table::Column::NoteMod,
|
||||||
"noteReps" => browser_table::Column::NoteReps,
|
"noteReps" => browser_table::Column::NoteReps,
|
||||||
|
@ -111,6 +111,7 @@ impl From<SortKindProto> for SortKind {
|
|||||||
SortKindProto::NoteCreation => SortKind::NoteCreation,
|
SortKindProto::NoteCreation => SortKind::NoteCreation,
|
||||||
SortKindProto::NoteDue => SortKind::NoteDue,
|
SortKindProto::NoteDue => SortKind::NoteDue,
|
||||||
SortKindProto::NoteEase => SortKind::NoteEase,
|
SortKindProto::NoteEase => SortKind::NoteEase,
|
||||||
|
SortKindProto::NoteInterval => SortKind::NoteInterval,
|
||||||
SortKindProto::NoteLapses => SortKind::NoteLapses,
|
SortKindProto::NoteLapses => SortKind::NoteLapses,
|
||||||
SortKindProto::NoteMod => SortKind::NoteMod,
|
SortKindProto::NoteMod => SortKind::NoteMod,
|
||||||
SortKindProto::NoteField => SortKind::NoteField,
|
SortKindProto::NoteField => SortKind::NoteField,
|
||||||
|
@ -40,6 +40,7 @@ pub enum Column {
|
|||||||
NoteDue,
|
NoteDue,
|
||||||
NoteEase,
|
NoteEase,
|
||||||
NoteField,
|
NoteField,
|
||||||
|
NoteInterval,
|
||||||
NoteLapses,
|
NoteLapses,
|
||||||
NoteMod,
|
NoteMod,
|
||||||
NoteReps,
|
NoteReps,
|
||||||
@ -492,6 +493,26 @@ impl<'a> NoteRowContext<'a> {
|
|||||||
.map(|time| time.date_string())
|
.map(|time| time.date_string())
|
||||||
.unwrap_or_else(|| "".into())
|
.unwrap_or_else(|| "".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the average interval of the review and relearn cards or the empty string if there
|
||||||
|
/// aren't any.
|
||||||
|
fn note_interval_str(&self) -> String {
|
||||||
|
let intervals: Vec<u32> = self
|
||||||
|
.cards
|
||||||
|
.iter()
|
||||||
|
.filter(|c| matches!(c.ctype, CardType::Review | CardType::Relearn))
|
||||||
|
.map(|c| c.interval)
|
||||||
|
.collect();
|
||||||
|
if intervals.is_empty() {
|
||||||
|
"".into()
|
||||||
|
} else {
|
||||||
|
time_span(
|
||||||
|
(intervals.iter().sum::<u32>() * 86400 / (intervals.len() as u32)) as f32,
|
||||||
|
self.tr,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RowContext for NoteRowContext<'_> {
|
impl RowContext for NoteRowContext<'_> {
|
||||||
@ -502,6 +523,7 @@ impl RowContext for NoteRowContext<'_> {
|
|||||||
Column::NoteDue => self.note_due_str(),
|
Column::NoteDue => self.note_due_str(),
|
||||||
Column::NoteEase => self.note_ease_str(),
|
Column::NoteEase => self.note_ease_str(),
|
||||||
Column::NoteField => self.note_field_str(),
|
Column::NoteField => self.note_field_str(),
|
||||||
|
Column::NoteInterval => self.note_interval_str(),
|
||||||
Column::NoteLapses => self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string(),
|
Column::NoteLapses => self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string(),
|
||||||
Column::NoteMod => self.note.mtime.date_string(),
|
Column::NoteMod => self.note.mtime.date_string(),
|
||||||
Column::NoteReps => self.cards.iter().map(|c| c.reps).sum::<u32>().to_string(),
|
Column::NoteReps => self.cards.iter().map(|c| c.reps).sum::<u32>().to_string(),
|
||||||
|
@ -273,6 +273,8 @@ pub enum SortKind {
|
|||||||
NoteCreation,
|
NoteCreation,
|
||||||
NoteDue,
|
NoteDue,
|
||||||
NoteEase,
|
NoteEase,
|
||||||
|
#[serde(rename = "noteIvl")]
|
||||||
|
NoteInterval,
|
||||||
NoteLapses,
|
NoteLapses,
|
||||||
NoteMod,
|
NoteMod,
|
||||||
#[serde(rename = "noteFld")]
|
#[serde(rename = "noteFld")]
|
||||||
|
@ -93,6 +93,7 @@ impl SortKind {
|
|||||||
| SortKind::NoteDue
|
| SortKind::NoteDue
|
||||||
| SortKind::NoteEase
|
| SortKind::NoteEase
|
||||||
| SortKind::NoteField
|
| SortKind::NoteField
|
||||||
|
| SortKind::NoteInterval
|
||||||
| SortKind::NoteLapses
|
| SortKind::NoteLapses
|
||||||
| SortKind::NoteMod
|
| SortKind::NoteMod
|
||||||
| SortKind::NoteReps
|
| SortKind::NoteReps
|
||||||
@ -256,6 +257,7 @@ fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
|||||||
SortKind::NoteCards
|
SortKind::NoteCards
|
||||||
| SortKind::NoteDue
|
| SortKind::NoteDue
|
||||||
| SortKind::NoteEase
|
| SortKind::NoteEase
|
||||||
|
| SortKind::NoteInterval
|
||||||
| SortKind::NoteLapses
|
| SortKind::NoteLapses
|
||||||
| SortKind::NoteReps => "(select pos from sort_order where nid = n.id) asc".into(),
|
| SortKind::NoteReps => "(select pos from sort_order where nid = n.id) asc".into(),
|
||||||
SortKind::NoteCreation => "n.id asc".into(),
|
SortKind::NoteCreation => "n.id asc".into(),
|
||||||
@ -275,6 +277,7 @@ fn prepare_sort(col: &mut Collection, kind: SortKind) -> Result<()> {
|
|||||||
NoteCards => include_str!("note_cards_order.sql"),
|
NoteCards => include_str!("note_cards_order.sql"),
|
||||||
NoteDue => include_str!("note_due_order.sql"),
|
NoteDue => include_str!("note_due_order.sql"),
|
||||||
NoteEase => include_str!("note_ease_order.sql"),
|
NoteEase => include_str!("note_ease_order.sql"),
|
||||||
|
NoteInterval => include_str!("note_interval_order.sql"),
|
||||||
NoteLapses => include_str!("note_lapses_order.sql"),
|
NoteLapses => include_str!("note_lapses_order.sql"),
|
||||||
NoteReps => include_str!("note_reps_order.sql"),
|
NoteReps => include_str!("note_reps_order.sql"),
|
||||||
Notetype => include_str!("notetype_order.sql"),
|
Notetype => include_str!("notetype_order.sql"),
|
||||||
|
11
rslib/src/search/note_interval_order.sql
Normal file
11
rslib/src/search/note_interval_order.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
DROP TABLE IF EXISTS sort_order;
|
||||||
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
|
pos integer PRIMARY KEY,
|
||||||
|
nid integer NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
INSERT INTO sort_order (nid)
|
||||||
|
SELECT nid
|
||||||
|
FROM cards
|
||||||
|
WHERE type IN (2, 3)
|
||||||
|
GROUP BY nid
|
||||||
|
ORDER BY AVG(ivl);
|
Loading…
Reference in New Issue
Block a user