Documentation
¶
Index ¶
- Constants
- func AdminLogout(db db.Db, id uuid.UUID) error
- func CalculateElo(a, b *Player, outcome Outcome) (int, int)deprecated
- func CalculateLiglicko2(a, b *Player, outcome Outcome, playedAt time.Time) (float64, float64, error)
- func DeleteGame(db db.Db, adminId uuid.UUID, ikey int64) error
- func DeletePlayer(db db.Db, playerId, adminId uuid.UUID) error
- func GetRemoteAddr(r *http.Request) string
- func GetTotalGameCount(db db.Db) (int, error)
- func GetTotalPlayerCount(db db.Db) (int, error)
- func InsertAdminUser(tx *sqlx.Tx, user AdminUser) error
- func InsertAuditLog(tx *sqlx.Tx, auditLog *AuditLog) error
- func InsertAuditLogGameAffected(tx *sqlx.Tx, gameAffected *AuditLogGameAffected) error
- func InsertAuditLogPlayerAffected(tx *sqlx.Tx, playerAffected *AuditLogPlayerAffected) error
- func InsertPlayer(db db.Db, player Player) error
- func InsertPlayerTx(tx *sqlx.Tx, player Player) error
- func Liglicko2InstantFromTime(t time.Time) float64
- func MergePlayers(db db.Db, target, dest, adminId uuid.UUID) error
- func NextIKey(db db.Db) (int64, error)
- func PlayerEloChart(db db.Db, id uuid.UUID) ([]byte, error)
- func RenamePlayer(db db.Db, id uuid.UUID, newName string, adminId uuid.UUID) error
- func ReplayFrom(txx *sqlx.Tx, ikey int64, initialPlayers map[uuid.UUID]*Player) ([]Game, []*Player, error)
- func SetGameToDraw(db db.Db, adminId uuid.UUID, ikey int64) error
- func SetLeaguePlayers(db db.Db, adminId uuid.UUID, players []uuid.UUID) error
- func SubmitGame(db db.Db, whiteName, blackName string, submitterIsWhite bool, ikey int64, ...) (*Game, *Player, *Player, int, int, error)
- func SwapGameWinner(db db.Db, adminId uuid.UUID, ikey int64) error
- type AdminUser
- func AdminGetFromSessionKey(db db.Db, key string) (*AdminUser, error)
- func AdminLogin(db db.Db, name, oauthId, lastIp, LastUserAgent string) (*AdminUser, error)
- func GetAdminUser(db db.Db, id uuid.UUID) (*AdminUser, error)
- func GetAdminUsers(db db.Db) ([]AdminUser, error)
- func NewAdminUser(name, oauthId, lastIp, LastUserAgent string) *AdminUser
- type AuditLog
- type AuditLogGameAffected
- type AuditLogPlayerAffected
- type AuditLogUiFriendly
- func GetAuditLogsUiFriendly(db db.Db) ([]AuditLogUiFriendly, error)
- func GetAuditLogsUiFriendlyForAdmin(db db.Db, id uuid.UUID) ([]AuditLogUiFriendly, error)
- func GetAuditLogsUiFriendlyForGame(db db.Db, ikey int64) ([]AuditLogUiFriendly, error)
- func GetAuditLogsUiFriendlyForPlayer(db db.Db, id uuid.UUID) ([]AuditLogUiFriendly, error)
- type DetailedAuditLog
- type Game
- type GameWithDetails
- type GameWithOutcome
- type GameWithPlayerNames
- type GamesUiFriendly
- type LeaguePlayerUiFriendly
- type Liglicko2Rating
- type Outcome
- type Player
- func GetLeaguePlayers(tx *sqlx.Tx) ([]Player, error)
- func GetPlayer(db db.Db, id uuid.UUID) (Player, error)
- func GetPlayerTx(tx *sqlx.Tx, id uuid.UUID) (Player, error)
- func GetPlayers(db db.Db) ([]Player, error)
- func GetPlayersByElo(db db.Db, showDeleted bool) ([]Player, error)
- func NewPlayer(name string) Player
- func SearchPlayerByName(db db.Db, name string) ([]Player, error)
- type PlayerWithGameCount
- type Score
Constants ¶
View Source
const ( Outcome_Win = 1.0 Outcome_Loss = 0.0 Outcome_Draw = 0.5 )
View Source
const ( StartingLiglicko2Rating = 1500.0 StartingLiglicko2Deviation = 500.0 StartingLiglicko2Volatility = 0.09 )
View Source
const K = 30
View Source
const MaxSessionKeyAge = time.Hour
View Source
const MinimumStableRatingDeviation = 120.0
View Source
const StartingElo = 1000
Variables ¶
This section is empty.
Functions ¶
func CalculateElo
deprecated
func CalculateLiglicko2 ¶ added in v0.2.0
func GetRemoteAddr ¶ added in v0.2.0
GetRemoteAddr returns the remote IP address of the request. It prioritizes the X-Forwarded-For header if present, otherwise it uses r.RemoteAddr. If r.RemoteAddr contains a port, it is stripped.
func InsertAuditLogGameAffected ¶ added in v0.2.0
func InsertAuditLogGameAffected(tx *sqlx.Tx, gameAffected *AuditLogGameAffected) error
func InsertAuditLogPlayerAffected ¶ added in v0.2.0
func InsertAuditLogPlayerAffected(tx *sqlx.Tx, playerAffected *AuditLogPlayerAffected) error
func Liglicko2InstantFromTime ¶ added in v0.2.0
func MergePlayers ¶ added in v0.2.0
func RenamePlayer ¶ added in v0.2.0
func ReplayFrom ¶ added in v0.2.0
func SetGameToDraw ¶ added in v0.2.0
func SetLeaguePlayers ¶ added in v0.2.0
func SubmitGame ¶
Types ¶
type AdminUser ¶ added in v0.2.0
type AdminUser struct {
Id uuid.UUID `db:"id"`
Name string `db:"name"`
OauthId string `db:"oauth_id"` // This is the Github login
Created time.Time `db:"created"`
SessionKey string `db:"session_key"`
LastLogin time.Time `db:"last_login"` // Used to know if the session key is expired
LastIp string `db:"last_ip"`
LastUserAgent string `db:"last_user_agent"`
}
func AdminGetFromSessionKey ¶ added in v0.2.0
func AdminLogin ¶ added in v0.2.0
func NewAdminUser ¶ added in v0.2.0
type AuditLog ¶ added in v0.2.0
type AuditLogGameAffected ¶ added in v0.2.0
type AuditLogPlayerAffected ¶ added in v0.2.0
type AuditLogPlayerAffected struct {
AuditLogId uuid.UUID `db:"audit_log_id"`
PlayerId uuid.UUID `db:"player_id"`
IsMainTarget bool `db:"is_main_target"`
PlayerName string `db:"player_name"`
}
func NewAuditLogPlayerAffected ¶ added in v0.2.0
type AuditLogUiFriendly ¶ added in v0.2.0
func GetAuditLogsUiFriendly ¶ added in v0.2.0
func GetAuditLogsUiFriendly(db db.Db) ([]AuditLogUiFriendly, error)
func GetAuditLogsUiFriendlyForAdmin ¶ added in v0.2.0
func GetAuditLogsUiFriendlyForGame ¶ added in v0.2.0
func GetAuditLogsUiFriendlyForGame(db db.Db, ikey int64) ([]AuditLogUiFriendly, error)
func GetAuditLogsUiFriendlyForPlayer ¶ added in v0.2.0
type DetailedAuditLog ¶ added in v0.2.0
type DetailedAuditLog struct {
AuditLog
AdminName string `db:"admin_name"`
Players []AuditLogPlayerAffected
Games []AuditLogGameAffected
}
func GetAuditLog ¶ added in v0.2.0
type Game ¶
type Game struct {
PlayerWhite uuid.UUID `db:"player_white"`
PlayerBlack uuid.UUID `db:"player_black"`
Score Score `db:"score"`
Submitter uuid.UUID `db:"submitter"`
Played time.Time `db:"played"`
Deleted bool `db:"deleted"`
SubmitIp string `db:"submit_ip"`
SubmitUserAgent string `db:"submit_user_agent"`
IKey int64 `db:"ikey"`
DEPRECATEDEloGiven int `db:"elo_given"` // Deprecated: for use with old elo system
DEPRECATEDEloTaken int `db:"elo_taken"` // Deprecated: for use with old elo system
// Liglicko2White and Liglicko2Black are per-game liglicko2 deltas for each side.
// They preserve sign, so draws between uneven players can still show non-zero
// changes.
Liglicko2White float64 `db:"liglicko2_white"`
Liglicko2WhiteOldRating float64 `db:"liglicko2_white_old_rating"`
Liglicko2WhiteOldVolatility float64 `db:"liglicko2_white_old_volatility"`
Liglicko2WhiteOldDeviation float64 `db:"liglicko2_white_old_deviation"`
Liglicko2WhiteOldAt float64 `db:"liglicko2_white_old_at"`
Liglicko2Black float64 `db:"liglicko2_black"`
Liglicko2BlackOldRating float64 `db:"liglicko2_black_old_rating"`
Liglicko2BlackOldVolatility float64 `db:"liglicko2_black_old_volatility"`
Liglicko2BlackOldDeviation float64 `db:"liglicko2_black_old_deviation"`
Liglicko2BlackOldAt float64 `db:"liglicko2_black_old_at"`
}
func CreateGame ¶
type GameWithDetails ¶ added in v0.2.0
type GameWithDetails struct {
Game
WhiteName string `db:"white_name"`
BlackName string `db:"black_name"`
SubmitterName string `db:"submitter_name"`
}
func GetGameWithDetails ¶ added in v0.2.0
func GetGameWithDetails(db db.Db, ikey int64) (GameWithDetails, error)
func (GameWithDetails) WinnerName ¶ added in v0.2.0
func (g GameWithDetails) WinnerName() string
type GameWithOutcome ¶ added in v0.2.0
type GameWithOutcome struct {
Ikey int64
PlayerName string
OpponentName string
Outcome string
Played time.Time
Deleted bool
EloChange int
Liglicko2Change float64
}
func GetGamesWithOutcomes ¶ added in v0.2.0
func GetGamesWithOutcomes(db db.Db) ([]GameWithOutcome, error)
type GameWithPlayerNames ¶
type GameWithPlayerNames struct {
Game
WhiteName string `db:"white_name"`
BlackName string `db:"black_name"`
}
func GetGamesByPlayer ¶
func (*GameWithPlayerNames) MapGameToGameWithOutcome ¶ added in v0.2.0
func (g *GameWithPlayerNames) MapGameToGameWithOutcome(playerId uuid.UUID) GameWithOutcome
type GamesUiFriendly ¶ added in v0.2.0
type GamesUiFriendly struct {
Wins, Draws, Losses int
TotalGames int
WinRate, LossRate, DrawRate float64
WhiteWinRate, BlackWinRate float64
Games []GameWithOutcome
}
func MapGamesToUserFriendly ¶ added in v0.2.0
func MapGamesToUserFriendly(playerId uuid.UUID, games []GameWithPlayerNames) GamesUiFriendly
type LeaguePlayerUiFriendly ¶ added in v0.2.0
func GetUiFriendlyLeaguePlayers ¶ added in v0.2.0
func GetUiFriendlyLeaguePlayers(db db.Db) ([]LeaguePlayerUiFriendly, error)
type Liglicko2Rating ¶ added in v0.2.0
type Liglicko2Rating = liglicko2core.Rating
type Player ¶
type Player struct {
Id uuid.UUID `db:"id"`
Name string `db:"name"`
NameNormalised string `db:"name_normalised"`
DEPRECATEDElo int `db:"elo"` // Deprecated: for use with old elo system
// Liglicko2Rating is the player's current liglicko2 rating scalar.
Liglicko2Rating float64 `db:"liglicko2_rating"`
// Liglicko2Deviation is the player's current liglicko2 rating deviation (RD).
Liglicko2Deviation float64 `db:"liglicko2_deviation"`
// Liglicko2Volatility is the player's current liglicko2 volatility (sigma).
Liglicko2Volatility float64 `db:"liglicko2_volatility"`
// Liglicko2At is the liglicko2 timestamp used by the algorithm.
// It is stored as "rating periods since Unix epoch", where this app currently
// defines 1 rating period as 1 day.
Liglicko2At float64 `db:"liglicko2_at"`
JoinTime time.Time `db:"join_time"`
Deleted bool `db:"deleted"`
}
func (*Player) ApplyRating ¶ added in v0.2.0
type PlayerWithGameCount ¶ added in v0.2.0
func GetPlayersByEloWithGameCount ¶ added in v0.2.0
func GetPlayersByEloWithGameCount(db db.Db) ([]PlayerWithGameCount, error)
Click to show internal directories.
Click to hide internal directories.