@quenty/elo 7.2.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +5 -2
- package/src/Shared/EloUtils.lua +52 -0
- package/src/Shared/EloUtils.spec.lua +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [7.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/elo@7.2.0...@quenty/elo@7.3.0) (2024-04-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add EloUtils percentile helper logic ([d2b4910](https://github.com/Quenty/NevermoreEngine/commit/d2b4910b93570f30c1060f78992286b1bf6a7698))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [7.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/elo@7.1.1...@quenty/elo@7.2.0) (2024-04-27)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/elo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/elo",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Elo rating utility library.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -33,5 +33,8 @@
|
|
|
33
33
|
"@quenty/loader": "^10.2.0",
|
|
34
34
|
"@quenty/maid": "^3.1.0"
|
|
35
35
|
},
|
|
36
|
-
"
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@quenty/probability": "^2.2.0"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "1f65df4adb6f3c04fb25d70bfa93f0f7c332c143"
|
|
37
40
|
}
|
package/src/Shared/EloUtils.lua
CHANGED
|
@@ -26,6 +26,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
26
26
|
|
|
27
27
|
local EloMatchResult = require("EloMatchResult")
|
|
28
28
|
local EloMatchResultUtils = require("EloMatchResultUtils")
|
|
29
|
+
local Probability = require("Probability")
|
|
29
30
|
|
|
30
31
|
local EloUtils = {}
|
|
31
32
|
|
|
@@ -64,6 +65,57 @@ end
|
|
|
64
65
|
]=]
|
|
65
66
|
function EloUtils.isEloConfig(config)
|
|
66
67
|
return type(config) == "table"
|
|
68
|
+
and type(config.factor) == "number"
|
|
69
|
+
and (type(config.kfactor) == "number" or type(config.kfactor) == "function")
|
|
70
|
+
and type(config.initial) == "number"
|
|
71
|
+
and type(config.ratingFloor) == "number"
|
|
72
|
+
and type(config.groupMultipleResultAsOne) == "boolean"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
--[=[
|
|
76
|
+
Gets the standard deviation of the elo curve
|
|
77
|
+
|
|
78
|
+
@param eloConfig EloConfig
|
|
79
|
+
@return number
|
|
80
|
+
]=]
|
|
81
|
+
function EloUtils.getStandardDeviation(eloConfig)
|
|
82
|
+
assert(EloUtils.isEloConfig(eloConfig), "Bad eloConfig")
|
|
83
|
+
|
|
84
|
+
return 0.5*eloConfig.factor*math.sqrt(2)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
--[=[
|
|
88
|
+
Gets the standard deviation of the elo curve from 0 to 1
|
|
89
|
+
|
|
90
|
+
@param eloConfig EloConfig
|
|
91
|
+
@param elo number
|
|
92
|
+
@return number
|
|
93
|
+
]=]
|
|
94
|
+
function EloUtils.getPercentile(eloConfig, elo)
|
|
95
|
+
assert(EloUtils.isEloConfig(eloConfig), "Bad eloConfig")
|
|
96
|
+
|
|
97
|
+
local standardDeviation = EloUtils.getStandardDeviation(eloConfig)
|
|
98
|
+
local mean = eloConfig.initial
|
|
99
|
+
|
|
100
|
+
local zScore = (elo - mean)/standardDeviation
|
|
101
|
+
return Probability.cdf(zScore)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
--[=[
|
|
105
|
+
Gets the standard deviation of the elo curve from 0 to 1
|
|
106
|
+
|
|
107
|
+
@param eloConfig EloConfig
|
|
108
|
+
@param percentile number
|
|
109
|
+
@return number
|
|
110
|
+
]=]
|
|
111
|
+
function EloUtils.percentileToElo(eloConfig, percentile)
|
|
112
|
+
assert(EloUtils.isEloConfig(eloConfig), "Bad eloConfig")
|
|
113
|
+
|
|
114
|
+
local standardDeviation = EloUtils.getStandardDeviation(eloConfig)
|
|
115
|
+
local mean = eloConfig.initial
|
|
116
|
+
|
|
117
|
+
local zScore = Probability.percentileToZScore(percentile)
|
|
118
|
+
return mean + zScore*standardDeviation
|
|
67
119
|
end
|
|
68
120
|
|
|
69
121
|
--[=[
|
|
@@ -64,5 +64,11 @@ return function()
|
|
|
64
64
|
expect(winChange > drawChange ).to.equal(true)
|
|
65
65
|
expect(drawChange > lossChange).to.equal(true)
|
|
66
66
|
end)
|
|
67
|
+
|
|
68
|
+
it("should compute percentile as 0.5", function()
|
|
69
|
+
local percentile = EloUtils.getPercentile(config, 1400)
|
|
70
|
+
|
|
71
|
+
expect(percentile).to.equal(0.5)
|
|
72
|
+
end)
|
|
67
73
|
end)
|
|
68
74
|
end
|