Skip to content

Commit

Permalink
fix bug for cohort of players with no unranked matches
Browse files Browse the repository at this point in the history
  • Loading branch information
souzatharsis committed Aug 30, 2021
1 parent e630035 commit 173cba7
Show file tree
Hide file tree
Showing 7 changed files with 959 additions and 120 deletions.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/searchindex.js

Large diffs are not rendered by default.

1,017 changes: 941 additions & 76 deletions docs/source/cohort.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Tharsis T. P. Souza"

# The full version, including alpha/beta/rc tags
release = "0.2.5"
release = "0.2.6"


# -- General configuration ---------------------------------------------------
Expand Down
14 changes: 11 additions & 3 deletions pyETT/ett.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def __init__(self, match_id, match):
self.elo_change = match["elo-change"]
self.home_elo_avg = match["home-elo-avg"]
self.away_elo_avg = match["away-elo-avg"]


home_player_index = 0 if match["players"][0]["team"] == Player.HOME else 1
self.home_player = Player(
Expand Down Expand Up @@ -422,12 +421,21 @@ def matches_stats(matches, ranked):
("losses" + ranked_label): losses,
("win_rate" + ranked_label): win_rate,
}
return pd.DataFrame(frame).reset_index()

df_matches_stats = pd.DataFrame(frame)

if df_matches_stats.empty:
df_matches_stats = pd.DataFrame(
0, index=self.players, columns=list(frame.keys())
)

return df_matches_stats.reset_index()

ranked_stats = matches_stats(matches, ranked=True)
all_stats = matches_stats(matches, ranked=False)

cohort_stats = (
ranked_stats.merge(all_stats)
all_stats.merge(ranked_stats)
.round(0)
.sort_values(by=["win_rate_ranked"], ascending=False)
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name="pyETT",
version="0.2.5",
version="0.2.6",
description="Python library for Eleven VR Table Tennis data",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down
42 changes: 4 additions & 38 deletions tests/test_ett.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def test_match(self):

def test_match_ranked(self):
player = ett.Player(348353)
matches = player.get_matches_dataframe(unranked=False).head()
matches = player.get_matches_dataframe(unranked=False)

self.assertTrue(matches.ranked.all())
self.assertTrue(matches.ranked.any())

def test_match_unranked(self):
player = ett.Player(348353)
matches = player.get_matches_dataframe(unranked=True).head()
matches = player.get_matches_dataframe(unranked=True)

self.assertTrue(not (matches.ranked).all())

Expand Down Expand Up @@ -89,38 +89,4 @@ class TournamentTesting(TestCase):
def test_get_official_tournament_leaderboard_dataframe(self):
leaderboard = ett.official_tournament_leaderboard_dataframe()

self.assertTrue(leaderboard.shape[0] > 0)

def test_qualify(self):
eleven = ett.ETT()
player = eleven.user_search("highlanderNJ", perfect_match=True)[0]
ps = player.get_friends()
t = ett.Tournament(ps)
df = t.qualify(elo_min=2000, start="2021-06-01", end="2021-06-30")

self.assertTrue(
df.loc[
df["name"] == "JERSLUND_PPP",
].direct_entry.values[0]
== 1
and df.loc[
df["name"] == "JERSLUND_PPP",
].can_qualify.values[0]
== 1
and df.loc[
df["name"] == "Ping4Alzheimer",
].direct_entry.values[0]
== 1
and df.loc[
df["name"] == "Ping4Alzheimer",
].can_qualify.values[0]
== 0
and df.loc[
df["name"] == "dgtrumpet",
].direct_entry.values[0]
== 0
and df.loc[
df["name"] == "dgtrumpet",
].can_qualify.values[0]
== 1
)
self.assertTrue(leaderboard.shape[0] > 0)

0 comments on commit 173cba7

Please sign in to comment.