Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Match ¶
type Match struct {
bun.BaseModel `bun:"table:matches,alias:m"`
ID int64 `bun:"id,pk,autoincrement"`
PlayersByRank map[Rank][]Player // the players ordered by their rank
Players []Player `json:"players"`
Date time.Time `bun:"date" json:"date"` // the date of the team
Field string `bun:"field" json:"field"` // field in where the match was played
Team1 Team `bun:"team1" json:"team1"` // the first team
Team2 Team `bun:"team2" json:"team2"` // the second team
MatchResult Result `bun:"result" json:"result"` // the match result
}
func (*Match) GenerateTeams ¶
func (m *Match) GenerateTeams()
GenerateTeams is the complete algorithm to create evenly teams based on the player's ranking where the first picker is random and each player are distributed based on their ranks
func (*Match) SaveResult ¶
SaveResult will return a list of players with the actualized stats looking at a MatchResult
type Player ¶
type Player struct {
bun.BaseModel `bun:"table:players,alias:p"`
ID int64 `bun:"id,pk,autoincrement"`
Nickname string `bun:"nickname,unique" json:"nickname"`
Name string `bun:"name" json:"name"`
Rank Rank `bun:"rank" json:"rank"`
Description string `bun:"description" json:"description"`
Age int `bun:"age" json:"age"`
Position Position `bun:"position" json:"position"`
TotalGoals int `bun:"totalGoals" json:"totalGoals"`
GamesPlayed int `bun:"gamesPlayed" json:"gamesPlayed"`
GamesWon int `bun:"gamesWon" json:"gamesWon"`
GamesLost int `bun:"gamesLost" json:"gamesLost"`
Diff int `bun:"diff" json:"diff"`
Elo float64 `bun:"elo" json:"elo"`
Points int `bun:"points" json:"points"`
}
func (*Player) CalculateELO ¶
CalculateELO calculates the player's ELO considering their points (age, goals, gamesWon, etc) is a simple formula, maybe improve it in a future
func (*Player) CalculatePoints ¶
CalculatePoints calculates the player's points
func (*Player) Init ¶
func (p *Player) Init(nickname string, name string, description string, age int, rank Rank, position Position, totalGoals int, gamesPlayed int, gamesWon int, gamesLost int) error
Init creates the player with their values
func (*Player) UpdatePlayer ¶
UpdatePlayer update the entire player struct checking the goals and if the player won or lose
type Position ¶
type Position string
const ( Volante Position = "volante" Delantero Position = "delantero" Defensor Position = "defensor" )
Position ------------------------------------------
func (*Position) UnmarshalJSON ¶
UnmarshalJSON give us the capability of unmarshal a non-string field into or Player struct
type Rank ¶
type Rank int
Rank ------------------------------------------
func (*Rank) UnmarshalJSON ¶
UnmarshalJSON give us the capability of unmarshal a non-int field into or Player struct
type Result ¶
type Result struct {
PlayerGoals map[string]int `json:"playersGoals"` // the goals that each player made (e.g: {1 : 3} - where 1 references: "Messi" that scored 3 goals)
Winner Team `json:"winner"` // winner of the match
Loser Team `json:"loser"` // loser of the match
}
Result of a match
func (*Result) ThePlayerWon ¶
ThePlayerWon check if the player is in the winner team or not TODO, improve this. Time complexity of O(n) but the maximum n will be 7