entity

package
v0.0.0-...-998107f Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

View Source
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 NewConfig

func NewConfig() *Config

NewConfig is default configuration

func (*Config) DefaultRating

func (c *Config) DefaultRating() rating.Rating

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

func (GameCount) AddScore

func (g GameCount) AddScore(score float64) GameCount

func (GameCount) String

func (g GameCount) String() string

String is implemets fmt.Stringer

func (GameCount) Total

func (g GameCount) Total() uint64

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 NewPlayer

func NewPlayer(name string, createdAt time.Time, config *Config) *Player

NewPlayer is Player constractor

func (*Player) GameCount

func (p *Player) GameCount() GameCount

GameCount is player's game count (win/lose/draw)

func (*Player) Prepare

func (p *Player) Prepare(now time.Time, config *Config) error

Prepare must do before Update

func (*Player) RRN

func (p *Player) RRN() RRN

RRN はリソースを管理する名前

func (*Player) Rating

func (p *Player) Rating() rating.Rating

Rating is current this player's estimated rating

func (*Player) String

func (p *Player) String() string

String is implements fmt.Stringer

func (*Player) Update

func (p *Player) Update(result *MatchResult) error

Update do Player's rating update.

type RRN

type RRN struct {
	Type string
	Name string
}

RRN is rating resource name

func MustParseRNN

func MustParseRNN(rrnStr string) RRN

MustParseRNN はexampleをシンプルに書くよう。errorが起きたらpanicする

func ParseRRN

func ParseRRN(rrn string) (RRN, error)

ParseRRN はRRNを読み取ります

func (RRN) String

func (rrn RRN) String() string

String はRRNの形式フォーマットを返します。

examples:

rrn:player:abdea3dfa
rrn:team:dda32341

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

Add はRatingResourceCollectionに一気に追加する関数

func (RatingResourceCollection) Prepares

func (c RatingResourceCollection) Prepares(outcomeAt time.Time, config *Config) error

Prepares はまとめてコレクションをPrepareする。

func (RatingResourceCollection) Ranking

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

Values はRatingResouceのスライスを返します。

type ScoreCollection

type ScoreCollection map[RRN]float64

ScoreCollection はまとめてアップデートするためのScoreの集合

func (ScoreCollection) Keys

func (c ScoreCollection) Keys() []RRN

Keys はScoreの集合のKeyになるRRNのスライス

Jump to

Keyboard shortcuts

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