Skip to content

Commit

Permalink
Add annotations (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
woctezuma committed Dec 30, 2024
1 parent 9f976bb commit a250dd1
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 163 deletions.
12 changes: 6 additions & 6 deletions igdb_look_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def get_igdb_request_headers():


def look_up_game_name(
game_name,
enforced_year=None,
game_name: str,
enforced_year: int | None = None,
*,
must_be_available_on_pc=True,
must_be_a_game=True,
must_be_available_on_pc: bool = True,
must_be_a_game: bool = True,
enforced_platform=None,
enforced_game_category=None,
year_constraint="equality",
verbose=True,
year_constraint: str = "equality",
verbose: bool = True,
):
if verbose:
print(
Expand Down
4 changes: 2 additions & 2 deletions igdb_match_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def format_game_name_for_igdb(raw_name, *, verbose=True):

def match_names_with_igdb(
raw_votes,
release_year=None,
release_year: str | None = None,
*,
must_be_available_on_pc=True,
must_be_a_game=True,
Expand Down Expand Up @@ -290,7 +290,7 @@ def merge_databases(new_database, previous_database):

def download_igdb_local_databases(
ballots,
release_year=None,
release_year: str | None = None,
*,
apply_hard_coded_extension_and_fixes=True,
extend_previous_databases=True,
Expand Down
18 changes: 9 additions & 9 deletions igdb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def get_steam_service_no() -> int:


def append_filter_for_igdb_fields(
igdb_fields,
filter_name,
filter_value,
igdb_fields: str,
filter_name: str,
filter_value: str | list[int] | int,
*,
use_parenthesis=False,
comparison_symbol="=",
use_parenthesis: bool = False,
comparison_symbol: str = "=",
):
where_statement = " ; where "
conjunction_statement = " & "
Expand Down Expand Up @@ -208,12 +208,12 @@ def get_comparison_symbol(year_constraint="equality"):

def get_igdb_fields_for_games(
*,
must_be_available_on_pc=True,
must_be_a_game=True,
must_be_available_on_pc: bool = True,
must_be_a_game: bool = True,
enforced_platform=None,
enforced_game_category=None,
enforced_year=None,
year_constraint="equality",
enforced_year: int | None = None,
year_constraint: str = "equality",
):
# Reference: https://api-docs.igdb.com/?kotlin#game

Expand Down
12 changes: 6 additions & 6 deletions load_ballots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def load_ballots(input_filename):


def print_reviews(
ballots,
matches,
app_id,
goty_field="goty_preferences",
goty_review_field=None,
ballots: dict,
matches: dict,
app_id: str,
goty_field: str = "goty_preferences",
goty_review_field: str | None = None,
*,
export_for_forum=True,
export_for_forum: bool = True,
) -> None:
if goty_review_field is None:
goty_review_field = goty_field.replace("_preferences", "_description")
Expand Down
96 changes: 50 additions & 46 deletions match_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@


def constrain_app_id_search_by_year(
dist,
sorted_app_ids,
release_year,
max_num_tries_for_year,
year_constraint="equality",
):
dist: dict[str, float],
sorted_app_ids: list[str],
release_year: int | None,
max_num_tries_for_year: int,
year_constraint: str | None = "equality",
) -> list[str]:
filtered_sorted_app_ids = sorted_app_ids.copy()

if release_year is not None and year_constraint is not None:
Expand Down Expand Up @@ -85,18 +85,18 @@ def constrain_app_id_search_by_year(


def apply_hard_coded_fixes_to_app_id_search(
game_name_input,
filtered_sorted_app_ids,
num_closest_neighbors,
):
game_name_input: str,
filtered_sorted_app_ids: list[str],
num_closest_neighbors: int,
) -> str:
closest_app_id = [find_hard_coded_app_id(game_name_input)]
if num_closest_neighbors > 1:
closest_app_id.extend(filtered_sorted_app_ids[0 : (num_closest_neighbors - 1)])

return closest_app_id


def get_default_distance_cut_off_for_difflib():
def get_default_distance_cut_off_for_difflib() -> float:
# Reference: https://docs.python.org/3/library/difflib.html

similarity_cut_off = 0.6
Expand All @@ -105,16 +105,16 @@ def get_default_distance_cut_off_for_difflib():


def find_closest_app_id(
game_name_input,
steamspy_database,
release_year=None,
num_closest_neighbors=1,
max_num_tries_for_year=2,
game_name_input: str,
steamspy_database: dict,
release_year: int | None = None,
num_closest_neighbors: int = 1,
max_num_tries_for_year: int = 2,
*,
use_levenshtein_distance=True,
year_constraint="equality",
is_steamspy_api_paginated=True,
):
use_levenshtein_distance: bool = True,
year_constraint: str = "equality",
is_steamspy_api_paginated: bool = True,
) -> tuple[list[str], list[int]]:
if use_levenshtein_distance:
# n is not used by Levenshtein distance.
n = None
Expand Down Expand Up @@ -165,16 +165,16 @@ def find_closest_app_id(


def precompute_matches(
raw_votes,
release_year=None,
num_closest_neighbors=3,
max_num_tries_for_year=2,
raw_votes: dict,
release_year: int | None = None,
num_closest_neighbors: int = 3,
max_num_tries_for_year: int = 2,
*,
use_levenshtein_distance=True,
year_constraint="equality",
goty_field="goty_preferences",
is_steamspy_api_paginated=True,
):
use_levenshtein_distance: bool = True,
year_constraint: str = "equality",
goty_field: str = "goty_preferences",
is_steamspy_api_paginated: bool = True,
) -> dict:
seen_game_names = set()
matches = {}

Expand Down Expand Up @@ -219,7 +219,7 @@ def precompute_matches(
return matches


def display_matches(matches, *, print_after_sort=True) -> None:
def display_matches(matches: dict, *, print_after_sort: bool = True) -> None:
# Index of the neighbor used to sort keys of the matches dictionary
neighbor_reference_index = 0

Expand Down Expand Up @@ -265,7 +265,11 @@ def display_matches(matches, *, print_after_sort=True) -> None:
print()


def normalize_votes(raw_votes, matches, goty_field="goty_preferences"):
def normalize_votes(
raw_votes: dict,
matches: dict,
goty_field: str = "goty_preferences",
) -> dict:
# Index of the first neighbor
neighbor_reference_index = 0

Expand Down Expand Up @@ -296,22 +300,22 @@ def normalize_votes(raw_votes, matches, goty_field="goty_preferences"):


def standardize_ballots(
ballots,
release_year,
ballots: dict,
release_year: int | None,
*,
print_after_sort=True,
use_igdb=False,
retrieve_igdb_data_from_scratch=True,
apply_hard_coded_extension_and_fixes=True,
use_levenshtein_distance=True,
extend_previous_databases=True,
must_be_available_on_pc=True,
must_be_a_game=True,
goty_field="goty_preferences",
year_constraint="equality",
print_matches=True,
verbose=False,
):
print_after_sort: bool = True,
use_igdb: bool = False,
retrieve_igdb_data_from_scratch: bool = True,
apply_hard_coded_extension_and_fixes: bool = True,
use_levenshtein_distance: bool = True,
extend_previous_databases: bool = True,
must_be_available_on_pc: bool = True,
must_be_a_game: bool = True,
goty_field: str = "goty_preferences",
year_constraint: str = "equality",
print_matches: bool = True,
verbose: bool = False,
) -> tuple[dict, dict]:
if use_igdb:
# Using IGDB

Expand Down
51 changes: 28 additions & 23 deletions optional_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from steam_store_utils import get_link_to_store


def get_best_optional_categories():
def get_best_optional_categories() -> list[str]:
return [f"best_{categorie}" for categorie in get_optional_categories()]


def get_optional_ballots(ballots, category_name):
def get_optional_ballots(ballots: dict, category_name: str) -> list:
return [
ballots[voter_name][category_name]
for voter_name in ballots
Expand All @@ -24,15 +24,18 @@ def get_optional_ballots(ballots, category_name):
]


def filter_noise_from_optional_ballots(optional_ballots):
def filter_noise_from_optional_ballots(optional_ballots: dict) -> list[str]:
return [element for element in optional_ballots if not is_a_noisy_vote(element)]


def get_dummy_field() -> str:
return "dummy_preferences"


def format_optional_ballots_for_igdb_matching(optional_ballots, dummy_field=None):
def format_optional_ballots_for_igdb_matching(
optional_ballots: dict,
dummy_field: str | None = None,
) -> dict[str, dict[str, dict[int, str]]]:
if dummy_field is None:
dummy_field = get_dummy_field()

Expand All @@ -48,16 +51,16 @@ def format_optional_ballots_for_igdb_matching(optional_ballots, dummy_field=None


def match_optional_ballots(
optional_ballots,
release_year=None,
optional_ballots: dict,
release_year: int | None = None,
*,
use_igdb=False,
retrieve_igdb_data_from_scratch=True,
apply_hard_coded_extension_and_fixes=True,
must_be_available_on_pc=False,
must_be_a_game=False,
use_levenshtein_distance=True,
):
use_igdb: bool = False,
retrieve_igdb_data_from_scratch: bool = True,
apply_hard_coded_extension_and_fixes: bool = True,
must_be_available_on_pc: bool = False,
must_be_a_game: bool = False,
use_levenshtein_distance: bool = True,
) -> list[str]:
import steampi.calendar

from extend_steamspy import load_extended_steamspy_database
Expand Down Expand Up @@ -190,7 +193,7 @@ def match_optional_ballots(
return matched_optional_ballots


def count_optional_ballots(optional_ballots):
def count_optional_ballots(optional_ballots: dict) -> dict:
optional_counts = {}

for element in optional_ballots:
Expand All @@ -202,7 +205,9 @@ def count_optional_ballots(optional_ballots):
return optional_counts


def compute_ranking_based_on_optional_ballots(optional_ballots):
def compute_ranking_based_on_optional_ballots(
optional_ballots: dict,
) -> list[tuple[str, int]]:
optional_counts = count_optional_ballots(optional_ballots)

# Reference: https://stackoverflow.com/a/37693603
Expand All @@ -213,7 +218,7 @@ def compute_ranking_based_on_optional_ballots(optional_ballots):
)


def pretty_display(ranking) -> None:
def pretty_display(ranking: list[tuple[str, int]]) -> None:
print()

current_num_votes = 0
Expand All @@ -237,14 +242,14 @@ def pretty_display(ranking) -> None:


def display_optional_ballots(
input_filename,
input_filename: str,
*,
filter_noise=True,
release_year=None,
use_igdb=False,
retrieve_igdb_data_from_scratch=True,
apply_hard_coded_extension_and_fixes=True,
use_levenshtein_distance=True,
filter_noise: bool = True,
release_year: int | None = None,
use_igdb: bool = False,
retrieve_igdb_data_from_scratch: bool = True,
apply_hard_coded_extension_and_fixes: bool = True,
use_levenshtein_distance: bool = True,
) -> bool:
from load_ballots import load_ballots

Expand Down
3 changes: 2 additions & 1 deletion parsing_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def adjust_params_to_year(params: dict[str, dict], year: str | int) -> dict[str,
return params


def get_adjusted_parsing_params(year: str | int):
def get_adjusted_parsing_params(year: str | int) -> dict[str, dict]:
return adjust_params_to_year(get_default_parsing_params(), year)


Expand Down Expand Up @@ -113,6 +113,7 @@ def get_parsing_offset(*, is_anonymized: bool) -> int:

def get_parsing_indices(
year: str | int,
*,
is_anonymized: bool,
) -> dict[str, dict[str, list[int | None]]]:
params = get_adjusted_parsing_params(year=year)
Expand Down
Loading

0 comments on commit a250dd1

Please sign in to comment.