Compare commits
No commits in common. "a75ce3287da734e6c6965359a36a4b57d63cf30a" and "cd78de96b40f9ad44d747db0125808bffbfb4e3c" have entirely different histories.
a75ce3287d
...
cd78de96b4
1 changed files with 6 additions and 67 deletions
|
@ -8,7 +8,6 @@ import (
|
|||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.lastassault.de/speatzle/morffix/constants"
|
||||
"github.com/go-echarts/go-echarts/v2/charts"
|
||||
|
@ -70,7 +69,7 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
`SELECT COALESCE(jsonb_path_query_first(ffprobe_data, '$.streams[*] ? (@.codec_type == "video") ? (@.disposition.attached_pic == 0).codec_name')::text, 'Unknown') AS name, COUNT(*) AS value
|
||||
FROM files
|
||||
WHERE ffprobe_data IS NOT NULL
|
||||
GROUP BY 1;`)
|
||||
GROUP BY jsonb_path_query_first(ffprobe_data, '$.streams[*] ? (@.codec_type == "video") ? (@.disposition.attached_pic == 0).codec_name');`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Codecs: %w", err)
|
||||
}
|
||||
|
@ -92,7 +91,7 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
`SELECT COALESCE(jsonb_path_query_first(ffprobe_data, '$.streams[*] ? (@.codec_type == "video") ? (@.disposition.attached_pic == 0).width')::text, 'Unknown') AS name, COUNT(*) AS value
|
||||
FROM files
|
||||
WHERE ffprobe_data IS NOT NULL
|
||||
GROUP BY 1;`)
|
||||
GROUP BY jsonb_path_query_first(ffprobe_data, '$.streams[*] ? (@.codec_type == "video") ? (@.disposition.attached_pic == 0).width');`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Resolution: %w", err)
|
||||
}
|
||||
|
@ -114,7 +113,7 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
`SELECT COALESCE(jsonb_path_query_first(ffprobe_data, '$.format.format_name')::text, 'Unknown') AS name, COUNT(*) AS value
|
||||
FROM files
|
||||
WHERE ffprobe_data IS NOT NULL
|
||||
GROUP BY 1;`)
|
||||
GROUP BY jsonb_path_query_first(ffprobe_data, '$.format.format_name');`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Container: %w", err)
|
||||
}
|
||||
|
@ -135,7 +134,7 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
rows, err = db.Query(ctx,
|
||||
`SELECT health AS id, COUNT(*) AS value
|
||||
FROM files
|
||||
GROUP BY 1;`)
|
||||
GROUP BY health;`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Health: %w", err)
|
||||
}
|
||||
|
@ -156,7 +155,7 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
rows, err = db.Query(ctx,
|
||||
`SELECT transcode AS id, COUNT(*) AS value
|
||||
FROM files
|
||||
GROUP BY 1;`)
|
||||
GROUP BY transcode;`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Transcode: %w", err)
|
||||
}
|
||||
|
@ -177,7 +176,7 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
rows, err = db.Query(ctx,
|
||||
`SELECT status AS id, COUNT(*) AS value
|
||||
FROM tasks
|
||||
GROUP BY 1;`)
|
||||
GROUP BY status;`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Task Status: %w", err)
|
||||
}
|
||||
|
@ -195,66 +194,6 @@ func generateStats(ctx context.Context) ([]ChartData, error) {
|
|||
}
|
||||
data = append(data, generatePie("Task Status", res))
|
||||
|
||||
type BarTaskRowValue struct {
|
||||
Date time.Time
|
||||
Status constants.TaskStatus
|
||||
Count int
|
||||
}
|
||||
|
||||
rows, err = db.Query(ctx,
|
||||
`SELECT date_trunc('day', updated_at) date, status, COUNT(*) AS count
|
||||
FROM tasks
|
||||
WHERE status = $1 OR status = $2
|
||||
GROUP BY 1,2;`, constants.TASK_STATUS_SUCCESS, constants.TASK_STATUS_FAILED)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Query Task Status Day: %w", err)
|
||||
}
|
||||
|
||||
taskStatusDayCounts, err := pgx.CollectRows(rows, pgx.RowToStructByName[BarTaskRowValue])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Collect Task Status Day Data: %w", err)
|
||||
}
|
||||
|
||||
days := []string{}
|
||||
successBarData := []opts.BarData{}
|
||||
failedBarData := []opts.BarData{}
|
||||
for _, v := range taskStatusDayCounts {
|
||||
days = append(days, v.Date.Format(time.DateOnly))
|
||||
if v.Status == constants.TASK_STATUS_SUCCESS {
|
||||
successBarData = append(successBarData, opts.BarData{
|
||||
Value: v.Count,
|
||||
})
|
||||
} else if v.Status == constants.TASK_STATUS_FAILED {
|
||||
failedBarData = append(failedBarData, opts.BarData{
|
||||
Value: v.Count,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
bar := charts.NewBar()
|
||||
bar.SetGlobalOptions(
|
||||
charts.WithInitializationOpts(opts.Initialization{
|
||||
Theme: "dark",
|
||||
BackgroundColor: "#111",
|
||||
}),
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "Task Success/Failed Per Day",
|
||||
}),
|
||||
)
|
||||
bar.SetXAxis(days).
|
||||
AddSeries("Success", successBarData).
|
||||
AddSeries("Failed", failedBarData).
|
||||
SetSeriesOptions(charts.WithBarChartOpts(opts.BarChart{
|
||||
Stack: "stackA",
|
||||
}))
|
||||
|
||||
snippet := bar.RenderSnippet()
|
||||
|
||||
data = append(data, ChartData{
|
||||
Element: template.HTML(snippet.Element),
|
||||
Script: template.HTML(snippet.Script),
|
||||
})
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue