From 211c46eb20d1a55201bb3944515e1bba5e63841a Mon Sep 17 00:00:00 2001 From: Aryan Kothari <87589047+thearyadev@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:54:58 -0500 Subject: [PATCH] Fix imports as a result of removing the Hero class. --- database/database.py | 21 ++++------------- heroes/hero_comparison.py | 2 +- statistic/__init__.py | 47 ++------------------------------------- 3 files changed, 7 insertions(+), 63 deletions(-) diff --git a/database/database.py b/database/database.py index 50872b5c..908a12f0 100644 --- a/database/database.py +++ b/database/database.py @@ -1,14 +1,8 @@ -import datetime import threading - from mysql.connector import pooling - import leaderboards -from heroes import Hero - lock = threading.Lock() - class DatabaseAccess: def __init__( self, user: str, password: str, host: str, port: str | int, database: str @@ -117,17 +111,11 @@ def add_leaderboard_entry( ( leaderboard_entry.region.name, leaderboard_entry.role.name, - leaderboard_entry.games, + 0, # games played, legacy # can be string or Hero object. If it's a Hero object, get the name. - leaderboard_entry.heroes[0].name - if isinstance(leaderboard_entry.heroes[0], Hero) - else leaderboard_entry.heroes[0], - leaderboard_entry.heroes[1].name - if isinstance(leaderboard_entry.heroes[1], Hero) - else leaderboard_entry.heroes[1], - leaderboard_entry.heroes[2].name - if isinstance(leaderboard_entry.heroes[2], Hero) - else leaderboard_entry.heroes[2], + leaderboard_entry.heroes[0], + leaderboard_entry.heroes[1], + leaderboard_entry.heroes[2], ), ) connection.commit() @@ -170,7 +158,6 @@ def get_all_records(self, seasonNumber: str) -> list[leaderboards.LeaderboardEnt ], role=leaderboards.Role[line[2]], region=leaderboards.Region[line[1]], - games=line[3], ) ) return results diff --git a/heroes/hero_comparison.py b/heroes/hero_comparison.py index b87c0f4c..a9e05acb 100644 --- a/heroes/hero_comparison.py +++ b/heroes/hero_comparison.py @@ -142,7 +142,7 @@ def predict_hero_name(self, image: Image, model_directory: Path) -> str: NNModel = importlib.import_module(f"models.{model_directory.name}.model").NNModel transformer = importlib.import_module(f"models.{model_directory.name}.model").transformer - st_dict = torch.load("./model_save.pth") + st_dict = torch.load(model_directory / "model.pth") model = NNModel(num_classes=40) model.to(device) model.load_state_dict(st_dict) diff --git a/statistic/__init__.py b/statistic/__init__.py index 1836ade0..dc4aa8d5 100644 --- a/statistic/__init__.py +++ b/statistic/__init__.py @@ -2,21 +2,13 @@ import database import leaderboards -from heroes import Hero, Heroes +from heroes import Heroes def convert_dict_to_hero_count_array(data: dict) -> list[dict]: return [{"hero": i[0], "count": i[1]} for i in data.items()] -def extract_games_played(i: leaderboards.LeaderboardEntry): - return i.games - - -def filter_games_results(i: leaderboards.LeaderboardEntry) -> bool: - return 25 <= i.games <= 725 - - def get_occurrences( *, data: list[leaderboards.LeaderboardEntry], @@ -96,7 +88,7 @@ def get_occurrences_most_played( if entry.role not in acceptedRoles: continue - mostPlayedHero: Hero | str = entry.heroes[mostPlayedSlot] + mostPlayedHero: str = entry.heroes[mostPlayedSlot] if isinstance(mostPlayedHero, str): if mostPlayedHero in results: results[mostPlayedHero] += 1 @@ -115,26 +107,6 @@ def get_occurrences_most_played( ) -def get_avg_games_played_by_region( - *, data: list[leaderboards.LeaderboardEntry], region: leaderboards.Region -) -> list[dict]: - results: dict[str, float] = {} - - for entry in filter(filter_games_results, data): - if entry.region != region: - continue - if entry.role.name in results: - results[entry.role.name] += entry.games / 500 - continue - results[entry.role.name] = entry.games / 500 - - return sorted( - convert_dict_to_hero_count_array(results), - key=lambda x: x["count"], - reverse=True, - ) - - def convert_count_dict_to_array(data: list[dict]) -> list[int | float]: return [entry["count"] for entry in data] @@ -151,21 +123,6 @@ def get_stdev(data: list[dict]) -> float: return statistics.stdev(convert_count_dict_to_array(data)) -def get_games_played_max(data: list[leaderboards.LeaderboardEntry]) -> int: - # return max(map(extract_games_played, filter(filter_games_results, data))) - return 0 - - -def get_games_played_min(data: list[leaderboards.LeaderboardEntry]) -> int: - # return min(map(extract_games_played, filter(filter_games_results, data))) - return 0 - - -def get_games_played_total(data: list[leaderboards.LeaderboardEntry]) -> int: - # return sum(map(extract_games_played, filter(filter_games_results, data))) - return 0 - - def get_number_of_ohp(data: list[leaderboards.LeaderboardEntry]) -> int: return len([i for i in data if i.heroes[1] == "Blank" or i.heroes[1] == "Blank2"])