Changed to smaller float
This commit is contained in:
@@ -26,7 +26,6 @@ func getEnter(c *gin.Context) {
|
||||
}
|
||||
|
||||
if slug != "" {
|
||||
|
||||
var table *repository.Table
|
||||
repository.GetDB().Model(&repository.Table{}).Where("slug = ?", slug).First(&table)
|
||||
|
||||
@@ -120,7 +119,7 @@ func postEnter(c *gin.Context) {
|
||||
users := []*repository.User{p1, p2, p3, p4}
|
||||
sides := []string{p1t, p2t, p3t, p4t}
|
||||
|
||||
var playerbuf []float64
|
||||
var playerbuf []float32
|
||||
|
||||
for i, u := range users {
|
||||
if u != nil {
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
type User struct {
|
||||
gorm.Model
|
||||
|
||||
Email string
|
||||
Email string `gorm:"unique"`
|
||||
Username string
|
||||
Slug string
|
||||
Slug string `gorm:"unique"`
|
||||
|
||||
Elo float64
|
||||
Elo float32
|
||||
GameCount int
|
||||
WinCount int
|
||||
LossCount int
|
||||
@@ -28,7 +28,7 @@ type Table struct {
|
||||
gorm.Model
|
||||
|
||||
Name string
|
||||
Slug string
|
||||
Slug string `gorm:"unique"`
|
||||
GameCount int
|
||||
}
|
||||
|
||||
@@ -55,13 +55,13 @@ type GameUser struct {
|
||||
User User
|
||||
|
||||
Side string `gorm:"size:1"`
|
||||
DeltaElo float64
|
||||
DeltaElo float32
|
||||
}
|
||||
|
||||
type LoginToken struct {
|
||||
gorm.Model
|
||||
|
||||
Token string
|
||||
Token string `gorm:"unique"`
|
||||
Email string
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ import (
|
||||
)
|
||||
|
||||
var eloCfg = struct {
|
||||
Mu0 float64
|
||||
Scale float64 // KNew applies to players during burn-in (first BurnInGames matches).
|
||||
KNew float64
|
||||
KStd float64
|
||||
Mu0 float32
|
||||
Scale float32 // KNew applies to players during burn-in (first BurnInGames matches).
|
||||
KNew float32
|
||||
KStd float32
|
||||
BurnInGames int
|
||||
RatingFloor float64
|
||||
MaxPerMatchDelta float64
|
||||
RatingFloor float32
|
||||
MaxPerMatchDelta float32
|
||||
MaxGoals int
|
||||
}{
|
||||
Mu0: 1500,
|
||||
@@ -41,16 +41,16 @@ var eloCfg = struct {
|
||||
type Team struct {
|
||||
Players []*repository.GameUser
|
||||
Score int
|
||||
AverageRating float64
|
||||
AverageRating float32
|
||||
}
|
||||
|
||||
func NewTeam(players []*repository.GameUser, score int) *Team {
|
||||
var t1s float64 = 0
|
||||
var t1s float32 = 0
|
||||
for _, player := range players {
|
||||
t1s += float64(player.User.Elo)
|
||||
t1s += float32(player.User.Elo)
|
||||
|
||||
}
|
||||
t1a := t1s / float64(len(players))
|
||||
t1a := t1s / float32(len(players))
|
||||
|
||||
return &Team{Players: players, Score: score, AverageRating: t1a}
|
||||
}
|
||||
@@ -80,9 +80,9 @@ func GetNewElo(t1, t2 *Team) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CalculateRating(rA, rB float64, goalsA, goalsB, gamesA int) (newrA float64, err error) {
|
||||
func CalculateRating(rA, rB float32, goalsA, goalsB, gamesA int) (newrA float32, err error) {
|
||||
// Observed score (no draws)
|
||||
var sA float64
|
||||
var sA float32
|
||||
if goalsA > goalsB {
|
||||
sA = 1.0
|
||||
} else {
|
||||
@@ -105,7 +105,7 @@ func CalculateRating(rA, rB float64, goalsA, goalsB, gamesA int) (newrA float64,
|
||||
eA := expected(eloCfg.Scale, rA, rB)
|
||||
mov := movFactor(rA, rB, diff)
|
||||
|
||||
var Keff float64
|
||||
var Keff float32
|
||||
if gamesA <= eloCfg.BurnInGames {
|
||||
Keff = eloCfg.KNew
|
||||
} else {
|
||||
@@ -124,13 +124,15 @@ func CalculateRating(rA, rB float64, goalsA, goalsB, gamesA int) (newrA float64,
|
||||
return rA + delta, nil
|
||||
}
|
||||
|
||||
// expected returns the win probability for player A against B
|
||||
func expected(scale, rA, rB float64) float64 {
|
||||
return 1.0 / (1.0 + math.Pow(10.0, -(rA-rB)/scale))
|
||||
func expected(scale, rA, rB float32) float32 {
|
||||
return float32(
|
||||
1.0 / (1.0 + math.Pow(10.0, float64(-(rA-rB)/scale))),
|
||||
)
|
||||
}
|
||||
|
||||
// movFactor returns a bounded margin-of-victory multiplier.
|
||||
func movFactor(rA, rB float64, diff int) float64 {
|
||||
func movFactor(rA, rB float32, diff int) float32 {
|
||||
fd := float64(diff)
|
||||
return math.Log(fd+1.0) * 2.2 / (math.Abs(rA-rB)*0.001 + 2.2)
|
||||
return float32(
|
||||
math.Log(fd+1.0) * 2.2 / (math.Abs(float64(rA-rB))*0.001 + 2.2),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ func NameFromEmail(email string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func RoundFloat(val float64, precision uint) float64 {
|
||||
func RoundFloat(val float32, precision uint) float32 {
|
||||
ratio := math.Pow(10, float64(precision))
|
||||
return math.Round(val*ratio) / ratio
|
||||
return float32(math.Round(float64(val)*ratio) / ratio)
|
||||
}
|
||||
|
||||
func MustRandToken(n int) string {
|
||||
|
||||
Reference in New Issue
Block a user