Add note interval column

This commit is contained in:
RumovZ 2021-03-30 23:44:35 +02:00
parent 31155f2dcd
commit 8779fb5ede
9 changed files with 59 additions and 16 deletions

View File

@ -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-flag = Any Flag
browsing-average-ease = Average Ease
browsing-average-interval = Average Interval
browsing-browser-appearance = Browser Appearance
browsing-browser-options = Browser Options
browsing-buried = Buried

View File

@ -720,6 +720,7 @@ class NoteState(ItemState):
("noteDue", tr.statistics_due_date()),
("noteEase", tr.browsing_average_ease()),
("noteFld", tr.browsing_sort_field()),
("noteIvl", tr.browsing_average_interval()),
("noteLapses", tr.scheduling_lapses()),
("noteMod", tr.search_note_modified()),
("noteReps", tr.scheduling_reviews()),

View File

@ -811,22 +811,23 @@ message SortOrder {
enum Kind {
NOTE_CARDS = 0;
NOTE_CREATION = 1;
NOTE_DUE = 17;
NOTE_EASE = 2;
NOTE_FIELD = 3;
NOTE_LAPSES = 4;
NOTE_MOD = 5;
NOTE_REPS = 6;
NOTE_TAGS = 7;
NOTETYPE = 8;
CARD_MOD = 9;
CARD_REPS = 10;
CARD_DUE = 11;
CARD_EASE = 12;
CARD_LAPSES = 13;
CARD_INTERVAL = 14;
CARD_DECK = 15;
CARD_TEMPLATE = 16;
NOTE_DUE = 2;
NOTE_EASE = 3;
NOTE_FIELD = 4;
NOTE_INTERVAL = 5;
NOTE_LAPSES = 6;
NOTE_MOD = 7;
NOTE_REPS = 8;
NOTE_TAGS = 9;
NOTETYPE = 10;
CARD_MOD = 11;
CARD_REPS = 12;
CARD_DUE = 13;
CARD_EASE = 14;
CARD_LAPSES = 15;
CARD_INTERVAL = 16;
CARD_DECK = 17;
CARD_TEMPLATE = 18;
}
Kind kind = 1;
bool reverse = 2;

View File

@ -27,6 +27,7 @@ impl From<String> for browser_table::Column {
"noteDue" => browser_table::Column::NoteDue,
"noteEase" => browser_table::Column::NoteEase,
"noteFld" => browser_table::Column::NoteField,
"noteIvl" => browser_table::Column::NoteInterval,
"noteLapses" => browser_table::Column::NoteLapses,
"noteMod" => browser_table::Column::NoteMod,
"noteReps" => browser_table::Column::NoteReps,

View File

@ -111,6 +111,7 @@ impl From<SortKindProto> for SortKind {
SortKindProto::NoteCreation => SortKind::NoteCreation,
SortKindProto::NoteDue => SortKind::NoteDue,
SortKindProto::NoteEase => SortKind::NoteEase,
SortKindProto::NoteInterval => SortKind::NoteInterval,
SortKindProto::NoteLapses => SortKind::NoteLapses,
SortKindProto::NoteMod => SortKind::NoteMod,
SortKindProto::NoteField => SortKind::NoteField,

View File

@ -40,6 +40,7 @@ pub enum Column {
NoteDue,
NoteEase,
NoteField,
NoteInterval,
NoteLapses,
NoteMod,
NoteReps,
@ -492,6 +493,26 @@ impl<'a> NoteRowContext<'a> {
.map(|time| time.date_string())
.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<'_> {
@ -502,6 +523,7 @@ impl RowContext for NoteRowContext<'_> {
Column::NoteDue => self.note_due_str(),
Column::NoteEase => self.note_ease_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::NoteMod => self.note.mtime.date_string(),
Column::NoteReps => self.cards.iter().map(|c| c.reps).sum::<u32>().to_string(),

View File

@ -273,6 +273,8 @@ pub enum SortKind {
NoteCreation,
NoteDue,
NoteEase,
#[serde(rename = "noteIvl")]
NoteInterval,
NoteLapses,
NoteMod,
#[serde(rename = "noteFld")]

View File

@ -93,6 +93,7 @@ impl SortKind {
| SortKind::NoteDue
| SortKind::NoteEase
| SortKind::NoteField
| SortKind::NoteInterval
| SortKind::NoteLapses
| SortKind::NoteMod
| SortKind::NoteReps
@ -256,6 +257,7 @@ fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
SortKind::NoteCards
| SortKind::NoteDue
| SortKind::NoteEase
| SortKind::NoteInterval
| SortKind::NoteLapses
| SortKind::NoteReps => "(select pos from sort_order where nid = 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"),
NoteDue => include_str!("note_due_order.sql"),
NoteEase => include_str!("note_ease_order.sql"),
NoteInterval => include_str!("note_interval_order.sql"),
NoteLapses => include_str!("note_lapses_order.sql"),
NoteReps => include_str!("note_reps_order.sql"),
Notetype => include_str!("notetype_order.sql"),

View 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);