Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat commits and past 7 days #565

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions go/exec/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ const (

type BenchmarkStats struct {
Total int
Finished int
Last30Days int
Commits int
Last7Days []int
}

func GetBenchmarkStats(client storage.SQLClient) (BenchmarkStats, error) {
rows, err := client.Select(`SELECT
rows, err := client.Select(`SELECT
(SELECT COUNT(uuid) FROM execution) AS count_status,
(SELECT COUNT(*) FROM execution WHERE status = 'finished') AS count_finished,
(SELECT COUNT(DISTINCT git_ref) FROM execution) AS count_commits,
(SELECT COUNT(*) FROM execution WHERE started_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)) AS count_all
FROM
FROM
execution
LIMIT 1;`)

Expand All @@ -52,10 +53,38 @@ func GetBenchmarkStats(client storage.SQLClient) (BenchmarkStats, error) {

var res BenchmarkStats
if rows.Next() {
err := rows.Scan(&res.Total, &res.Finished, &res.Last30Days)
err := rows.Scan(&res.Total, &res.Commits, &res.Last30Days)
if err != nil {
return BenchmarkStats{}, err
}
}

rows.Close()

rows, err = client.Select(`SELECT
COUNT(*)
FROM
execution
WHERE
started_at >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
GROUP BY
DATE_FORMAT(started_at, '%Y%m%d')
ORDER BY
DATE_FORMAT(started_at, '%Y%m%d') ASC
LIMIT 7;`)

if err != nil {
return BenchmarkStats{}, err
}

for rows.Next() {
var count int
err := rows.Scan(&count)
if err != nil {
return BenchmarkStats{}, err
}
res.Last7Days = append(res.Last7Days, count)
}

return res, nil
}
Loading