...

Package zenith

Overview ▾

Package zenith implements score tracking and leaderboards

Constants

Outcomes

const (
    Won  = 1
    Drew = 2
    Lost = 3
)
const DatabaseVersion = 1

Variables

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

type Database struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func Connect

func Connect(driver string, dataSource string) (*Database, error)

func (*Database) CreateTables

func (d *Database) CreateTables() error

func (*Database) Matches

func (d *Database) Matches(game, player int) ([]*MatchResult, error)

TODO Allow -1 player to select all

func (*Database) Migrate

func (d *Database) Migrate() error

func (*Database) Player

func (d *Database) Player(game, player int) (*Player, error)

func (*Database) Track

func (d *Database) Track(results ...*MatchResult) error

func (*Database) Versus

func (d *Database) Versus(game, player, versus int) (int, int, int, error)

type MatchResult

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
}

type Outcome

Outcome represents the outcome of a match for a player.

type Outcome int

type Player

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
}

type Tracker

Tracker records match results and provides player standings.

type Tracker struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func NewTracker

func NewTracker(options *TrackerOptions) (*Tracker, error)

NewTracker returns a new score tracker. A game ID greater than zero must be specified.

func (*Tracker) Player

func (t *Tracker) Player(game, player int) (*Player, error)

Player returns the Player with the specified ID.

func (*Tracker) PlayersByStanding

func (t *Tracker) PlayersByStanding(start int, end int) []*Player

PlayersByStanding returns the Players within a specified range of standings.

func (*Tracker) Track

func (t *Tracker) Track(results ...*MatchResult) error

Track tracks one or more match results.

type TrackerOptions

TrackerOptions specify options when creating a new Tracker.

type TrackerOptions struct {
    Database *Database
    Web      string // Web interface address
}