示例#1
0
def getTeamTimeDist(id, homeOrAway):
    team = teams.getTeamById(id) if type(id) == int else teams.getTeamByName(id)
    teamPos= possessions[(possessions['off'] == team['id'])]
    if homeOrAway is not None:
        validGames = [int(game[1]['gameId']) for game in games.iterrows() if game[1][homeOrAway] == team['id']]
        teamPos = pd.DataFrame([p[1] for p in teamPos.iterrows() if p[1]['gameId'] in validGames])
    tm = teamPos['dur'].values
    mean = sum(tm)/len(tm)
    textstr = "mean="+str(round(mean, 2))
    return s.weibull_min.fit(tm, floc=0)
示例#2
0
def getTeamTrans(id, offenseOrDefense, homeOrAway):
    #get transitional matrix for a team, filter by offensive or defensive possessions
    global ends
    team = teams.getTeamById(id) if type(id) == int else teams.getTeamByName(id)
    thisTeam = possessions[possessions[offenseOrDefense] == team['id']]
    if homeOrAway is not None:
        validGames = [int(game[1]['gameId']) for game in games.iterrows() if game[1][homeOrAway] == team['id']]
        thisTeam = pd.DataFrame([p[1] for p in thisTeam.iterrows() if p[1]['gameId'] in validGames])
    ends = np.zeros(shape=(10,10))
    thisTeam.apply(getTransMatrix, axis=1)
    ends = (ends/ends.sum())*100
    return ends
示例#3
0
def getTeamTimeDist(id, homeOrAway):
    team = teams.getTeamById(id) if type(id) == int else teams.getTeamByName(
        id)
    teamPos = possessions[(possessions['off'] == team['id'])]
    if homeOrAway is not None:
        validGames = [
            int(game[1]['gameId']) for game in games.iterrows()
            if game[1][homeOrAway] == team['id']
        ]
        teamPos = pd.DataFrame(
            [p[1] for p in teamPos.iterrows() if p[1]['gameId'] in validGames])
    tm = teamPos['dur'].values
    mean = sum(tm) / len(tm)
    textstr = "mean=" + str(round(mean, 2))
    return s.weibull_min.fit(tm, floc=0)
示例#4
0
def getTeamTrans(id, offenseOrDefense, homeOrAway):
    #get transitional matrix for a team, filter by offensive or defensive possessions
    global ends
    team = teams.getTeamById(id) if type(id) == int else teams.getTeamByName(
        id)
    thisTeam = possessions[possessions[offenseOrDefense] == team['id']]
    if homeOrAway is not None:
        validGames = [
            int(game[1]['gameId']) for game in games.iterrows()
            if game[1][homeOrAway] == team['id']
        ]
        thisTeam = pd.DataFrame([
            p[1] for p in thisTeam.iterrows() if p[1]['gameId'] in validGames
        ])
    ends = np.zeros(shape=(10, 10))
    thisTeam.apply(getTransMatrix, axis=1)
    ends = (ends / ends.sum()) * 100
    return ends