diff --git a/sandbox/data-exploration/pyproject.toml b/sandbox/data-exploration/pyproject.toml new file mode 100644 index 0000000..99ef37d --- /dev/null +++ b/sandbox/data-exploration/pyproject.toml @@ -0,0 +1,6 @@ +[project] +name = "leetify-data-exploration" +version = "0.0.1" +dependencies = [ + "click" +] diff --git a/sandbox/data-exploration/src/api/__init__.py b/sandbox/data-exploration/src/api/__init__.py new file mode 100644 index 0000000..bb67a43 --- /dev/null +++ b/sandbox/data-exploration/src/api/__init__.py @@ -0,0 +1 @@ +from .core import * diff --git a/sandbox/data-exploration/src/api/core.py b/sandbox/data-exploration/src/api/core.py new file mode 100644 index 0000000..a797feb --- /dev/null +++ b/sandbox/data-exploration/src/api/core.py @@ -0,0 +1,20 @@ +import requests + +class Leetify: + api_base_url = "https://api.leetify.com/api" + profile_base_url = f"{api_base_url}/profile" + match_base_url = f"{api_base_url}/games" + + def __get_page(self, url: str) -> dict: + resp = requests.get(url) + return resp.json() + + def get_profile(self, id: str) -> dict: + url = f"{self.profile_base_url}/{id}" + return self.__get_page(url) + + def get_match(self, id: str) -> dict: + url = f"{self.match_base_url}/{id}" + return self.__get_page(url) + + diff --git a/sandbox/data-exploration/src/tools/__init__.py b/sandbox/data-exploration/src/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sandbox/data-exploration/src/tools/recent_player_comp.py b/sandbox/data-exploration/src/tools/recent_player_comp.py new file mode 100644 index 0000000..7be485e --- /dev/null +++ b/sandbox/data-exploration/src/tools/recent_player_comp.py @@ -0,0 +1,60 @@ +import click +import pandas as pd +from api import Leetify +from tools.utils import playerStats_df, get_n_matches + + +@click.command() +@click.option("--user", prompt="Your user id") +@click.option("-n", prompt="number of games", type=int) +@click.option( + "--include-self", + help="Includes self in overal stat averages", + default=False, + type=bool, +) +def comp_users(user, n, include_self): + api = Leetify() + cols_of_interest = [ + "preaim", + "reactionTime", + "accuracy", + "accuracyEnemySpotted", + "accuracyHead", + "sprayAccuracy", + "counterStrafingShotsGoodRatio", + "hsp", + "mvps", + "totalKills", + "kdRatio", + ] + + profile = api.get_profile(user) + + meta = profile.get("meta") + if not meta: + print("Missing user meta data(could be malformed response from api)") + return + + name = meta.get("name") + print(f"{name}") + + matches = get_n_matches(profile, n) + + m_ids = [m.get("gameId") for m in matches] + dfs = [playerStats_df(id) for id in m_ids] + + df = pd.concat(dfs) + players_of_interest_df = ( + df if include_self else df[df["leetifyUserId"] != meta["leetifyUserId"]] + ) + stats_of_interest_df = players_of_interest_df[cols_of_interest] + total_means = stats_of_interest_df.mean() + my_means = df[df["leetifyUserId"] == meta["leetifyUserId"]][ + cols_of_interest + ].mean() + print(my_means - total_means) + + +if __name__ == "__main__": + comp_users() diff --git a/sandbox/data-exploration/src/tools/utils.py b/sandbox/data-exploration/src/tools/utils.py new file mode 100644 index 0000000..7b844f2 --- /dev/null +++ b/sandbox/data-exploration/src/tools/utils.py @@ -0,0 +1,12 @@ +from api import Leetify +import pandas as pd + +def get_n_matches(profile, n): + key_f = lambda match: match.get("gameFinishedAt") + games = sorted(profile.get("games"), key=key_f, reverse=True) + return games[:n] + +def playerStats_df(id, api = Leetify()): + m_details = api.get_match(id) + pStats = m_details.get('playerStats') + return pd.DataFrame(pStats)