exploring stat comparision
This commit is contained in:
parent
266b354513
commit
d5899d3a75
|
|
@ -0,0 +1,6 @@
|
|||
[project]
|
||||
name = "leetify-data-exploration"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"click"
|
||||
]
|
||||
|
|
@ -0,0 +1 @@
|
|||
from .core import *
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
@ -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()
|
||||
|
|
@ -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)
|
||||
Loading…
Reference in New Issue