diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 32c956d..cc3e13c 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -26,6 +26,39 @@ pub enum Range { SinceReset, } +impl Range { + pub const ALL: [Range; 5] = [ + Range::Hour, + Range::Day, + Range::Week, + Range::Month, + Range::SinceReset, + ]; + /// The value used in `?range=`. + pub fn code(self) -> &'static str { + match self { + Range::Hour => "1h", + Range::Day => "24h", + Range::Week => "7d", + Range::Month => "30d", + Range::SinceReset => "reset", + } + } + pub fn parse(code: &str) -> Option { + Range::ALL.into_iter().find(|r| r.code() == code) + } + /// For headings: "last 24 hours", "since reset". + pub fn label(self) -> &'static str { + match self { + Range::Hour => "last hour", + Range::Day => "last 24 hours", + Range::Week => "last 7 days", + Range::Month => "last 30 days", + Range::SinceReset => "since reset", + } + } +} + #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct View { pub range: Option, @@ -89,6 +122,8 @@ pub struct Totals { pub requests: u64, pub executed: u64, pub hits: u64, + /// Every compile that was built instead of served from cache. Timeouts, + /// read errors and forced recaches are counted inside this, as sccache does. pub misses: u64, pub not_cacheable: u64, pub unsupported_compiler: u64,