Ejemplo n.º 1
0
    def rate_for_games(self, stacked, unstacked):
        """

        :param games:
        :return:
        """
        self.teams = util.get_teams(unstacked)
        self._initialize(self.teams)
        cols = {name: idx for idx, name in enumerate(stacked.columns)}
        for k, row in enumerate(stacked.values):
            hteam_id = row[cols['hteam_id']]
            ateam_id = row[cols['ateam_id']]

            # update winning percentages for teams that don't exist in database
            if np.isnan(row[cols['hteam_id']]) or np.isnan(row[cols['ateam_id']]):
                if not self.ignore_nan_teams:
                    self.update_wp(self.team_index[hteam_id], self.team_index[ateam_id])
                continue
            i, j = self.team_index[hteam_id], self.team_index[ateam_id]

            self.update_wins(i, j, row[cols['home_outcome']], row[cols['neutral']])
            self.update_played(i, j, row[cols['neutral']])
Ejemplo n.º 2
0
            ['UConn', 82, 'Duke', 68],
            ['Minnesota', 71, 'UConn', 72],
            ['Kansas',	69,	'UConn', 62],
            ['Duke', 81, 'Minnesota', 70],
            ['Minnesota', 52, 'Kansas', 62]]
    df = pd.DataFrame(data, columns=['hteam', 'hscore', 'ateam', 'ascore'])
    df['home_outcome'] = df.hscore > df.ascore
    df['neutral'] = False
    df['hteam_id'] = df.hteam.map(lambda x: team_ids.get(x))
    df['ateam_id'] = df.ateam.map(lambda x: team_ids.get(x))
    return df

if __name__ == "__main__":
    # df = rpi_test_data()
    games = util.get_games(date(2015, 3, 15))
    d1 = pd.read_sql("SELECT * FROM division_one WHERE year=2015", DB.conn)
    games = games.merge(d1, left_on='hteam_id', right_on='ncaaid')
    games = games.merge(d1, left_on='ateam_id', right_on='ncaaid')
    teams = util.get_teams(games)
    data = games[['hteam_id', 'ateam_id', 'home_outcome', 'neutral']].values
    agg = RPIAggregator(teams)
    map(lambda x: agg.update(x), data)
    ratings = agg.evaluate()
    teams['rpi'] = ratings[0]
    teams['sos'] = ratings[1]
    teams['w'] = agg.total_won
    teams['l'] = agg.total_played - agg.total_won
    all_teams = pd.read_sql("SELECT ncaa, ncaaid FROM teams", DB.conn)
    df = teams.merge(all_teams, left_on="team_id", right_on="ncaaid")

Ejemplo n.º 3
0
import csv
import player
import util
from operator import itemgetter

# import read_schedule

path = "../excel/BBM_PlayerRankings"
'''
get zscores
'''
path = "../excel/players.csv"

teams_abbrevs = util.get_teams()
players = []
names = set()
'''
Returns a list of players specified by a list of names
'''


def find_players(names):
    with open(path, "rb") as f:
        reader = csv.reader(f, delimiter="\t")
        for i, line in enumerate(reader):
            line = line[0]
            number, name, position, age, team, games, games_started, minutes, fgm, \
                fga, fgp, threepm, threepa, threepp, twopm, twopa, twopp, \
                effective_fgp, ftm, fta, ftp, oreb, drb, trb, ast, stl, blk, tov, \
            pf, pts = line.split(',')