aboutsummaryrefslogtreecommitdiff
path: root/ui/src/stats.rs
blob: b4a2e23398078aa2911a40ab9fcc7cba94a90f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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()
    }
}