Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cobbling together a test to guage how starting ranks affect the rating pool #69

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ help:
virtualenv -ppython3 .venv
.venv/bin/pip install -r requirements.txt

100k:
python -m goratings
1M:
analysis/analyze_glicko2_one_game_at_a_time.py --games 1000000

test: .venv
.venv/bin/tox -e py3
Expand Down
112 changes: 86 additions & 26 deletions analysis/analyze_glicko2_one_game_at_a_time.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env -S PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=..:. pypy3

import sys
import logging
from analysis.util import (
Glicko2Analytics,
InMemoryStorage,
Expand All @@ -12,9 +14,13 @@
rank_to_rating,
should_skip_game,
)
from analysis.util.InMemoryWithStartingRankStorage import (
InMemoryStorageWithStartingRankStorage,
)
from goratings.interfaces import GameRecord, RatingSystem, Storage
from goratings.math.glicko2 import Glicko2Entry, glicko2_update


class OneGameAtATime(RatingSystem):
_storage: Storage

Expand All @@ -23,10 +29,16 @@ def __init__(self, storage: Storage) -> None:

def process_game(self, game: GameRecord) -> Glicko2Analytics:
if game.black_manual_rank_update is not None:
self._storage.set(game.black_id, Glicko2Entry(rank_to_rating(game.black_manual_rank_update)))
self._storage.set(
game.black_id,
Glicko2Entry(rank_to_rating(game.black_manual_rank_update)),
)

if game.white_manual_rank_update is not None:
self._storage.set(game.white_id, Glicko2Entry(rank_to_rating(game.white_manual_rank_update)))
self._storage.set(
game.white_id,
Glicko2Entry(rank_to_rating(game.white_manual_rank_update)),
)

if should_skip_game(game, self._storage):
return Glicko2Analytics(skipped=True, game=game)
Expand All @@ -38,10 +50,16 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:
black,
[
(
white.copy(get_handicap_adjustment("white", white.rating, game.handicap,
komi=game.komi, size=game.size,
rules=game.rules,
)),
white.copy(
get_handicap_adjustment(
"white",
white.rating,
game.handicap,
komi=game.komi,
size=game.size,
rules=game.rules,
)
),
game.winner_id == game.black_id,
)
],
Expand All @@ -52,10 +70,16 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:
white,
[
(
black.copy(get_handicap_adjustment("black", black.rating, game.handicap,
komi=game.komi, size=game.size,
rules=game.rules,
)),
black.copy(
get_handicap_adjustment(
"black",
black.rating,
game.handicap,
komi=game.komi,
size=game.size,
rules=game.rules,
)
),
game.winner_id == game.white_id,
)
],
Expand All @@ -64,17 +88,23 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:

self._storage.set(game.black_id, updated_black)
self._storage.set(game.white_id, updated_white)
#self._storage.add_rating_history(game.black_id, game.ended, updated_black)
#self._storage.add_rating_history(game.white_id, game.ended, updated_white)
# self._storage.add_rating_history(game.black_id, game.ended, updated_black)
# self._storage.add_rating_history(game.white_id, game.ended, updated_white)

return Glicko2Analytics(
skipped=False,
game=game,
expected_win_rate=black.expected_win_probability(
white, get_handicap_adjustment("black", black.rating, game.handicap,
komi=game.komi, size=game.size,
rules=game.rules,
), ignore_g=True
white,
get_handicap_adjustment(
"black",
black.rating,
game.handicap,
komi=game.komi,
size=game.size,
rules=game.rules,
),
ignore_g=True,
),
black_rating=black.rating,
white_rating=white.rating,
Expand All @@ -87,11 +117,24 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:
)



# Run
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

cli.add_argument(
"--starting-ranks",
dest="starting_ranks",
action="store_true",
help="Use a two pass system to bin players into an appropriate starting rank.",
)

config(cli.parse_args(), "glicko2-one-game-at-a-time")
game_data = GameData()
storage = InMemoryStorage(Glicko2Entry)

if config.args.starting_ranks:
storage = InMemoryStorageWithStartingRankStorage(Glicko2Entry)
else:
storage = InMemoryStorage(Glicko2Entry)

engine = OneGameAtATime(storage)
tally = TallyGameAnalytics(storage)

Expand All @@ -101,17 +144,34 @@ def process_game(self, game: GameRecord) -> Glicko2Analytics:

tally.print()

storage.finalize()

self_reported_ratings = tally.get_self_reported_rating()
if self_reported_ratings:
aga_1d = (self_reported_ratings['aga'][30] if 'aga' in self_reported_ratings else [1950.123456])
aga_1d = (
self_reported_ratings["aga"][30]
if "aga" in self_reported_ratings
else [1950.123456]
)
avg_1d_aga = sum(aga_1d) / len(aga_1d)
egf_1d = (self_reported_ratings['egf'][30] if 'egf' in self_reported_ratings else [1950.123456])
egf_1d = (
self_reported_ratings["egf"][30]
if "egf" in self_reported_ratings
else [1950.123456]
)
avg_1d_egf = sum(egf_1d) / len(egf_1d)
ratings_1d = ((self_reported_ratings['egf'][30] if 'egf' in self_reported_ratings else [1950.123456]) +
(self_reported_ratings['aga'][30] if 'aga' in self_reported_ratings else [1950.123456]))
ratings_1d = (
self_reported_ratings["egf"][30]
if "egf" in self_reported_ratings
else [1950.123456]
) + (
self_reported_ratings["aga"][30]
if "aga" in self_reported_ratings
else [1950.123456]
)
avg_1d_rating = sum(ratings_1d) / len(ratings_1d)

print("Avg 1d rating egf: %6.1f aga: %6.1f egf+aga: %6.1f" % (avg_1d_egf, avg_1d_aga, avg_1d_rating))



print(
"Avg 1d rating egf: %6.1f aga: %6.1f egf+aga: %6.1f"
% (avg_1d_egf, avg_1d_aga, avg_1d_rating)
)
3 changes: 3 additions & 0 deletions analysis/util/InMemoryStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ def get_matches_newer_or_equal_to(self, player_id: int, timestamp: int) -> Any:
else:
break
return [e[1] for e in self._match_history[player_id][-ct:]]

def finalize(self) -> None:
pass
Loading