Documentation ¶
Index ¶
- type Comment
- type ErrExists
- type ErrFKeyViolation
- type ErrNoResults
- type Event
- type Leaderboard
- type Match
- type PatchSchema
- type PatchUser
- type Realm
- type Report
- type ReportData
- type Roles
- type Schema
- type Service
- func (s *Service) AlliancesUpsert(ctx context.Context, matchKey string, blueAlliance []string, ...) error
- func (s *Service) CheckMatchKeyExists(matchKey string) (bool, error)
- func (s *Service) CheckSimilarUsernameExists(ctx context.Context, username string, id *int64) error
- func (s *Service) CheckTBAEventKeyExists(ctx context.Context, eventKey string) (bool, error)
- func (s *Service) Close() error
- func (s *Service) CreateSchema(ctx context.Context, schema Schema) error
- func (s *Service) CreateUser(ctx context.Context, u User) error
- func (s *Service) DeleteRealm(ctx context.Context, id int64) error
- func (s *Service) DeleteUser(ctx context.Context, id int64) error
- func (s *Service) EventsUpsert(ctx context.Context, events []Event) error
- func (s *Service) GetEvent(ctx context.Context, eventKey string) (Event, error)
- func (s *Service) GetEventComments(ctx context.Context, eventKey, teamKey string) (comments []Comment, err error)
- func (s *Service) GetEventReports(ctx context.Context, eventKey string, realmID *int64) ([]Report, error)
- func (s *Service) GetEvents(ctx context.Context, tbaDeleted bool) ([]Event, error)
- func (s *Service) GetEventsFromRealm(ctx context.Context, realm *int64, tbaDeleted bool) ([]Event, error)
- func (s *Service) GetLeaderboard(ctx context.Context) (Leaderboard, error)
- func (s *Service) GetMatch(ctx context.Context, matchKey string) (Match, error)
- func (s *Service) GetMatchTeamComments(ctx context.Context, matchKey, teamKey string) (comments []Comment, err error)
- func (s *Service) GetMatches(ctx context.Context, eventKey string, teamKeys []string, tbaDeleted bool) ([]Match, error)
- func (s *Service) GetPublicRealms(ctx context.Context) ([]Realm, error)
- func (s *Service) GetRealm(ctx context.Context, id int64) (Realm, error)
- func (s *Service) GetRealms(ctx context.Context) ([]Realm, error)
- func (s *Service) GetReportsBySchemaID(ctx context.Context, schemaID int64) ([]Report, error)
- func (s *Service) GetSchemaByID(ctx context.Context, id int64) (Schema, error)
- func (s *Service) GetSchemaByYear(ctx context.Context, year int) (Schema, error)
- func (s *Service) GetSchemas(ctx context.Context) ([]Schema, error)
- func (s *Service) GetTeam(ctx context.Context, teamKey string, eventKey string) (Team, error)
- func (s *Service) GetTeamEventReports(ctx context.Context, eventKey string, teamKey string, realmID *int64) ([]Report, error)
- func (s *Service) GetTeamKeys(ctx context.Context, eventKey string) ([]string, error)
- func (s *Service) GetTeamMatchReports(ctx context.Context, matchKey string, teamKey string) ([]Report, error)
- func (s *Service) GetUserByID(ctx context.Context, id int64) (User, error)
- func (s *Service) GetUserByUsername(ctx context.Context, username string) (User, error)
- func (s *Service) GetUsers(ctx context.Context) ([]User, error)
- func (s *Service) GetUsersByRealm(ctx context.Context, realmID int64) ([]User, error)
- func (s *Service) GetVisibleSchemas(ctx context.Context, realmID *int64) ([]Schema, error)
- func (s *Service) InsertRealm(ctx context.Context, realm Realm) (int64, error)
- func (s *Service) MarkEventsDeleted(ctx context.Context, events []Event) error
- func (s *Service) MarkMatchesDeleted(ctx context.Context, eventKey string, matches []Match) error
- func (s *Service) PatchUser(ctx context.Context, pu PatchUser) error
- func (s *Service) Ping(ctx context.Context) error
- func (s *Service) TeamKeysUpsert(ctx context.Context, eventKey string, keys []string) error
- func (s *Service) TeamsUpsert(ctx context.Context, teams []Team) error
- func (s *Service) UpdateRealm(ctx context.Context, realm Realm) error
- func (s *Service) UpdateTBAMatches(ctx context.Context, eventKey string, matches []Match) error
- func (s *Service) UpsertEvent(ctx context.Context, event Event) (created bool, err error)
- func (s *Service) UpsertMatch(ctx context.Context, match Match) error
- func (s *Service) UpsertMatchTeamComment(ctx context.Context, c Comment) (created bool, err error)
- func (s *Service) UpsertReport(ctx context.Context, r Report) (created bool, err error)
- type Stat
- type StatDescription
- type StatDescriptions
- type Team
- type UnixTime
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comment ¶
type Comment struct { ID int64 `json:"id" db:"id"` EventKey string `json:"-" db:"event_key"` MatchKey string `json:"matchKey" db:"match_key"` TeamKey string `json:"-" db:"team_key"` ReporterID *int64 `json:"reporterId" db:"reporter_id"` RealmID *int64 `json:"-" db:"realm_id"` Comment string `json:"comment" db:"comment"` }
Comment defines a comment on a robots performance during a match. It is the qualitative equivalent of a report.
type ErrExists ¶
type ErrExists struct {
// contains filtered or unexported fields
}
ErrExists is returned if a unique record already exists.
type ErrFKeyViolation ¶
type ErrFKeyViolation struct {
// contains filtered or unexported fields
}
ErrFKeyViolation is returned if inserting a record causes a foreign key violation.
type ErrNoResults ¶
type ErrNoResults struct {
// contains filtered or unexported fields
}
ErrNoResults indicates that no data matching the query was found.
type Event ¶
type Event struct { Key string `json:"key" db:"key"` RealmID *int64 `json:"realmId,omitempty" db:"realm_id"` SchemaID *int64 `json:"schemaId,omitempty" db:"schema_id"` Name string `json:"name" db:"name"` District *string `json:"district,omitempty" db:"district"` FullDistrict *string `json:"fullDistrict,omitempty" db:"full_district"` Week *int `json:"week,omitempty" db:"week"` StartDate UnixTime `json:"startDate" db:"start_date"` EndDate UnixTime `json:"endDate" db:"end_date"` Webcasts pq.StringArray `json:"webcasts" db:"webcasts"` LocationName string `json:"locationName" db:"location_name"` Lat float64 `json:"lat" db:"lat"` Lon float64 `json:"lon" db:"lon"` TBADeleted bool `json:"tbaDeleted" db:"tba_deleted"` }
Event holds information about an FRC event such as webcast associated with it, the location, its start date, and more.
type Leaderboard ¶
type Leaderboard []struct { ReporterID int64 `json:"reporterId" db:"reporter_id"` Reports int64 `json:"reports" db:"num_reports"` }
Leaderboard holds information about how many reports each reporter submitted.
type Match ¶
type Match struct { Key string `json:"key" db:"key"` EventKey string `json:"eventKey" db:"event_key"` PredictedTime *UnixTime `json:"predictedTime" db:"predicted_time"` ActualTime *UnixTime `json:"actualTime" db:"actual_time"` ScheduledTime *UnixTime `json:"scheduledTime" db:"scheduled_time"` RedScore *int `json:"redScore" db:"red_score"` BlueScore *int `json:"blueScore" db:"blue_score"` RedAlliance pq.StringArray `json:"redAlliance" db:"red_alliance"` BlueAlliance pq.StringArray `json:"blueAlliance" db:"blue_alliance"` TBADeleted bool `json:"tba_deleted" db:"tba_deleted"` }
Match holds information about an FRC match at a specific event
type PatchSchema ¶
type PatchSchema struct { ID int64 `json:"id" db:"id"` Year *int64 `json:"year,omitempty" db:"year"` Auto StatDescriptions `json:"auto" db:"auto"` Teleop StatDescriptions `json:"teleop" db:"teleop"` }
PatchSchema is a nullable schema for patching.
type PatchUser ¶
type PatchUser struct { ID int64 `json:"id" db:"id"` Username *string `json:"username" db:"username"` HashedPassword *string `json:"-" db:"hashed_password"` PasswordChanged *UnixTime `json:"-" db:"password_changed"` FirstName *string `json:"firstName" db:"first_name"` LastName *string `json:"lastName" db:"last_name"` Roles *Roles `json:"roles" db:"roles"` Stars pq.StringArray `json:"stars"` }
PatchUser is like User but with all nullable fields (besides id and realmID) for patching.
type Realm ¶
type Realm struct { ID int64 `json:"id" db:"id"` Name string `json:"name" db:"name" validate:"omitempty,gte=1,lte=32"` }
Realm holds the name of a realm, and whether to share the realms reports.
type Report ¶
type Report struct { ID int64 `json:"-" db:"id"` MatchKey string `json:"-" db:"match_key"` TeamKey string `json:"-" db:"team_key"` ReporterID *int64 `json:"reporterId" db:"reporter_id"` RealmID *int64 `json:"-" db:"realm_id"` AutoName string `json:"autoName" db:"auto_name"` Data ReportData `json:"data" db:"data"` }
Report is data about how an FRC team performed in a specific match.
type ReportData ¶
ReportData holds all the data in a report
func (*ReportData) Scan ¶
func (rd *ReportData) Scan(src interface{}) error
Scan implements sql.Scanner to scan JSON from the DB into ReportData.
type Roles ¶
type Roles struct { IsSuperAdmin bool `json:"isSuperAdmin" yaml:"isSuperAdmin"` IsAdmin bool `json:"isAdmin" yaml:"isAdmin"` IsVerified bool `json:"isVerified" yaml:"isVerified"` }
Roles holds information about a users roles and permissions such as whether they are an administrator.
type Schema ¶
type Schema struct { ID int64 `json:"id" db:"id"` Year *int64 `json:"year,omitempty" db:"year"` RealmID *int64 `json:"realmId,omitempty" db:"realm_id"` Auto StatDescriptions `json:"auto" db:"auto"` Teleop StatDescriptions `json:"teleop" db:"teleop"` }
Schema describes the statistics that reports should include
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides methods for storing data in a PostgreSQL database.
func New ¶
New creates a new store service from a dataSourceName. The logger is used to log errors that would not otherwise be returned such as issues rolling back transactions. The context passed is used for pinging the database.
func (*Service) AlliancesUpsert ¶
func (s *Service) AlliancesUpsert(ctx context.Context, matchKey string, blueAlliance []string, redAlliance []string, tx *sqlx.Tx) error
AlliancesUpsert upserts the red and blue alliances for a specific match. matchKey is the key of the match. Upsert done within transaction.
func (*Service) CheckMatchKeyExists ¶
CheckMatchKeyExists returns whether the match key exists in the database.
func (*Service) CheckSimilarUsernameExists ¶
CheckSimilarUsernameExists checks whether a user with (case insensitive) the same username exists. It returns an ErrExists if a similar user exists. If an id is given, it will ignore the user with that id.
func (*Service) CheckTBAEventKeyExists ¶
CheckTBAEventKeyExists checks whether a specific event key exists and is from TBA rather than manually added. Returns ErrNoResults if event does not exist.
func (*Service) CreateSchema ¶
CreateSchema creates a new schema
func (*Service) CreateUser ¶
CreateUser creates a given user.
func (*Service) DeleteRealm ¶
DeleteRealm deletes a realm from the database.
func (*Service) DeleteUser ¶
DeleteUser deletes a specific user from the database.
func (*Service) EventsUpsert ¶
EventsUpsert upserts multiple events into the database. It will set tba_deleted to false for all updated events.
func (*Service) GetEventComments ¶
func (s *Service) GetEventComments(ctx context.Context, eventKey, teamKey string) (comments []Comment, err error)
GetEventComments gets all comments for a given team in an event.
func (*Service) GetEventReports ¶
func (s *Service) GetEventReports(ctx context.Context, eventKey string, realmID *int64) ([]Report, error)
GetEventReports retrieves all reports for an event from the db. If a realmID is specified, only reports from that realm will be included.
func (*Service) GetEvents ¶
GetEvents returns all events from the database. event.Webcasts and schemaID will be nil for every event. If tbaDeleted is true, events that have been deleted from TBA will be returned in addition to events that have not been deleted. Otherwise, only events that have not been deleted will be returned.
func (*Service) GetEventsFromRealm ¶
func (s *Service) GetEventsFromRealm(ctx context.Context, realm *int64, tbaDeleted bool) ([]Event, error)
GetEventsFromRealm returns all events from a specific realm. Additionally all TBA events will be retrieved. If no realm is specified (nil) then just the TBA events will be retrieved. event.Webcasts and schemaID will be nil for every event. If tbaDeleted is true, events that have been deleted from TBA will be returned in addition to events that have not been deleted. Otherwise, only events that have not been deleted will be returned.
func (*Service) GetLeaderboard ¶
func (s *Service) GetLeaderboard(ctx context.Context) (Leaderboard, error)
GetLeaderboard retrieves leaderboard information from the reports and users table.
func (*Service) GetMatchTeamComments ¶
func (s *Service) GetMatchTeamComments(ctx context.Context, matchKey, teamKey string) (comments []Comment, err error)
GetMatchTeamComments gets all comments for a given team in a match.
func (*Service) GetMatches ¶
func (s *Service) GetMatches(ctx context.Context, eventKey string, teamKeys []string, tbaDeleted bool) ([]Match, error)
GetMatches returns all matches from a specific event that include the given teams. If teams is nil or empty a list of all the matches for that event are returned. // If tbaDeleted is true, matches that have been deleted from TBA will be returned in addition to matches that have not been deleted. Otherwise, only matches that have not been deleted will be returned.
func (*Service) GetPublicRealms ¶
GetPublicRealms returns all public realms in the database.
func (*Service) GetReportsBySchemaID ¶
GetReportsBySchemaID retrieves all reports with a specific schema.
func (*Service) GetSchemaByID ¶
GetSchemaByID retrieves a schema given its ID
func (*Service) GetSchemaByYear ¶
GetSchemaByYear retrieves the schema for a given year
func (*Service) GetSchemas ¶
GetSchemas retrieves all schemas from the database.
func (*Service) GetTeam ¶
GetTeam retrieves a team specified by teamKey from a event specified by eventKey.
func (*Service) GetTeamEventReports ¶
func (s *Service) GetTeamEventReports(ctx context.Context, eventKey string, teamKey string, realmID *int64) ([]Report, error)
GetTeamEventReports retrieves all reports for a specific team and event from the db. If a realmID is specified, only reports from that realm will be included.
func (*Service) GetTeamKeys ¶
GetTeamKeys retrieves all team keys from an event specified by eventKey.
func (*Service) GetTeamMatchReports ¶
func (s *Service) GetTeamMatchReports(ctx context.Context, matchKey string, teamKey string) ([]Report, error)
GetTeamMatchReports retrieves all reports for a specific team and match from the db.
func (*Service) GetUserByID ¶
GetUserByID retrieves a user from the database by id.
func (*Service) GetUserByUsername ¶
GetUserByUsername retrieves a user from the database by username. It does not retrieve the users stars.
func (*Service) GetUsersByRealm ¶
GetUsersByRealm retrieves all users in a specific realm.
func (*Service) GetVisibleSchemas ¶
GetVisibleSchemas retrieves schemas from the database frm a specific realm, from realms with public events, and standard FRC schemas. If the realm ID is nil, no private realms' schemas will be retrieved.
func (*Service) InsertRealm ¶
InsertRealm inserts a realm into the database.
func (*Service) MarkEventsDeleted ¶
MarkEventsDeleted will set tba_deleted to true on all events that were *not* included in the events slice and are not custom events (have a NULL realm_id).
func (*Service) MarkMatchesDeleted ¶
MarkMatchesDeleted will set tba_deleted to true on all matches for an event that were *not* included in the passed matches slice.
func (*Service) Ping ¶
Ping pings the underlying postgresql database. You would think we would call db.Ping() here, but that doesn't actually Ping the database because reasons.
func (*Service) TeamKeysUpsert ¶
TeamKeysUpsert upserts multiple team keys from a single event into the database.
func (*Service) TeamsUpsert ¶
TeamsUpsert upserts multiple teams into the database.
func (*Service) UpdateRealm ¶
UpdateRealm updates a realm.
func (*Service) UpdateTBAMatches ¶
UpdateTBAMatches puts a set of multiple matches and their alliances from TBA into the database. New matches are added, existing matches will be updated, and matches deleted from TBA will be deleted from the database. User-created matches will be unaffected. If eventKey is specified, only matches from that event will be affected. It will set tba_deleted to false for all updated matches.
func (*Service) UpsertEvent ¶
UpsertEvent upserts a single event into the database and returns whether the event was created or updated.
func (*Service) UpsertMatch ¶
UpsertMatch upserts a match and its alliances into the database.
func (*Service) UpsertMatchTeamComment ¶
UpsertMatchTeamComment will upsert a comment for a team in a match. There can only be one comment per reporter per team per match per event.
func (*Service) UpsertReport ¶
UpsertReport creates a new report in the db, or replaces the existing one if the same reporter already has a report in the db for that team and match. It returns a boolean that is true when the report was created, and false when it was updated.
type Stat ¶
type Stat struct { Attempts *int `json:"attempts,omitempty"` Successes *int `json:"successes,omitempty"` Name string `json:"name"` }
A Stat holds a single statistic from a single match, and could be either a boolean or numeric statistic
type StatDescription ¶
StatDescription describes a single statistic in a schema
type StatDescriptions ¶
type StatDescriptions []StatDescription
StatDescriptions holds multiple StatDescriptions for storing in one DB column
func (*StatDescriptions) Scan ¶
func (sd *StatDescriptions) Scan(src interface{}) error
Scan implements sql.Scanner to scan JSON from the DB into StatDescriptions.
type Team ¶
type Team struct { Key string `db:"key"` EventKey string `db:"event_key"` Rank *int `db:"rank"` RankingScore *float64 `db:"ranking_score"` }
Team holds data about a single FRC team at a specific event.
type UnixTime ¶
type UnixTime struct {
Unix int64
}
UnixTime exists so that we can have times that look like time.Time's to database drivers and JSON marshallers/unmarshallers but are internally represented as unix timestamps for easier comparison.
func NewUnixFromInt ¶
NewUnixFromInt creates a new UnixTime timestamp from an int64.
func NewUnixFromTime ¶
NewUnixFromTime creates a new UnixTime timestamp from a time.Time.
func (*UnixTime) MarshalJSON ¶
MarshalJSON returns a []byte that represents this UnixTime in RFC 3339 format.
func (*UnixTime) Scan ¶
Scan accepts either a time.Time or an int64 for scanning from a database into a unix timestamp.
func (*UnixTime) UnmarshalJSON ¶
UnmarshalJSON accepts a []byte representing a time.Time value, and unmarshals it into a unix timestamp.
type User ¶
type User struct { ID int64 `json:"id" db:"id"` Username string `json:"username" db:"username"` HashedPassword string `json:"-" db:"hashed_password"` PasswordChanged UnixTime `json:"-" db:"password_changed"` RealmID int64 `json:"realmId" db:"realm_id"` FirstName string `json:"firstName" db:"first_name"` LastName string `json:"lastName" db:"last_name"` Roles Roles `json:"roles" db:"roles"` Stars pq.StringArray `json:"stars" db:"stars"` }
User holds information about a user such as their id, username, and hashed password.