- Introduced EventWithSettings and EventWithSettingsRes structs for enhanced event data handling. - Implemented conversion functions for creating and updating event settings. - Added support for fetching events with settings from the database. - Created new report data structures for comprehensive reporting capabilities. - Implemented event statistics retrieval and filtering by league and sport. - Added handlers for event statistics endpoints in the web server. - Introduced DateInterval type for managing time intervals in reports.
260 lines
7.3 KiB
Go
260 lines
7.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: events_stat.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const GetTotalEventStats = `-- name: GetTotalEventStats :one
|
|
SELECT COUNT(*) AS event_count,
|
|
COUNT(*) FILTER (
|
|
WHERE events.default_is_active = TRUE
|
|
) AS total_active_events,
|
|
COUNT(*) FILTER (
|
|
WHERE events.default_is_active = FALSE
|
|
) AS total_inactive_events,
|
|
COUNT(*) FILTER (
|
|
WHERE events.default_is_featured = TRUE
|
|
) AS total_featured_events,
|
|
COUNT(DISTINCT league_id) as total_leagues,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'upcoming'
|
|
) AS pending,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'in_play'
|
|
) AS in_play,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'to_be_fixed'
|
|
) AS to_be_fixed,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'ended'
|
|
) AS ended,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'postponed'
|
|
) AS postponed,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'cancelled'
|
|
) AS cancelled,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'walkover'
|
|
) AS walkover,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'interrupted'
|
|
) AS interrupted,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'abandoned'
|
|
) AS abandoned,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'retired'
|
|
) AS retired,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'suspended'
|
|
) AS suspended,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'decided_by_fa'
|
|
) AS decided_by_fa,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'removed'
|
|
) AS removed
|
|
FROM events
|
|
WHERE (
|
|
events.league_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
events.sport_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetTotalEventStatsParams struct {
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
}
|
|
|
|
type GetTotalEventStatsRow struct {
|
|
EventCount int64 `json:"event_count"`
|
|
TotalActiveEvents int64 `json:"total_active_events"`
|
|
TotalInactiveEvents int64 `json:"total_inactive_events"`
|
|
TotalFeaturedEvents int64 `json:"total_featured_events"`
|
|
TotalLeagues int64 `json:"total_leagues"`
|
|
Pending int64 `json:"pending"`
|
|
InPlay int64 `json:"in_play"`
|
|
ToBeFixed int64 `json:"to_be_fixed"`
|
|
Ended int64 `json:"ended"`
|
|
Postponed int64 `json:"postponed"`
|
|
Cancelled int64 `json:"cancelled"`
|
|
Walkover int64 `json:"walkover"`
|
|
Interrupted int64 `json:"interrupted"`
|
|
Abandoned int64 `json:"abandoned"`
|
|
Retired int64 `json:"retired"`
|
|
Suspended int64 `json:"suspended"`
|
|
DecidedByFa int64 `json:"decided_by_fa"`
|
|
Removed int64 `json:"removed"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalEventStats(ctx context.Context, arg GetTotalEventStatsParams) (GetTotalEventStatsRow, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalEventStats, arg.LeagueID, arg.SportID)
|
|
var i GetTotalEventStatsRow
|
|
err := row.Scan(
|
|
&i.EventCount,
|
|
&i.TotalActiveEvents,
|
|
&i.TotalInactiveEvents,
|
|
&i.TotalFeaturedEvents,
|
|
&i.TotalLeagues,
|
|
&i.Pending,
|
|
&i.InPlay,
|
|
&i.ToBeFixed,
|
|
&i.Ended,
|
|
&i.Postponed,
|
|
&i.Cancelled,
|
|
&i.Walkover,
|
|
&i.Interrupted,
|
|
&i.Abandoned,
|
|
&i.Retired,
|
|
&i.Suspended,
|
|
&i.DecidedByFa,
|
|
&i.Removed,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetTotalEventStatsByInterval = `-- name: GetTotalEventStatsByInterval :many
|
|
SELECT DATE_TRUNC($1, start_time)::timestamp AS date,
|
|
COUNT(*) AS event_count,
|
|
COUNT(*) FILTER (
|
|
WHERE events.default_is_active = TRUE
|
|
) AS total_active_events,
|
|
COUNT(*) FILTER (
|
|
WHERE events.default_is_active = FALSE
|
|
) AS total_inactive_events,
|
|
COUNT(*) FILTER (
|
|
WHERE events.default_is_featured = TRUE
|
|
) AS total_featured_events,
|
|
COUNT(DISTINCT league_id) as total_leagues,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'upcoming'
|
|
) AS pending,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'in_play'
|
|
) AS in_play,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'to_be_fixed'
|
|
) AS to_be_fixed,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'ended'
|
|
) AS ended,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'postponed'
|
|
) AS postponed,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'cancelled'
|
|
) AS cancelled,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'walkover'
|
|
) AS walkover,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'interrupted'
|
|
) AS interrupted,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'abandoned'
|
|
) AS abandoned,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'retired'
|
|
) AS retired,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'suspended'
|
|
) AS suspended,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'decided_by_fa'
|
|
) AS decided_by_fa,
|
|
COUNT(*) FILTER (
|
|
WHERE events.status = 'removed'
|
|
) AS removed
|
|
FROM events
|
|
WHERE (
|
|
events.league_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
events.sport_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
GROUP BY date
|
|
ORDER BY date
|
|
`
|
|
|
|
type GetTotalEventStatsByIntervalParams struct {
|
|
Interval pgtype.Text `json:"interval"`
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
}
|
|
|
|
type GetTotalEventStatsByIntervalRow struct {
|
|
Date pgtype.Timestamp `json:"date"`
|
|
EventCount int64 `json:"event_count"`
|
|
TotalActiveEvents int64 `json:"total_active_events"`
|
|
TotalInactiveEvents int64 `json:"total_inactive_events"`
|
|
TotalFeaturedEvents int64 `json:"total_featured_events"`
|
|
TotalLeagues int64 `json:"total_leagues"`
|
|
Pending int64 `json:"pending"`
|
|
InPlay int64 `json:"in_play"`
|
|
ToBeFixed int64 `json:"to_be_fixed"`
|
|
Ended int64 `json:"ended"`
|
|
Postponed int64 `json:"postponed"`
|
|
Cancelled int64 `json:"cancelled"`
|
|
Walkover int64 `json:"walkover"`
|
|
Interrupted int64 `json:"interrupted"`
|
|
Abandoned int64 `json:"abandoned"`
|
|
Retired int64 `json:"retired"`
|
|
Suspended int64 `json:"suspended"`
|
|
DecidedByFa int64 `json:"decided_by_fa"`
|
|
Removed int64 `json:"removed"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalEventStatsByInterval(ctx context.Context, arg GetTotalEventStatsByIntervalParams) ([]GetTotalEventStatsByIntervalRow, error) {
|
|
rows, err := q.db.Query(ctx, GetTotalEventStatsByInterval, arg.Interval, arg.LeagueID, arg.SportID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetTotalEventStatsByIntervalRow
|
|
for rows.Next() {
|
|
var i GetTotalEventStatsByIntervalRow
|
|
if err := rows.Scan(
|
|
&i.Date,
|
|
&i.EventCount,
|
|
&i.TotalActiveEvents,
|
|
&i.TotalInactiveEvents,
|
|
&i.TotalFeaturedEvents,
|
|
&i.TotalLeagues,
|
|
&i.Pending,
|
|
&i.InPlay,
|
|
&i.ToBeFixed,
|
|
&i.Ended,
|
|
&i.Postponed,
|
|
&i.Cancelled,
|
|
&i.Walkover,
|
|
&i.Interrupted,
|
|
&i.Abandoned,
|
|
&i.Retired,
|
|
&i.Suspended,
|
|
&i.DecidedByFa,
|
|
&i.Removed,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|