From 04e606bf4bdf4a8050cc4eaa0696a206d1288bf5 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 15 Jan 2021 01:39:23 +0100 Subject: [PATCH] Add firstWeekday to GraphsOut --- rslib/backend.proto | 7 +++++++ rslib/src/config.rs | 20 ++++++++++++++++++++ rslib/src/stats/graphs.rs | 2 ++ 3 files changed, 29 insertions(+) diff --git a/rslib/backend.proto b/rslib/backend.proto index 52bb6b24a..848a201b9 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -1082,6 +1082,12 @@ message GraphsIn { } message GraphsOut { + enum Weekday { + SUNDAY = 0; + MONDAY = 1; + FRIDAY = 5; + SATURDAY = 6; + } repeated Card cards = 1; repeated RevlogEntry revlog = 2; uint32 days_elapsed = 3; @@ -1090,6 +1096,7 @@ message GraphsOut { uint32 scheduler_version = 5; /// Seconds to add to UTC timestamps to get local time. int32 local_offset_secs = 7; + Weekday first_weekday = 8; } message RevlogEntry { diff --git a/rslib/src/config.rs b/rslib/src/config.rs index 53838e51c..8e8c0f9f3 100644 --- a/rslib/src/config.rs +++ b/rslib/src/config.rs @@ -18,6 +18,7 @@ pub(crate) fn schema11_config_as_string() -> String { "curDeck": 1, "newSpread": 0, "collapseTime": 1200, + "firstWeekday": 0, "timeLim": 0, "estTimes": true, "dueCounts": true, @@ -47,6 +48,7 @@ pub(crate) enum ConfigKey { ShowRemainingDueCountsInStudy, ShowIntervalsAboveAnswerButtons, NewReviewMix, + FirstWeekday, AnswerTimeLimitSecs, ShowDayLearningCardsFirst, LastUnburiedDay, @@ -75,6 +77,7 @@ impl From for &'static str { ConfigKey::ShowRemainingDueCountsInStudy => "dueCounts", ConfigKey::ShowIntervalsAboveAnswerButtons => "estTimes", ConfigKey::NewReviewMix => "newSpread", + ConfigKey::FirstWeekday => "firstWeekday", ConfigKey::AnswerTimeLimitSecs => "timeLim", ConfigKey::ShowDayLearningCardsFirst => "dayLearnFirst", ConfigKey::LastUnburiedDay => "lastUnburied", @@ -227,6 +230,16 @@ impl Collection { self.set_config(ConfigKey::NewReviewMix, &(mix as u8)) } + + pub(crate) fn get_first_weekday(&self) -> Weekday { + match self.get_config_default::(ConfigKey::FirstWeekday) { + 1 => Weekday::Monday, + 5 => Weekday::Friday, + 6 => Weekday::Saturday, + _ => Weekday::Sunday, + } + } + pub(crate) fn get_show_due_counts(&self) -> bool { self.get_config_optional(ConfigKey::ShowRemainingDueCountsInStudy) .unwrap_or(true) @@ -309,6 +322,13 @@ pub(crate) enum NewReviewMix { NewFirst = 2, } +pub(crate) enum Weekday { + Sunday = 0, + Monday = 1, + Friday = 5, + Saturday = 6, +} + #[cfg(test)] mod test { use super::SortKind; diff --git a/rslib/src/stats/graphs.rs b/rslib/src/stats/graphs.rs index f0e8e7163..90f3139ea 100644 --- a/rslib/src/stats/graphs.rs +++ b/rslib/src/stats/graphs.rs @@ -25,6 +25,7 @@ impl Collection { let offset = self.local_utc_offset_for_user()?; let local_offset_secs = offset.local_minus_utc() as i64; + let cards = self.storage.all_searched_cards()?; let revlog = if all { self.storage.get_all_revlog_entries(revlog_start)? @@ -42,6 +43,7 @@ impl Collection { next_day_at_secs: timing.next_day_at as u32, scheduler_version: self.sched_ver() as u32, local_offset_secs: local_offset_secs as i32, + first_weekday: self.get_first_weekday() as i32, }) } }