Skip to content

Commit

Permalink
Merge pull request #565 from vitessio/feat/commits-and-past-7-days
Browse files Browse the repository at this point in the history
Feat commits and past 7 days
  • Loading branch information
frouioui authored Jul 8, 2024
2 parents 6713638 + 3c6107c commit f5217cf
Showing 1 changed file with 34 additions and 5 deletions.
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
}

0 comments on commit f5217cf

Please sign in to comment.