bts

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const BYE = Team("BYE")

BYE represents a bye week for a team in a schedule.

View Source
const NONE = Team("----")

NONE represents a null pick--used when a player uses a pick bye on a week.

Variables

View Source
var NULLGAME = Game{NONE, NONE, Neutral}

NULLGAME represents a game that doesn't exsit. Go figure.

Functions

func AccumulateStreak

func AccumulateStreak(p *Predictions, s *Streak) (cumprobs, cumspreads []float64)

AccumulateStreak returns the accumulated probability of win a total spread for each week of the given streak.

func SummarizeStreak

func SummarizeStreak(p *Predictions, s *Streak) (prob, spread float64)

SummarizeStreak returns the total predicted probability of beating a streak and the total spread.

Types

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game represents a matchup between two teams.

func NewGame

func NewGame(team1, team2 Team, locRelTeam1 RelativeLocation) *Game

NewGame makes a game between two teams.

func (*Game) LocationRelativeToTeam

func (g *Game) LocationRelativeToTeam(t int) RelativeLocation

LocationRelativeToTeam returns the location of the game relative to the given team.

func (*Game) Team

func (g *Game) Team(t int) Team

Team returns a given team.

type GameModel

type GameModel struct {
	Game  *Game
	Model string
}

GameModel is a combined game and model for 2D lookup of lines

type GaussianSpreadModel

type GaussianSpreadModel struct {
	// contains filtered or unexported fields
}

GaussianSpreadModel implements PredictionModel and uses a normal distribution based on spreads to calculate win probabilities. The spread is determined by a team rating and where the game is being played (to account for bias).

func NewGaussianSpreadModel

func NewGaussianSpreadModel(ratings map[string]bpefs.ModelTeamPoints, perf bpefs.ModelPerformance) *GaussianSpreadModel

NewGaussianSpreadModel makes a model.

func (GaussianSpreadModel) MostLikelyOutcome

func (m GaussianSpreadModel) MostLikelyOutcome(game *Game) (Team, float64, float64)

MostLikelyOutcome returns the most likely team to win a given game, the probability of win, and the predicted spread.

func (GaussianSpreadModel) Predict

func (m GaussianSpreadModel) Predict(game *Game) (float64, float64)

Predict returns the probability and spread for team1.

func (GaussianSpreadModel) String

func (m GaussianSpreadModel) String() string

type IdenticalPermutor

type IdenticalPermutor struct {
	// contains filtered or unexported fields
}

IdenticalPermutor permutes a set of potentially repeated integers with n_i copies of integers i=0 to i=N.

func NewIdenticalPermutor

func NewIdenticalPermutor(setSizes ...int) *IdenticalPermutor

NewIdenticalPermutor creates an IdenticalPermutor for potentially duplicated integers in the range [0, len(setSizes)). Each passed ith value in the variatic argument represents the number of identical copies of integer i that is in the set to be permuted. For example:

NewIdenticalPermutor(2, 0, 3, 1)

This will create a permutor over the set [0, 0, 2, 2, 2, 3] (2 copies of 0, 0 copies of 1, 3 copies of 2, and 1 copy of 3).

func (*IdenticalPermutor) Len

func (ip *IdenticalPermutor) Len() int

Len returns the length of the set being permuted.

func (*IdenticalPermutor) NumberOfPermutations

func (ip *IdenticalPermutor) NumberOfPermutations() *big.Int

NumberOfPermutations returns the number of permutations possible for the set.

func (*IdenticalPermutor) Permutation

func (ip *IdenticalPermutor) Permutation() []int

Permutation gets the current permutation. This value is a view into the internal slice and will change if Next() is called.

func (*IdenticalPermutor) Permute

func (ip *IdenticalPermutor) Permute() bool

Permute permutes the internal indices and returns false if the iterator has run out of permutations. Get the current permutation with Permutation(). The implementation uses Heap's algorithm (non-recursive) and a map of hashes to keep track of which permutations have been seen already. This means for very large permutations, there is some small probability that a hash collision will occur and certain permutations could be skipped in the iteration.

func (*IdenticalPermutor) Reset

func (ip *IdenticalPermutor) Reset()

Reset resets the permutor to its initial state. This invalidates any slices of indices previously read with Permutation().

type IndexPermutor

type IndexPermutor struct {
	// contains filtered or unexported fields
}

IndexPermutor permutes an integer range from 0 to N.

func NewIndexPermutor

func NewIndexPermutor(size int) *IndexPermutor

NewIndexPermutor creates an IndexPermutor for the integer range [0, size)

func (*IndexPermutor) Len

func (ip *IndexPermutor) Len() int

Len returns the length of the set being permuted.

func (*IndexPermutor) NumberOfPermutations

func (ip *IndexPermutor) NumberOfPermutations() *big.Int

NumberOfPermutations returns the number of permutations possible for the set.

func (*IndexPermutor) Permutation

func (ip *IndexPermutor) Permutation() []int

Permutation gets the current permutation. This value is a view into the internal slice and will change if Next() is called.

func (*IndexPermutor) Permute

func (ip *IndexPermutor) Permute() bool

Permute permutes the internal indices and returns false if the iterator has run out of permutations. Get the current permutation with Permutation(). The implementation uses Heap's algorithm (non-recursive).

func (*IndexPermutor) Reset

func (ip *IndexPermutor) Reset()

Reset resets the permutor to its initial state. This invalidates any slices of indices previously read with Permutation().

type LineMap

type LineMap map[GameModel]float64

LineMap is a mapping of game/model combinations with a line

func MakeLines

func MakeLines(url string) (LineMap, error)

MakeLines makes a map of games to lines

type OracleModel

type OracleModel struct {
	// contains filtered or unexported fields
}

OracleModel represents a Model that knows who won each matchup, so always returns a probability of win of either 1 or 0, and a spread equal to the scoring margin in the game.

func NewOracleModel

func NewOracleModel(results []bpefs.Game) *OracleModel

NewOracleModel makes a model.

func (OracleModel) MostLikelyOutcome

func (m OracleModel) MostLikelyOutcome(g *Game) (team Team, prob float64, spread float64)

MostLikelyOutcome returns the historical winner of g, a probability of 1, and a spread equal to the scoring margin. If the two teams did not play each other, returns g.team1 and a probability and spread of zero.

func (OracleModel) Predict

func (m OracleModel) Predict(g *Game) (prob float64, spread float64)

Predict returns a probability of 1 if g.team1 won the game, a probability of 0 if g.team1 lost (or the game did not happen), and a spread equal to the scoring margin (or zero if the game did not happen).

func (OracleModel) String

func (m OracleModel) String() string

String implements the Stringer interface.

type Permutor

type Permutor interface {
	Len() int
	NumberOfPermutations() *big.Int
	Permutation() []int
	Permute() bool
	Reset()
}

type Player

type Player struct {
	// contains filtered or unexported fields
}

Player represents a player's current status in the competition.

func NewPlayer

func NewPlayer(name string, ref *firestore.DocumentRef, remaining Remaining, remainingRefs []*firestore.DocumentRef, weekTypesRemaining []int) (*Player, error)

NewPlayer builds a new player

func (Player) Name

func (p Player) Name() string

Name returns the player's name

func (Player) Ref

func (p Player) Ref() *firestore.DocumentRef

Ref returns a reference to the player document in Firestore.

func (Player) RemainingIterator

func (p Player) RemainingIterator() *IndexPermutor

RemainingIterator returns an iterator over remaining team indices.

func (Player) RemainingTeams

func (p Player) RemainingTeams() Remaining

RemainingTeams returns the list of remaining teams.

func (Player) RemainingTeamsRefs

func (p Player) RemainingTeamsRefs() []*firestore.DocumentRef

RemainingTeamsRefs returns the list of remaining teams as references to Firestore documents.

func (Player) RemainingWeekTypes

func (p Player) RemainingWeekTypes() []int

RemainingWeekTypes returns the list of remaining week types.

func (Player) RemainingWeeks

func (p Player) RemainingWeeks() int

RemainingWeeks calculates the number of weeks of picks this player has remaining.

func (Player) String

func (p Player) String() string

func (Player) WeekTypeIterator

func (p Player) WeekTypeIterator() *IdenticalPermutor

WeekTypeIterator returns an iterator over remaining week types.

type PlayerMap

type PlayerMap map[string]*Player

PlayerMap associates a player's name with a status.

func (PlayerMap) Duplicates

func (pm PlayerMap) Duplicates() map[string][]*Player

Duplicates returns a list of Players who are duplicates of one another.

func (PlayerMap) PlayerNames

func (pm PlayerMap) PlayerNames() []string

PlayerNames returns the unique names of the players in the PlayerMap.

type PredictionModel

type PredictionModel interface {
	MostLikelyOutcome(*Game) (team Team, prob float64, spread float64)
	Predict(*Game) (prob float64, spread float64)
}

PredictionModel describes an object that can predict the probability a given team will defeat another team, or the point spread if those teams were to play.

type Predictions

type Predictions struct {
	// contains filtered or unexported fields
}

Predictions represents the probability of win and predicted spread for every team for each week.

func EmptyPredictions

func EmptyPredictions(teamList TeamList, nWeeks int) *Predictions

EmptyPredictions returns empty probabilities for a set of teams and a given number of weeks.

func MakePredictions

func MakePredictions(s *Schedule, m PredictionModel) *Predictions

MakePredictions uses a schedule and a model to build a map of predictions for fast lookup.

func (*Predictions) FilterWeeks

func (p *Predictions) FilterWeeks(w int)

FilterWeeks filters the Predictions by removing weeks prior to the given one.

func (*Predictions) GetProbability

func (p *Predictions) GetProbability(team Team, week int) float64

GetProbability returns the probability that the given team wins in the given week. Bye weeks have a probability of 1.

func (*Predictions) GetSpread

func (p *Predictions) GetSpread(team Team, week int) float64

GetSpread returns the predicted spread for a given team in a given week. Teams on bye weeks are given a spread of 0.

func (Predictions) String

func (p Predictions) String() string

type RelativeLocation

type RelativeLocation int

RelativeLocation describes where a game is being played relative to one team's home field.

const (
	// Home is a team's home field.
	Home RelativeLocation = 2

	// Near is a field closer to a given team's home field than the team's opponent's home field.
	Near RelativeLocation = 1

	// Neutral is a truely neutral location.
	Neutral RelativeLocation = 0

	// Far is a field closer to a given team's opponent's home field than the team's home field.
	Far RelativeLocation = -1

	// Away is a team's opponent's home field.
	Away RelativeLocation = -2
)

type Remaining

type Remaining TeamList

Remaining represents a player's teams remaining.

type RemainingMap

type RemainingMap map[string]Remaining

RemainingMap associates a player's name to the teams remaining.

type Schedule

type Schedule map[Team][]*Game

Schedule is a team's schedule for the year.

func MakeSchedule

func MakeSchedule(ctx context.Context, client *firestore.Client, season *firestore.DocumentRef, week int, teams []*firestore.DocumentRef) (schedule Schedule, err error)

MakeSchedule builds a schedule from the games in Firestore. The schedule will only include games from the given `week` onward (inclusive), and only for the given `teams`. If a `team` does not have a game in a given week, a BYE will be inserted.

func (*Schedule) FilterWeeks

func (s *Schedule) FilterWeeks(w int)

FilterWeeks filters the Predictions by removing weeks prior to the given one.

func (Schedule) Get

func (s Schedule) Get(t Team, w int) *Game

Get a game for a team and week number.

func (Schedule) NumWeeks

func (s Schedule) NumWeeks() int

NumWeeks returns the number of weeks contained in the schedule.

func (Schedule) String

func (s Schedule) String() string

func (Schedule) TeamList

func (s Schedule) TeamList() TeamList

TeamList generates a list of first-level teams from the schedule.

type Streak

type Streak struct {
	// contains filtered or unexported fields
}

Streak represents a potential streak selection for a contestant.

func NewStreak

func NewStreak(teamList Remaining, picksPerWeek []int) *Streak

NewStreak creates a Streak from a list of teams, a selected number of picks per week, and a permutation of the teams into the week.

func (*Streak) Clone

func (s *Streak) Clone() *Streak

Clone clones the streak. This results in a new struct with all of the internal objects cloned.

func (*Streak) FindTeam

func (s *Streak) FindTeam(team Team) int

FindTeam returns the first week in which the given team was selected.

func (*Streak) GetWeek

func (s *Streak) GetWeek(week int) TeamList

GetWeek returns the teams selected on a given week.

func (*Streak) NumWeeks

func (s *Streak) NumWeeks() int

NumWeeks returns the number of weeks in the streak.

func (*Streak) PermuteTeamOrder

func (s *Streak) PermuteTeamOrder(indexPermutation []int)

PermuteTeamOrder permutes the order of the streak by the given permutation index.

func (*Streak) Perturbate

func (s *Streak) Perturbate(src rand.Source, picksPerWeekAlso bool)

Perturbate randomly swaps two teams in the team order. If `picksPerWeekAlso` is `true`, will also randomly swap the picks per week for two weeks. This function is not guaranteed to produce a new distinct streak.

func (*Streak) PicksPerWeek

func (s *Streak) PicksPerWeek(ppw []int) []int

PicksPerWeek sets the number of picks per week. A nil value as an argument returns the old picks per week value with no changes made.

func (*Streak) String

func (s *Streak) String() string

type Team

type Team string

Team play game against Team.

type TeamList

type TeamList []Team

TeamList implements the sort.Interface interface and represents a list of Teams.

func (TeamList) Clone

func (t TeamList) Clone() TeamList

Clone just clones the probabilities.

func (TeamList) Len

func (t TeamList) Len() int

Len calculates the length of the TeamList (implements sort.Interface interface)

func (TeamList) Less

func (t TeamList) Less(i, j int) bool

Less reports whether (implements sort.Interface interface)

func (TeamList) Swap

func (t TeamList) Swap(i, j int)

Swap swaps the elements with indexes i and j (implements sort.Interface interface)

type WeeksMap

type WeeksMap map[string][]int

WeeksMap associates a player's name to the remaining weeks.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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