This commit is contained in:
parent
0f5d842a64
commit
38219f7b07
6 changed files with 87 additions and 1 deletions
|
@ -2,15 +2,21 @@ package server
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.lastassault.de/speatzle/morffix/constants"
|
||||
"github.com/go-echarts/go-echarts/v2/charts"
|
||||
"github.com/go-echarts/go-echarts/v2/opts"
|
||||
"github.com/go-echarts/go-echarts/v2/types"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type StatsDisplay struct {
|
||||
CodecCounts []CodecCount
|
||||
Element template.HTML
|
||||
Script template.HTML
|
||||
}
|
||||
|
||||
type CodecCount struct {
|
||||
|
@ -35,6 +41,36 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
data.CodecCounts = codecCounts
|
||||
|
||||
chartData := []opts.PieData{}
|
||||
for _, c := range codecCounts {
|
||||
chartData = append(chartData, opts.PieData{
|
||||
Name: c.Codec,
|
||||
Value: c.Count,
|
||||
})
|
||||
}
|
||||
|
||||
pie := charts.NewPie()
|
||||
pie.SetGlobalOptions(
|
||||
charts.WithInitializationOpts(opts.Initialization{
|
||||
Theme: types.ThemePurplePassion,
|
||||
}),
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "Codecs",
|
||||
}))
|
||||
|
||||
pie.AddSeries("Codecs", chartData).SetSeriesOptions(charts.WithLabelOpts(
|
||||
opts.Label{
|
||||
Show: opts.Bool(true),
|
||||
Formatter: "{b}: {c}",
|
||||
Color: "white",
|
||||
}),
|
||||
)
|
||||
|
||||
snippet := pie.RenderSnippet()
|
||||
|
||||
data.Element = template.HTML(snippet.Element)
|
||||
data.Script = template.HTML(snippet.Script)
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
err = templates.ExecuteTemplate(&buf, constants.STATS_TEMPLATE_NAME, data)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue