Saved Stat
All checks were successful
/ release (push) Successful in 48s

This commit is contained in:
Samuel Lorch 2025-03-19 23:07:11 +01:00
parent e7371850d1
commit a5fc856764
2 changed files with 27 additions and 0 deletions

View file

@ -24,6 +24,7 @@ type StatsDisplay struct {
Size []int
Duration []int
Count []int
Saved []int
}
type ChartData struct {
@ -337,6 +338,14 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
duration = 0
}
var saved int
err = db.QueryRow(r.Context(),
`SELECT (SUM(old_size) - COALESCE(SUM(size), 0)) AS saved
FROM files WHERE ($1 = -1 OR files.library_id = $1) AND status = $2 AND old_size NOT NULL`, id, constants.FILE_STATUS_EXISTS).Scan(&saved)
if err != nil {
saved = 0
}
buf := bytes.Buffer{}
err = templates.ExecuteTemplate(&buf, constants.STATS_TEMPLATE_NAME, StatsDisplay{
Libraries: libraries,
@ -344,6 +353,7 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
Size: splitInt(size),
Count: splitInt(count),
Duration: splitInt(duration),
Saved: splitInt(saved),
Charts: data,
})
if err != nil {

View file

@ -44,6 +44,23 @@
{{end}}
{{end}}
</div>
<h4>Saved</h4>
<div class="counter">
{{ $l := len .Saved }}
{{range $i, $c := .Saved}}
<img class="counter-image" alt="{{$c}}" src="/static/counter/{{$c}}.gif">
{{ $n := sub $l $i }}
{{ if eq $n 4 }}
KB
{{ else if eq $n 7 }}
MB
{{ else if eq $n 10 }}
GB
{{ else if eq $n 13 }}
TB
{{end}}
{{end}}
</div>
<div class="stats">
{{range $c := .Charts}}
{{$c.Element}} {{$c.Script}}