diff options
Diffstat (limited to 'ui/src/stats.rs')
-rw-r--r-- | ui/src/stats.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ui/src/stats.rs b/ui/src/stats.rs new file mode 100644 index 0000000..b4a2e23 --- /dev/null +++ b/ui/src/stats.rs @@ -0,0 +1,63 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin <metamuffin.org> +*/ + +use crate::{ + format::{format_duration, format_duration_long, format_kind, format_size}, + locale::{Language, tr, trs}, + scaffold::LayoutPage, +}; +use markup::raw; + +markup::define! { + StatsPage<'a>(lang: &'a Language) { + .page.stats { + h1 { @trs(&lang, "stats.title") } + p { @raw(tr(lang, "stats.count") + .replace("{count}", &format!("<b>{}</b>", all.count)) + )} + p { @raw(tr(lang, "stats.runtime") + .replace("{dur}", &format!("<b>{}</b>", format_duration_long(all.runtime, lang))) + .replace("{size}", &format!("<b>{}</b>", format_size(all.size))) + )} + p { @raw(tr(lang, "stats.average") + .replace("{dur}", &format!("<b>{}</b>", format_duration(all.average_runtime()))) + .replace("{size}", &format!("<b>{}</b>", format_size(all.average_size() as u64))) + )} + + h2 { @trs(&lang, "stats.by_kind.title") } + table.striped { + tr { + th { @trs(&lang, "stats.by_kind.kind") } + th { @trs(&lang, "stats.by_kind.count") } + th { @trs(&lang, "stats.by_kind.total_size") } + th { @trs(&lang, "stats.by_kind.total_runtime") } + th { @trs(&lang, "stats.by_kind.average_size") } + th { @trs(&lang, "stats.by_kind.average_runtime") } + th { @trs(&lang, "stats.by_kind.max_size") } + th { @trs(&lang, "stats.by_kind.max_runtime") } + } + @for (k,b) in &kinds { tr { + td { @format_kind(*k, lang) } + td { @b.count } + td { @format_size(b.size) } + td { @format_duration(b.runtime) } + td { @format_size(b.average_size() as u64) } + td { @format_duration(b.average_runtime()) } + td { @if b.max_size.0 > 0 { a[href=uri!(r_library_node(&b.max_size.1))]{ @format_size(b.max_size.0) }}} + td { @if b.max_runtime.0 > 0. { a[href=uri!(r_library_node(&b.max_runtime.1))]{ @format_duration(b.max_runtime.0) }}} + }} + } + } + } +} + +pub fn stats_page() { + LayoutPage { + title: tr(lang, "stats.title").to_string(), + content: StatsPage { lang: &lang }, + ..Default::default() + } +} |