Beispiel #1
0
    for game in team.games:
        p_win = calculate_game_probability(
            rating, game.difficulty(location_adjustment))
        if game.result == "W":
            p = p * p_win
        elif game.result == "L":
            p = p * (1.0 - p_win)
        else:
            raise "Unexpected result %s" % game.result
    return p


### GET INPUT DATA ###
# Create team objects
team_list_source = "%s/constants/names.txt" % ROOT_PATH
teams = Team.build_teams_from_file(team_list_source)

records_source = "%s/output/standings-week%s.csv" % (ROOT_PATH, CURRENT_WEEK)
with open(records_source) as f:
    for line in f:
        name, record = line.strip().split(",")
        name = translate_ncaa_name(name)
        teams[name].record = record

# Create game objects
schedule_root = '%s/output/football/schedules/' % ROOT_PATH
idx = 0
for name, team in teams.items():
    team.id = idx
    idx += 1
    filename_format_name = build_filename_format(name)
                                                           CURRENT_WEEK)
sources['performance'] = '%s/output/performance-ratings-week%s.csv' % (
    root_path, CURRENT_WEEK)
sources['names'] = '%s/constants/names.txt' % root_path
sources['last_week'] = '%s/output/results-week%s.csv' % (root_path,
                                                         CURRENT_WEEK - 1)
sources['conferences'] = '%s/constants/conferences.txt' % root_path
sources['records'] = '%s/output/standings-week%s.csv' % (root_path,
                                                         CURRENT_WEEK)

data = {}
for key, sourcefile in sources.items():
    with open(sourcefile) as f:
        data[key] = list(f)

teams = Team.build_teams_from_file(sources['names'])
conference_flairs = build_conference_flairs(data['conferences'])
dropped_out = Team.set_last_week(data['last_week'], teams)

for data_line in data['power']:
    raw_data = read_power_line(data_line)
    team = process_power_name(raw_data['name'])
    if team in POWER_NAMES:
        team = POWER_NAMES[team]
    teams[team].set_power_mean(raw_data['mean'])

for data_line in data['performance']:
    raw_data = read_performance_line(data_line)
    raw_name = raw_data['name']
    if raw_name in PERFORMANCE_NAMES:
        name = PERFORMANCE_NAMES[raw_name]