Skip to content

Commit

Permalink
Fix imports as a result of removing the Hero class.
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyadev committed Feb 15, 2024
1 parent dee0e2a commit 211c46e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 63 deletions.
21 changes: 4 additions & 17 deletions database/database.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion heroes/hero_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 2 additions & 45 deletions statistic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand All @@ -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]

Expand All @@ -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"])

Expand Down

0 comments on commit 211c46e

Please sign in to comment.