@@ -53,24 +53,45 @@ ORDER BY Date`,
5353}
5454
5555type StatusPerWeek struct {
56- Date time.Time `spanner:"Date"`
57- Finished int64 `spanner:"Finished"`
58- Skipped int64 `spanner:"Skipped"`
56+ Date time.Time `spanner:"Date"`
57+ Total int64 `spanner:"Total"`
58+ Finished int64
59+ Skipped int64 `spanner:"Skipped"`
60+ WithFailedSteps int64 `spanner:"WithFailedSteps"`
61+ WithSkippedSteps int64 `spanner:"WithSkippedSteps"`
5962}
6063
6164func (repo * StatsRepository ) SessionStatusPerWeek (ctx context.Context ) (
6265 []* StatusPerWeek , error ) {
63- return readEntities [StatusPerWeek ](ctx , repo .client .Single (), spanner.Statement {
64- SQL : `SELECT
65- TIMESTAMP_TRUNC(Sessions.FinishedAt, WEEK) as Date,
66- COUNTIF(Sessions.SkipReason IS NULL) as Finished,
67- COUNTIF(Sessions.SkipReason IS NOT NULL) as Skipped
68- FROM Series
69- JOIN Sessions ON Sessions.ID = Series.LatestSessionID
70- WHERE FinishedAt IS NOT NULL
66+ rows , err := readEntities [StatusPerWeek ](ctx , repo .client .Single (), spanner.Statement {
67+ SQL : `WITH SessionTestAggregates AS (
68+ SELECT
69+ SessionID,
70+ COUNTIF(Result = 'failed') > 0 AS HasFailedSteps,
71+ COUNTIF(Result = 'skipped') > 0 AS HasSkippedSteps
72+ FROM SessionTests
73+ GROUP BY SessionID
74+ )
75+ SELECT
76+ TIMESTAMP_TRUNC(Sessions.FinishedAt, WEEK) AS Date,
77+ COUNT(Sessions.ID) AS Total,
78+ COUNTIF(Sessions.SkipReason IS NOT NULL) AS Skipped,
79+ COUNTIF(sta.HasFailedSteps) AS WithFailedSteps,
80+ COUNTIF(sta.HasSkippedSteps AND NOT sta.HasFailedSteps) AS WithSkippedSteps
81+ FROM Sessions
82+ LEFT JOIN
83+ SessionTestAggregates AS sta ON Sessions.ID = sta.SessionID
84+ WHERE Sessions.FinishedAt IS NOT NULL
7185GROUP BY Date
7286ORDER BY Date` ,
7387 })
88+ if err != nil {
89+ return nil , err
90+ }
91+ for _ , row := range rows {
92+ row .Finished = row .Total - row .Skipped - row .WithFailedSteps - row .WithSkippedSteps
93+ }
94+ return rows , err
7495}
7596
7697type DelayPerWeek struct {
0 commit comments