rating

package
v0.0.0-...-c84c7a3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: MIT Imports: 12 Imported by: 0

README

rating package

Public

func Initialize()

Only function that should be called from this package.

Initializes the cron jobs that should take place in this package.

Private

func GetTeamElo(teamIdKey string)

Parameter teamIdKey is the id of a team on lichess.org

Does a GET request to lichess and gets all the members in a team. Calls GetGamesInTeam to get all games in a team. Calls sortGames to sort these games. Calls calculateElo to calculate Elo.

returns []TeamMember with all team members in a team with an internal ELO in team.

func getGamesInTeam(teamMembers [] TeamMember)

Parameter teamMembers is a slice of team members

Loops through every team member vs team member permutation and calls getGamesOfMemberVSMember.

returns []Game of every match between teammembers in a team.

func getGamesOfMemberVSMember(member TeamMember, vsMember TeamMember)

Parameters member and vsMember, two members which we get all games between.

returns []Game which contains all matches between two members.

func getRequest(c *http.Client, s string)

Parameters c and s, where s is the GET request address.

Is a simple function for get requests.

returns *http.Response

func getWhiteAndBlackFromGame(game Game, teamMembers [] TeamMember)

Parameters game is a game object, teamMembers is a slice of all team members.

Functions loops through all team members to find the teamMember object of the black and white members of a game match.

returns []TeamMember which contains White and Black corresponding teamMember objects. White in the first index and black in the second.

func calculateElo(games []Game, teamMembers []TeamMember)

Parameters games and teamMembers. games is a slice of games and teamMembers is a slice of all team members in a team.

Calculates the elo of team members match by match (game).

returns []TeamMember with all elo scores updated

func insertElo(eloWhite float64, eloBlack float64, white TeamMember, black TeamMember, teamMembers [] TeamMember)

Parameters eloWhite, eloBlack, white, black, teamMembers

Inserts the new elo of white and black player into teamMembers and returns it.

returns []TeamMember with updated elo.

func sortGames(games []Game)

Parameter games

Sorts games by timestamp and returns

returns []Game

func fakeTeamMembers

Returns fake test data []TeamMembers

structs
type Game struct {
	ID        string `json:"id"`
	CreatedAt int    `json:"createdAt"`
	Players   struct {
		White struct {
			User struct {
				ID   string `json:"id"`
				Name string `json:"name"`
			} `json:"user"`
		} `json:"white"`
		Black struct {
			User struct {
				ID   string `json:"id"`
				Name string `json:"name"`
			} `json:"user"`
		} `json:"black"`
	} `json:"players"`
	Winner string `json:"winner"`
}


type TeamMember struct {
	ID                string  `json:"id"`
	Username          string  `json:"username"`
	InternalCreatedAt int     `json:"internalCreatedAt"`
	Elo               float64 `json:"elo"`
}

Documentation

Index

Constants

View Source
const LICHESS_DEFAULT_TEAM = "testclub"
View Source
const LICHESS_LEAGUE_ID = 3
View Source
const LICHESS_LEAGUE_SEASON_NAME = "Sjakksesong"
View Source
const LICHESS_PLATFORM_ID = 1
View Source
const LICHESS_RATE_LIMIT = 61

LICHESS_RATE_LIMIT for sleep when we hit the rate limit of lichess.org

Variables

This section is empty.

Functions

func Initialize

func Initialize()

Types

type Game

type Game struct {
	ID        string          `json:"id"`
	CreatedAt int             `json:"createdAt"`
	Status    string          `json:"status"`
	Players   Players         `json:"players"`
	Winner    string          `json:"winner"`
	Result    database.RESULT `json:"result"`
}

TODO check and fix struct for remi/draw Game - Struct for getting game/match information

type Player

type Player struct {
	User User `json:"user"`
}

type Players

type Players struct {
	White Player `json:"white"`
	Black Player `json:"black"`
}

type TeamMember

type TeamMember struct {
	ID                string  `json:"id"`
	Username          string  `json:"username"`
	InternalCreatedAt int     `json:"internalCreatedAt"`
	Elo               float64 `json:"elo"`
	LeagueID          int64   `json:"league_id"`
}

TeamMember - Struct for getting essential teammembers information

type User

type User struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Jump to

Keyboard shortcuts

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