Esempio n. 1
0
def test_draft_player_to_empty_roster_fail_to_find():
    avail = df.copy()
    empty_roster = pd.DataFrame()
    mean_player = sfb.mean_player(avail)
    single_player = sfb.find_player("Damian Lillard", avail)
    player_name = "Steven Curry"
    assert sfb.draft_player(player_name, empty_roster, avail).equals(
        empty_roster
    )  # empty unchanged
    assert sfb.draft_player(player_name, mean_player, avail).equals(
        mean_player
    )  # mean unchanged
    assert sfb.draft_player(player_name, single_player, avail).equals(
        single_player
    )  # single unchanged
    assert avail.equals(df)  # avail unchanged
Esempio n. 2
0
def test_means_player_produces_means():
    avail = df.copy()  # generate duplicate data
    mean_player = sfb.mean_player(avail)
    assert len(mean_player.values) == 1  # produces a single player
    assert mean_player["Player"].values[0] == "Mr Mean"  # name is correct
    assert mean_player["G"].values[0] == avail["G"].mean()  # g is correct
    assert mean_player["FGM"].values[0] == avail["FGM"].mean()  # fgm is correct
    assert mean_player["FGA"].values[0] == avail["FGA"].mean()  # fga is correct
    assert mean_player["3PT"].values[0] == avail["3PT"].mean()  # 3pt is correct
    assert mean_player["FTM"].values[0] == avail["FTM"].mean()  # ftm is correct
    assert mean_player["FTA"].values[0] == avail["FTA"].mean()  # fta is correct
    assert mean_player["REB"].values[0] == avail["REB"].mean()  # reb is correct
    assert mean_player["AST"].values[0] == avail["AST"].mean()  # ast is correct
    assert mean_player["STL"].values[0] == avail["STL"].mean()  # stl is correct
    assert mean_player["BLK"].values[0] == avail["BLK"].mean()  # blk is correct
    assert mean_player["TOV"].values[0] == avail["TOV"].mean()  # tov is correct
    assert mean_player["PTS"].values[0] == avail["PTS"].mean()  # pts is correct
Esempio n. 3
0
def test_draft_player_to_mean_player_roster():
    avail = df.copy()
    mean_player = sfb.mean_player(avail)
    player_name = "Stephen Curry"
    new_roster = sfb.draft_player(player_name, mean_player, avail)
    assert (
        len(avail.values) == len(df.values) - 1
    )  # size of available players decreases by 1
    assert (
        sfb.find_player(player_name, avail).empty == True
    )  # drafted player no longer available
    assert len(new_roster.values) == 1  # new roster has exactly one player in it
    assert (
        new_roster["Player"].values[0] == player_name
    )  # that player is the one that was drafted
    assert (
        sfb.find_player("Mr Mean", new_roster).empty == True
    )  # mean player no longer on roster
Esempio n. 4
0
import stat_funcs_basics as sfb
import stat_funcs_net as sfn
import stat_funcs_z as sfz
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors
from matplotlib.ticker import PercentFormatter

# Generate z score data
df = pd.read_csv("data/espn_data_set.csv")
roster = sfb.mean_player(df)
net_change_table = sfn.generate_net_change_table(roster, df)
z_score_table = sfz.generate_z_score_table(net_change_table)

# Select data parameter & print table
stat_str = "Z_AVG"
z_score_table.sort_values(by=[stat_str], ascending=False, inplace=True)
# z_score_table.to_csv("data/z_score_table.csv", index=False)
print(net_change_table)
print(z_score_table)


for stat_str in z_score_table:
    # Create matplotlib histogram
    if stat_str == "Player":
        continue
    z_avg_array = z_score_table[stat_str].to_numpy()
    num_bins = 25
    n, bins, patches = plt.hist(z_avg_array, num_bins)
    ax = plt.gca()
Esempio n. 5
0
 def __init__(self, owner_name, team_name, df):
     self.owner_name = owner_name
     self.team_name = team_name
     self.roster = sfb.mean_player(df)