Skip to content

Commit

Permalink
Add Algolia Support (#105)
Browse files Browse the repository at this point in the history
* Add Algolia Support

Signed-off-by: Vivek Joshy <8206808+vivekjoshy@users.noreply.github.com>

* Add Changelog Fragment

Signed-off-by: Vivek Joshy <8206808+vivekjoshy@users.noreply.github.com>

---------

Signed-off-by: Vivek Joshy <8206808+vivekjoshy@users.noreply.github.com>
  • Loading branch information
vivekjoshy committed Aug 11, 2023
1 parent b7b4918 commit 7e2f977
Show file tree
Hide file tree
Showing 27 changed files with 493 additions and 492 deletions.
30 changes: 26 additions & 4 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from processors import Draw, Rank, Win
from prompt_toolkit import HTML
from prompt_toolkit import print_formatted_text as print
from prompt_toolkit import prompt
Expand All @@ -12,6 +11,7 @@
ThurstoneMostellerFull,
ThurstoneMostellerPart,
)
from processors import Draw, Rank, Win


class NumberValidator(Validator):
Expand Down Expand Up @@ -48,6 +48,13 @@ def validate(self, document):
input_benchmark_type = prompt(
"Benchmark Processor: ", completer=benchmark_types_completer
)
minimum_matches = int(
prompt("Minimum Matches Per Player: ", validator=NumberValidator())
)
if minimum_matches < 1:
print(HTML("<style fg='Red'>Invalid Match Count</style>"))
quit()

input_seed = int(prompt("Enter Random Seed: ", validator=NumberValidator()))

model = None
Expand All @@ -59,15 +66,30 @@ def validate(self, document):

if input_benchmark_type in benchmark_type_names.keys() and model:
if input_benchmark_type == "Win":
win_processor = Win(path="data/overwatch.jsonl", seed=input_seed, model=model)
win_processor = Win(
path="data/overwatch.jsonl",
seed=input_seed,
minimum_matches=minimum_matches,
model=model,
)
win_processor.process()
win_processor.print_result()
elif input_benchmark_type == "Draw":
draw_processor = Draw(path="data/chess.csv", seed=input_seed, model=model)
draw_processor = Draw(
path="data/chess.csv",
seed=input_seed,
minimum_matches=minimum_matches,
model=model,
)
draw_processor.process()
draw_processor.print_result()
elif input_benchmark_type == "Rank":
rank_processor = Rank(path="data/overwatch.jsonl", seed=input_seed, model=model)
rank_processor = Rank(
path="data/overwatch.jsonl",
seed=input_seed,
minimum_matches=minimum_matches,
model=model,
)
rank_processor.process()
rank_processor.print_result()
else:
Expand Down
40 changes: 27 additions & 13 deletions benchmark/processors/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from prompt_toolkit import HTML
from prompt_toolkit import print_formatted_text as print
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.styles import Style
from sklearn.model_selection import train_test_split

import openskill
from openskill.models import (
BradleyTerryFull,
BradleyTerryPart,
Expand Down Expand Up @@ -46,6 +46,7 @@ def __init__(
self,
path,
seed: int,
minimum_matches: int,
model: Union[
BradleyTerryFull,
BradleyTerryPart,
Expand All @@ -60,11 +61,13 @@ def __init__(
for match_index, row in df.iterrows():
self.data.append(row)
self.seed = seed
self.minimum_matches = minimum_matches
self.model = model

# Counters
self.match_count = {}
self.confident_matches = 0
self.available_matches = 0
self.valid_matches = 0
self.openskill_correct_predictions = 0
self.openskill_incorrect_predictions = 0
self.trueskill_correct_predictions = 0
Expand All @@ -87,15 +90,24 @@ def __init__(
self.trueskill_time = None

def process(self):
style = Style.from_dict(
{
"label": "bg:#ffff00 #000000",
"percentage": "bg:#ffff00 #000000",
"current": "#448844",
"bar": "",
}
)

title = HTML(f'<style fg="Red">Counting Matches</style>')
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
for match in progress_bar(self.data, total=len(self.data)):
if self.consistent(match=match):
self.count(match=match)

# Check if data has sufficient history.
title = HTML(f'<style fg="Red">Verifying History</style>')
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
for match in progress_bar(self.data, total=len(self.data)):
if self.consistent(match=match):
if self.has_sufficient_history(match=match):
Expand All @@ -111,7 +123,7 @@ def process(self):
title = HTML(
f'Updating OpenSkill Ratings with <style fg="Green">{self.model.__name__}</style> Model:'
)
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
os_process_time_start = time.time()
for match in progress_bar(self.training_set, total=len(self.training_set)):
self.process_openskill(match=match)
Expand All @@ -122,7 +134,7 @@ def process(self):
title = HTML(
f'Updating Ratings with <style fg="Green">TrueSkill</style> Model:'
)
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
ts_process_time_start = time.time()
for match in progress_bar(self.training_set, total=len(self.training_set)):
self.process_trueskill(match=match)
Expand All @@ -131,22 +143,23 @@ def process(self):

# Process Test Set
title = HTML(f'<style fg="Red">Processing Test Set</style>')
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
for match in progress_bar(self.test_set, total=len(self.test_set)):
if self.valid_test(match=match):
self.verified_test_set.append(match)
self.valid_matches += 1

# Predict OpenSkill Matches
title = HTML(f'<style fg="Blue">Predicting OpenSkill Matches:</style>')
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
for match in progress_bar(
self.verified_test_set, total=len(self.verified_test_set)
):
self.predict_openskill(match=match)

# Predict TrueSkill Matches
title = HTML(f'<style fg="Blue">Predicting TrueSkill Matches:</style>')
with ProgressBar(title=title) as progress_bar:
with ProgressBar(title=title, style=style) as progress_bar:
for match in progress_bar(
self.verified_test_set, total=len(self.verified_test_set)
):
Expand All @@ -157,9 +170,10 @@ def print_result(self):
print("-" * 40)
print(
HTML(
f"Confident Matches: <style fg='Yellow'>{self.confident_matches}</style>"
f"Available Matches: <style fg='Yellow'>{self.available_matches}</style>"
)
)
print(HTML(f"Valid Matches: <style fg='Yellow'>{self.valid_matches}</style>"))
print(
HTML(
f"Predictions Made with OpenSkill's <style fg='Green'><u>{self.model.__name__}</u></style> Model:"
Expand Down Expand Up @@ -278,13 +292,13 @@ def has_sufficient_history(self, match):
white_player: dict = match["white_username"]
black_player: dict = match["black_username"]

if self.match_count[white_player] < 2:
if self.match_count[white_player] < self.minimum_matches:
return False

if self.match_count[black_player] < 2:
if self.match_count[black_player] < self.minimum_matches:
return False

self.confident_matches += 1
self.available_matches += 1
return True

def process_openskill(self, match):
Expand Down

0 comments on commit 7e2f977

Please sign in to comment.