scoring

package
v0.0.57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

README

api/sinks/postgres/scoring

Read queries and initialization for the scoring tables. Score insertion lives in the sibling agent package; this package is responsible for seeding and reading.

Seeding populates the running-totals table at startup with a zero row for every team, box, and service combination — using insert-or-ignore so pre-existing counters are not reset on restart. Read queries cover six views: most recent result per service (current status), totals per team, totals per box, totals per box and service, a full three-level team/box/service breakdown, and a bounded history of the newest results for each of a single team's services.

The history query is issued once per service rather than once per request, so that every service is guaranteed its own share of results even though services are not checked in lockstep. Each query is an indexed top-N lookup that reads only the rows it returns, and the services are walked in configuration order so the combined result is already sorted by box and then service without a sort step. Also provides helpers for converting raw pass/total counts into a rounded uptime percentage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentServiceStatus

func GetCurrentServiceStatus(ctx context.Context, db *pgxpool.Pool, cfg *config.APIConfigSpec) ([]types.Score, error)

GetCurrentServiceStatus returns the entire recent scores table. It is sorted by team number, then box ID, then service ID.

func GetRecentNScores added in v0.0.57

func GetRecentNScores(
	ctx context.Context,
	db *pgxpool.Pool,
	cfg *config.APIConfigSpec,
	teamNum types.TeamNum,
	numChecks int,
) ([]types.Score, error)

GetRecentNScores collects the numChecks most recent scores for every service on every box belonging to a single team. Results are sorted by box, then service, then newest check first.

func InitScoring

func InitScoring(ctx context.Context, db *pgxpool.Pool, cfg *config.APIConfigSpec) error

InitScoring creates rows in the final scores table for each team/box/service combo.

Types

type BoxScores

type BoxScores map[types.BoxName]types.ScoreResult

BoxScores is a map that can be used to quickly reference stats for a specific box.

func GetBoxScores

func GetBoxScores(ctx context.Context, db *pgxpool.Pool) (BoxScores, error)

GetBoxScores collates and calculates competion scores for all teams.

type DetailedScores

type DetailedScores map[types.TeamNum]ServiceScores

DetailedScores is a double-nested map that can be used to quickly reference stats for a specific teams' boxes' services. EXTREMELY ugly but i cant think of a better way to do this. this is a map[]map[]map[]. team_num -> box -> service.

func GetDetailedScores

func GetDetailedScores(ctx context.Context, db *pgxpool.Pool) (DetailedScores, error)

GetDetailedScores pulls the full final scoring data as it is stored in the db.

type ServiceScores

type ServiceScores map[types.BoxName]map[types.ServiceName]types.ScoreResult

ServiceScores is a nested map that can be used to quickly reference stats for a specific boxes' specific service. very ugly but i cant think of a better way to do this.

func GetServiceScores

func GetServiceScores(ctx context.Context, db *pgxpool.Pool) (ServiceScores, error)

GetServiceScores collates and calculates competion scores for each service on each box.

type TeamScores

type TeamScores map[types.TeamNum]types.ScoreResult

TeamScores is a map that can be used to quickly reference a specific teams stats.

func GetTeamScores

func GetTeamScores(ctx context.Context, db *pgxpool.Pool) (TeamScores, error)

GetTeamScores collates and calculates competion scores for all teams.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL