Documentation
¶
Index ¶
- Constants
- type Config
- type GameCount
- type MatchResult
- type Player
- type RRN
- type RatingResource
- type RatingResourceCollection
- func (c RatingResourceCollection) Add(items ...RatingResource) RatingResourceCollection
- func (c RatingResourceCollection) Prepares(outcomeAt time.Time, config *Config) error
- func (c RatingResourceCollection) Ranking() []RatingResource
- func (c RatingResourceCollection) Ratings() map[RRN]rating.Rating
- func (c RatingResourceCollection) Updates(scores ScoreCollection, outcomeAt time.Time, config *Config) error
- func (c RatingResourceCollection) Values() []RatingResource
- type ScoreCollection
Examples ¶
Constants ¶
const ( PeriodDay time.Duration = 24 * time.Hour PeriodWeek = 7 * PeriodDay PeriodMonth = 30 * PeriodDay PeriodYear = 365 * PeriodDay )
RatingPeriod constans can multiple float64
PeriodDay * 3.0 => 3 days
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { //RatingPeriod is the fixed interval of Rating. //All matches played between this interval are considered to occur simultaneously and are calculated. //In RatingPeriod, the period in which the players play about 15 times is good. RatingPeriod time.Duration //It will return to the initial deviation if you have not played for about this period. //This period is a guideline, and the time to return to the actual initial deviation is determined by the player's Volatility here. //And initial Volatility is calculated based on this period. PeriodToResetDeviation time.Duration Tau float64 }
Config is rating system propaties
func (*Config) DefaultRating ¶
InitialVolatility detamine initial volatility from rating period and period to reset deviation
type GameCount ¶
type GameCount struct { Win uint64 `json:"win"` Lose uint64 `json:"lose"` Draw uint64 `json:"draw"` }
GameCount is (win/lose/draw) count
type MatchResult ¶
type MatchResult struct { Opponent rating.Rating `json:"opponent"` Score float64 `json:"score"` OutcomeAt time.Time `json:"outcome_at"` }
MatchResult represents the Match result from the viewpoint of a player
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player is entity of ratable person.
Example ¶
package main import ( "fmt" "time" "github.com/mashiike/restrating/entity" ) func main() { loc, _ := time.LoadLocation("Asia/Tokyo") baseTime := time.Date(2019, 05, 01, 0, 0, 0, 0, loc) config := entity.NewConfig() players := make(entity.RatingResourceCollection, 3) players = players.Add( entity.NewPlayer("sheep", baseTime, config), //rrn:player:sheep entity.NewPlayer("goat", baseTime, config), //rrn:player:goat entity.NewPlayer("donkey", baseTime, config), //rrn:player:donkey ) scores := entity.ScoreCollection{ entity.MustParseRNN("rrn:player:sheep"): 0.0, entity.MustParseRNN("rrn:player:goat"): 1.0, entity.MustParseRNN("rrn:player:donkey"): 2.0, } for k := 0; k < 5; k++ { players.Updates(scores, baseTime.AddDate(0, 0, k*8), config) } for _, player := range players.Ranking() { fmt.Println(player) } }
Output:
func (*Player) Update ¶
func (p *Player) Update(result *MatchResult) error
Update do Player's rating update.
type RRN ¶
RRN is rating resource name
func MustParseRNN ¶
MustParseRNN はexampleをシンプルに書くよう。errorが起きたらpanicする
type RatingResource ¶
type RatingResource interface { RRN() RRN Rating() rating.Rating Prepare(time.Time, *Config) error Update(*MatchResult) error }
RatingResource はPlayer/Teamの同一視
type RatingResourceCollection ¶
type RatingResourceCollection map[RRN]RatingResource
RatingResourceCollection はRatingResouceのコレクション
func (RatingResourceCollection) Add ¶
func (c RatingResourceCollection) Add(items ...RatingResource) RatingResourceCollection
Add はRatingResourceCollectionに一気に追加する関数
func (RatingResourceCollection) Prepares ¶
func (c RatingResourceCollection) Prepares(outcomeAt time.Time, config *Config) error
Prepares はまとめてコレクションをPrepareする。
func (RatingResourceCollection) Ranking ¶
func (c RatingResourceCollection) Ranking() []RatingResource
Ranking は強さ順に並んだSliceを返す
func (RatingResourceCollection) Ratings ¶
func (c RatingResourceCollection) Ratings() map[RRN]rating.Rating
Ratings はその時点でのRatingの値を返す
func (RatingResourceCollection) Updates ¶
func (c RatingResourceCollection) Updates(scores ScoreCollection, outcomeAt time.Time, config *Config) error
Updates はまとめてコレクションをUpdateする。
func (RatingResourceCollection) Values ¶
func (c RatingResourceCollection) Values() []RatingResource
Values はRatingResouceのスライスを返します。
type ScoreCollection ¶
ScoreCollection はまとめてアップデートするためのScoreの集合