stats: add 1h, 4h, 3d time range windows
Adds Hour (5-min buckets), FourHour (15-min buckets), and ThreeDay (hourly buckets) to the Window enum, plus the matching tab buttons in stats.html. Simplifies web_ui.rs to use Window::span_secs() instead of a duplicate match. Closes #25
This commit is contained in:
parent
4bb3877460
commit
f9d1e69a50
3 changed files with 24 additions and 10 deletions
|
|
@ -20,7 +20,10 @@ use hive_sh4re::ReminderStats;
|
|||
/// total span + the bucket width used to roll up trend series.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Window {
|
||||
Hour,
|
||||
FourHour,
|
||||
Day,
|
||||
ThreeDay,
|
||||
Week,
|
||||
Month,
|
||||
}
|
||||
|
|
@ -28,6 +31,9 @@ pub enum Window {
|
|||
impl Window {
|
||||
pub fn parse(s: &str) -> Self {
|
||||
match s {
|
||||
"1h" => Self::Hour,
|
||||
"4h" => Self::FourHour,
|
||||
"3d" => Self::ThreeDay,
|
||||
"7d" => Self::Week,
|
||||
"30d" => Self::Month,
|
||||
_ => Self::Day,
|
||||
|
|
@ -36,15 +42,21 @@ impl Window {
|
|||
|
||||
fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Hour => "1h",
|
||||
Self::FourHour => "4h",
|
||||
Self::Day => "24h",
|
||||
Self::ThreeDay => "3d",
|
||||
Self::Week => "7d",
|
||||
Self::Month => "30d",
|
||||
}
|
||||
}
|
||||
|
||||
fn span_secs(self) -> i64 {
|
||||
pub fn span_secs(self) -> i64 {
|
||||
match self {
|
||||
Self::Hour => 3600,
|
||||
Self::FourHour => 4 * 3600,
|
||||
Self::Day => 24 * 3600,
|
||||
Self::ThreeDay => 3 * 24 * 3600,
|
||||
Self::Week => 7 * 24 * 3600,
|
||||
Self::Month => 30 * 24 * 3600,
|
||||
}
|
||||
|
|
@ -52,8 +64,11 @@ impl Window {
|
|||
|
||||
fn bucket_secs(self) -> i64 {
|
||||
match self {
|
||||
// hourly for the 24h view, daily for the longer ranges.
|
||||
Self::Day => 3600,
|
||||
// 5-min buckets for 1h (12 buckets), 15-min for 4h (16 buckets),
|
||||
// hourly for 24h + 3d, daily for 7d + 30d.
|
||||
Self::Hour => 300,
|
||||
Self::FourHour => 900,
|
||||
Self::Day | Self::ThreeDay => 3600,
|
||||
Self::Week | Self::Month => 24 * 3600,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue