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
|
|
@ -68,7 +68,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="window-tabs" id="window-tabs">
|
<div class="window-tabs" id="window-tabs">
|
||||||
|
<button data-w="1h">last 1h</button>
|
||||||
|
<button data-w="4h">last 4h</button>
|
||||||
<button data-w="24h" class="active">last 24h</button>
|
<button data-w="24h" class="active">last 24h</button>
|
||||||
|
<button data-w="3d">last 3d</button>
|
||||||
<button data-w="7d">last 7d</button>
|
<button data-w="7d">last 7d</button>
|
||||||
<button data-w="30d">last 30d</button>
|
<button data-w="30d">last 30d</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ use hive_sh4re::ReminderStats;
|
||||||
/// total span + the bucket width used to roll up trend series.
|
/// total span + the bucket width used to roll up trend series.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Window {
|
pub enum Window {
|
||||||
|
Hour,
|
||||||
|
FourHour,
|
||||||
Day,
|
Day,
|
||||||
|
ThreeDay,
|
||||||
Week,
|
Week,
|
||||||
Month,
|
Month,
|
||||||
}
|
}
|
||||||
|
|
@ -28,6 +31,9 @@ pub enum Window {
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn parse(s: &str) -> Self {
|
pub fn parse(s: &str) -> Self {
|
||||||
match s {
|
match s {
|
||||||
|
"1h" => Self::Hour,
|
||||||
|
"4h" => Self::FourHour,
|
||||||
|
"3d" => Self::ThreeDay,
|
||||||
"7d" => Self::Week,
|
"7d" => Self::Week,
|
||||||
"30d" => Self::Month,
|
"30d" => Self::Month,
|
||||||
_ => Self::Day,
|
_ => Self::Day,
|
||||||
|
|
@ -36,15 +42,21 @@ impl Window {
|
||||||
|
|
||||||
fn label(self) -> &'static str {
|
fn label(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
Self::Hour => "1h",
|
||||||
|
Self::FourHour => "4h",
|
||||||
Self::Day => "24h",
|
Self::Day => "24h",
|
||||||
|
Self::ThreeDay => "3d",
|
||||||
Self::Week => "7d",
|
Self::Week => "7d",
|
||||||
Self::Month => "30d",
|
Self::Month => "30d",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span_secs(self) -> i64 {
|
pub fn span_secs(self) -> i64 {
|
||||||
match self {
|
match self {
|
||||||
|
Self::Hour => 3600,
|
||||||
|
Self::FourHour => 4 * 3600,
|
||||||
Self::Day => 24 * 3600,
|
Self::Day => 24 * 3600,
|
||||||
|
Self::ThreeDay => 3 * 24 * 3600,
|
||||||
Self::Week => 7 * 24 * 3600,
|
Self::Week => 7 * 24 * 3600,
|
||||||
Self::Month => 30 * 24 * 3600,
|
Self::Month => 30 * 24 * 3600,
|
||||||
}
|
}
|
||||||
|
|
@ -52,8 +64,11 @@ impl Window {
|
||||||
|
|
||||||
fn bucket_secs(self) -> i64 {
|
fn bucket_secs(self) -> i64 {
|
||||||
match self {
|
match self {
|
||||||
// hourly for the 24h view, daily for the longer ranges.
|
// 5-min buckets for 1h (12 buckets), 15-min for 4h (16 buckets),
|
||||||
Self::Day => 3600,
|
// 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,
|
Self::Week | Self::Month => 24 * 3600,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -319,13 +319,9 @@ async fn api_stats(
|
||||||
) -> axum::Json<crate::stats::Snapshot> {
|
) -> axum::Json<crate::stats::Snapshot> {
|
||||||
let window = crate::stats::Window::parse(q.window.as_deref().unwrap_or("24h"));
|
let window = crate::stats::Window::parse(q.window.as_deref().unwrap_or("24h"));
|
||||||
let mut snapshot = crate::stats::snapshot_default(window);
|
let mut snapshot = crate::stats::snapshot_default(window);
|
||||||
// Fetch reminder stats from the broker. The window spans are:
|
// Pass the window span to the reminder-stats RPC so the broker
|
||||||
// 24h = 86400s, 7d = 604800s, 30d = 2592000s.
|
// filters its counts to the same time range as the chart data.
|
||||||
let window_secs = match window {
|
let window_secs = window.span_secs();
|
||||||
crate::stats::Window::Day => 24 * 3600,
|
|
||||||
crate::stats::Window::Week => 7 * 24 * 3600,
|
|
||||||
crate::stats::Window::Month => 30 * 24 * 3600,
|
|
||||||
};
|
|
||||||
snapshot.reminder_stats = fetch_reminder_stats(&state.socket, state.flavor(), window_secs as u64).await;
|
snapshot.reminder_stats = fetch_reminder_stats(&state.socket, state.flavor(), window_secs as u64).await;
|
||||||
axum::Json(snapshot)
|
axum::Json(snapshot)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue