Skip to content

Commit

Permalink
Add and fix some annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
woctezuma committed Dec 29, 2024
1 parent ef8cf36 commit 2c3f173
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion anonymize_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_review_token_indices(


def get_author_name_token_index(
ballot_year: str = "2018",
ballot_year: str | int = "2018",
*,
is_anonymized: bool = False,
) -> int:
Expand Down
13 changes: 8 additions & 5 deletions parsing_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def adjust_params_to_year(params: dict[str, dict], year: str | int) -> dict[str,
return params


def get_adjusted_parsing_params(year):
def get_adjusted_parsing_params(year: str | int):
return adjust_params_to_year(get_default_parsing_params(), year)


def get_next_indices(last_index: int = 0, num_indices: int = 0) -> tuple[int, int, int]:
def get_next_indices(
last_index: int = 0,
num_indices: int = 0,
) -> tuple[int, int, int | None]:
# The first index to include
start = 1 + last_index

Expand All @@ -67,7 +70,7 @@ def get_next_indices(last_index: int = 0, num_indices: int = 0) -> tuple[int, in
def convert_params_to_indices(
params: dict[str, dict],
offset: int = 9,
) -> dict[str, dict]:
) -> dict:
voter_index = offset

indices = {
Expand Down Expand Up @@ -108,9 +111,9 @@ def get_parsing_offset(*, is_anonymized: bool) -> int:
return 0 if is_anonymized else 9


def get_parsing_indices(year, is_anonymized):
def get_parsing_indices(year: str | int, is_anonymized: bool):
params = get_adjusted_parsing_params(year=year)
offset = get_parsing_offset(is_anonymized)
offset = get_parsing_offset(is_anonymized=is_anonymized)
return convert_params_to_indices(params, offset)


Expand Down
4 changes: 2 additions & 2 deletions parsing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def parse_csv(fname: str, parsing_params):
if not is_anonymized:
text_data = remove_header(text_data)

return parse_text_data(text_data, parsing_params, is_anonymized)
return parse_text_data(text_data, parsing_params, is_anonymized=is_anonymized)


def parse_text_data(
Expand All @@ -58,7 +58,7 @@ def parse_text_data(

voter_name = read_voter_name(tokens, indices)

single_ballot = {}
single_ballot: dict = {}
single_ballot = fill_in_review(tokens, indices, single_ballot=single_ballot)
single_ballot = fill_in_game_list(
tokens,
Expand Down
28 changes: 14 additions & 14 deletions schulze_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@


def apply_pipeline_for_optional_categories(
input_filename,
release_year="2020",
input_filename: str,
release_year: str = "2020",
*,
try_to_break_ties=True,
use_igdb=True,
retrieve_igdb_data_from_scratch=True,
apply_hard_coded_extension_and_fixes=True,
use_levenshtein_distance=True,
goty_field="goty_preferences",
year_constraint="equality",
print_matches=True,
num_app_id_groups_to_display=3,
must_be_available_on_pc=False,
must_be_a_game=False,
verbose=False,
try_to_break_ties: bool = True,
use_igdb: bool = True,
retrieve_igdb_data_from_scratch: bool = True,
apply_hard_coded_extension_and_fixes: bool = True,
use_levenshtein_distance: bool = True,
goty_field: str = "goty_preferences",
year_constraint: str = "equality",
print_matches: bool = True,
num_app_id_groups_to_display: int = 3,
must_be_available_on_pc: bool = False,
must_be_a_game: bool = False,
verbose: bool = False,
) -> bool:
ballots = load_ballots(input_filename)

Expand Down
10 changes: 5 additions & 5 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def test_filtering_out(self) -> None:
def test_filter_out_votes_for_early_access_titles(self) -> None:
ballot_year = "2018"

ballots = {}
ballots: dict = {}

# Add dummy vote for an Early Access game
ballots["dummy_voter_name"] = {}
Expand Down Expand Up @@ -810,7 +810,7 @@ def test_figure_out_ballots_with_missing_data(self) -> None:
dummy_voter = "dummy_voter_name"
goty_field = "dummy_preferences"

ballots = {}
ballots: dict = {}
ballots[dummy_voter] = {}
ballots[dummy_voter][goty_field] = {}
ballots[dummy_voter][goty_field][1] = "Hello"
Expand Down Expand Up @@ -844,7 +844,7 @@ def test_figure_out_ballots_with_missing_data(self) -> None:
def test_load_igdb_local_databases(self) -> None:
ballot_year = "2018"

ballots = {}
ballots: dict = {}

# Add dummy votes for the two actual GotY 2018 on MetaCouncil
ballots["dummy_voter_name"] = {}
Expand Down Expand Up @@ -925,7 +925,7 @@ def test_load_igdb_match_database(self) -> None:
assert data is not None

def test_save_igdb_match_database(self) -> None:
data = {}
data: dict = {}
file_name = "data/dummy_match_file_for_unit_test.json"
igdb_databases.save_igdb_match_database(data, file_name=file_name)
assert Path(file_name).exists()
Expand All @@ -936,7 +936,7 @@ def test_load_igdb_local_database(self) -> None:
assert data is not None

def test_save_igdb_local_database(self) -> None:
data = {}
data: dict = {}
file_name = "data/dummy_local_file_for_unit_test.json"
igdb_databases.save_igdb_local_database(data, file_name=file_name)
assert Path(file_name).exists()
Expand Down

0 comments on commit 2c3f173

Please sign in to comment.