Esempio n. 1
0
def impt_stat():
    '''Iterates through each statistic's BS Object to get the important
       information.

       returns a dictionary
    '''
    
    # dictionary to hold the stat, mean, and standard deviation
    stat_mean_sdev = {}

    # builds then iterates through each stat's BS obj
    for k, v in build_dict('stat_position.txt').items():
        # list to store all important numbers per stat
        ind_stat = []
        
        # creates a BS object per stat
        statistic = soupy(k)

        # position of each important number within BS object list
        x = int(v)
        
        # variables to find the next important number
        y = x + 1
        z = x + 3

        # iterates through BS object to append important num to list
        for s in statistic:
            if x > len(statistic):
                break
            else:
                if k == 'Passes_Intercepted':
                    ind_stat.append(float(statistic[x]))
                    x += z
                else:
                    ind_stat.append(float(statistic[x]))
                    x += y

        # determines mean and standard deviation of each statistic
        stat_mean = round(mean(ind_stat), 3)
        stat_sdev = round(stdev(ind_stat), 3)
    
        # adds stat: (mean, stdev) to the dictionary
        stat_mean_sdev[k] = (stat_mean, stat_sdev)

    return stat_mean_sdev
Esempio n. 2
0
def match_team(teams):
    '''

    '''
    # builds dictionary of variation on team names
    team_var = build_dict('team_variation.txt')
    
    # list to return and list to place hold teams not in team_var
    teams_new = []
    no_list = []
    
    # iterates through teams and team_var
    x = 0

    for t in teams:
        if len(teams) == 128:
            for k, v in team_var.items():
                if t in v:
                    teams_new.append(k)
        else:
            ind = teams.index(t)
            x = 0
            '''if team from teams is appended to no_list, 
            following team is not added to team_var
            '''
            if teams[ind - 1] in no_list:
                continue
            for k, v in team_var.items():     
                if t in v:
                    teams_new.append(k) # adds correct variation of team name to list
                    x = 0
                    break
                elif x == len(team_var) - 1:
                    no_list.append(t)          
                else:
                    x += 1
            
    return teams_new
Esempio n. 3
0
def team_stats():
    '''

    '''
    lower_better = [
                    '3rd_Down_Conversion_Pct_Defense',
                    '4th_Down_Conversion_Pct_Defense',
                    'Blocked_Kicks_Allowed',
                    'Blocked_Punts_Allowed',
                    'First_Downs_Defense',
                    'Fumbles_Lost',
                    'Kickoff_Return_Defense',  
                    'Total_Defense',
                    'Rushing_Defense',
                    'Passing_Yards_Allowed',
                    'Punt_Return_Defense',
                    'Scoring_Defense',
                    'Team_Passing_Efficiency_Defense',
                    'Red_Zone_Defense',
                    'Passes_Had_Intercepted',
                    'Tackles_for_Loss_Allowed',
                    'Sacks_Allowed',
                    'Turnovers_Lost'
                   ]

    # builds then iterates through each stat's BS obj
    for k, v in build_dict('stat_position.txt').items():
        
        # creates a BS object per stat
        stats = soupy(k)
        
        # position of each important number within BS object list
        x = int(v)
        a = 1
        b = 2
        
        # variables to find the next important number
        y = x + 1
        z = x + 3
        c = 6

        # list to hold teams and stats
        team_lst = []
        stat_lst = []

        # iterates through BS object to append important num to list
        for s in stats:
            if x > len(stats):
                break
            elif k == 'Passes_Intercepted':
                team_lst.append(stats[a])
                stat_lst.append(stats[x])
                x += z
                a += z
            else:
                team_lst.append(stats[a])
                stat_lst.append(stats[x])
                x += y
                a += y

        stand_score = z_score(team_lst, stat_lst)

        for key, val in stand_score.items():
            val = float(val)
            if k in lower_better:
                if val < 0:
                    stand_score[key] = abs(val)
                else:
                    stand_score[key] = (val - (val * 2))
            else:
                pass    
        
        yield stand_score