예제 #1
0
def add_prev_week_rankings(league, current_week):
    file = constants.league_week_storage_path_template % (current_week - 1, league.id)
    prev_league = unpickle_json_from_file(file)

    if prev_league is not None:
        for team_id in league.teams:
            league.teams[team_id].prev_rank = prev_league.teams[team_id].rank

    return league
예제 #2
0
def extract_pro_data(pro_league, current_week):
    pro_data = unpickle_json_from_file(constants.pro_data_storage_path)
    pro_data = pro_data if pro_data is not None else {}
    # print(pro_data)
    i = 0
    max_pf = -1
    for team_id in pro_league.teams:
        if current_week <= 14:
            if pro_league.teams[team_id].div_rank == 1:
                i += 1
                division_ref = 'div%s' % i
                award = gwjffl.Award('Division Winner')  # TODO: constant
                award.value = 15  # TODO: externalize
                award.team = pro_league.teams[team_id]
                pro_data[division_ref] = award
            if pro_league.teams[team_id].rank == 1:
                award = gwjffl.Award('#1 Overall')  # TODO: constant
                award.value = 10  # TODO: externalize
                award.team = pro_league.teams[team_id]
                pro_data['number_one'] = award
            if pro_league.teams[team_id].points_for > max_pf:
                max_pf = pro_league.teams[team_id].points_for
                if 'regular_season_most_points' not in pro_data:
                    pro_data['regular_season_most_points'] = {}
                award = gwjffl.Award('Most total points')  # TODO: constant
                award.value = 25  # TODO: externalize
                award.team = pro_league.teams[team_id]
                award.points = pro_league.teams[team_id].points_for
                pro_data['regular_season_most_points'] = award
        elif current_week == 17:
            if pro_league.teams[team_id].rank == 1:
                award = gwjffl.Award('1st place')  # TODO: constant
                award.value = 100  # TODO: externalize
                award.team = pro_league.teams[team_id]
                pro_data['first'] = award
            if pro_league.teams[team_id].rank == 2:
                award = gwjffl.Award('2nd place')  # TODO: constant
                award.value = 50  # TODO: externalize
                award.team = pro_league.teams[team_id]
                pro_data['second'] = award
            if pro_league.teams[team_id].rank == 3:
                award = gwjffl.Award('3rd place')  # TODO: constant
                award.value = 25  # TODO: externalize
                award.team = pro_league.teams[team_id]
                pro_data['third'] = award

    if current_week == 17:
        award = gwjffl.Award('Consolation Champ')  # TODO: constant
        award.value = 15  # TODO: externalize
        award.team = get_consolation_winner(pro_league, current_week)
        pro_data['consolation_champ'] = award

    award = gwjffl.Award('Highest single-week team total')
    if current_week <= 14:
        highest_score = 'regular_season_highest_score'  # TODO: constant
        award.value = 10  # TODO: externalize
    else:
        highest_score = 'postseason_highest_score'  # TODO: constant
        award.value = 5  # TODO: externalize
    if pro_data.get(highest_score, None) is None:
        pro_data[highest_score] = award
    for result in pro_league.scores:
        if result.score > pro_data[highest_score].points:
            pro_data[highest_score].points = result.score
            pro_data[highest_score].team = pro_league.teams[result.team_id]
            pro_data[highest_score].week = current_week - 1

    pickle_json_to_file(constants.pro_data_storage_path, pro_data)
    return pro_data