mirror of
https://github.com/avitex/elixir-glicko
synced 2024-11-22 03:09:57 +00:00
Flattern opponent in result map
This commit is contained in:
parent
c80e397073
commit
218ac020fe
@ -28,14 +28,16 @@ defmodule Glicko do
|
|||||||
|
|
||||||
defp do_new_rating(player = %Player{version: :v2}, results, opts) do
|
defp do_new_rating(player = %Player{version: :v2}, results, opts) do
|
||||||
results = Enum.map(results, fn result ->
|
results = Enum.map(results, fn result ->
|
||||||
|
opponent = Player.to_v2(result.opponent)
|
||||||
|
|
||||||
result =
|
result =
|
||||||
Map.new
|
Map.new
|
||||||
|> Map.put(:opponent, Player.to_v2(result.opponent))
|
|
||||||
|> Map.put(:score, result.score)
|
|> Map.put(:score, result.score)
|
||||||
|
|> Map.put(:opponent_rating, opponent.rating)
|
||||||
|
|> Map.put(:opponent_rating_deviation, opponent.rating_deviation)
|
||||||
|
|> Map.put(:opponent_rating_deviation_g, calc_g(opponent.rating_deviation))
|
||||||
|
|
||||||
result = Map.put(result, :opponent_rating_deviation_g, calc_g(result.opponent.rating_deviation))
|
Map.put(result, :e, calc_e(player, result))
|
||||||
result = Map.put(result, :e, calc_e(player, result))
|
|
||||||
result
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ctx =
|
ctx =
|
||||||
@ -153,7 +155,7 @@ defmodule Glicko do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp calc_k(ctx, k) do
|
defp calc_k(ctx, k) do
|
||||||
if calc_f(ctx, (ctx.alpha - k * ctx.system_constant)) < 0 do
|
if calc_f(ctx, ctx.alpha - k * ctx.system_constant) < 0 do
|
||||||
calc_k(ctx, k + 1)
|
calc_k(ctx, k + 1)
|
||||||
else
|
else
|
||||||
k
|
k
|
||||||
@ -167,6 +169,6 @@ defmodule Glicko do
|
|||||||
|
|
||||||
# E function
|
# E function
|
||||||
defp calc_e(player, result) do
|
defp calc_e(player, result) do
|
||||||
1 / (1 + :math.exp(-1 * result.opponent_rating_deviation_g * (player.rating - result.opponent.rating)))
|
1 / (1 + :math.exp(-1 * result.opponent_rating_deviation_g * (player.rating - result.opponent_rating)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user