Outcomes
const ( Won = 1 Drew = 2 Lost = 3 )
const DatabaseVersion = 1
var DatabasePrefix string
TODO: Add indexes
var DatabaseTables = map[string][]string{ "match": { "`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT", "`timestamp` INTEGER NOT NULL DEFAULT 0", "`game` INTEGER NOT NULL DEFAULT 0", "`match` INTEGER NOT NULL DEFAULT 0", "`player` INTEGER NOT NULL DEFAULT 0", "`outcome` INTEGER NOT NULL DEFAULT 0", }, "matchmeta": { "`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT", "`game` INTEGER NOT NULL DEFAULT 0", "`match` INTEGER NOT NULL DEFAULT 0", "`player` INTEGER NOT NULL DEFAULT 0", "`key` VARCHAR(255) NOT NULL DEFAULT ''", "`value` TEXT NOT NULL DEFAULT ''", }, "meta": { "`key` VARCHAR(255) NOT NULL PRIMARY KEY", "`value` TEXT NOT NULL DEFAULT ''", }}
type Database struct { sync.RWMutex // contains filtered or unexported fields }
func Connect(driver string, dataSource string) (*Database, error)
func (d *Database) CreateTables() error
func (d *Database) Matches(game, player int) ([]*MatchResult, error)
TODO Allow -1 player to select all
func (d *Database) Migrate() error
func (d *Database) Player(game, player int) (*Player, error)
func (d *Database) Track(results ...*MatchResult) error
func (d *Database) Versus(game, player, versus int) (int, int, int, error)
MatchResult represents the result of a match for a player. MetaI and MetaS may optionally be used to provide additional metadata of the match result.
type MatchResult struct { ID int Timestamp int Game int Match int Player int Outcome Outcome MetaI map[string]int MetaS map[string]string }
Outcome represents the outcome of a match for a player.
type Outcome int
Player represents the current standing and wins/draws/losses of a player.
type Player struct { ID int Standing int Wins int Draws int Losses int }
Tracker records match results and provides player standings.
type Tracker struct { sync.RWMutex // contains filtered or unexported fields }
func NewTracker(options *TrackerOptions) (*Tracker, error)
NewTracker returns a new score tracker. A game ID greater than zero must be specified.
func (t *Tracker) Player(game, player int) (*Player, error)
Player returns the Player with the specified ID.
func (t *Tracker) PlayersByStanding(start int, end int) []*Player
PlayersByStanding returns the Players within a specified range of standings.
func (t *Tracker) Track(results ...*MatchResult) error
Track tracks one or more match results.
TrackerOptions specify options when creating a new Tracker.
type TrackerOptions struct { Database *Database Web string // Web interface address }