def test_sort_roster(rosters: List[Roster], first): for roster in rosters: roster.wl_points = Roster.calculate_wl_points(roster) rosters = Roster.sort(rosters) assert rosters[0].name == first
def update_record(roster: Roster, up_to_week: int, schedule: Schedule, league_start_week: int): wins = 0 losses = 0 ties = 0 total_score_for = 0.0 total_score_against = 0.0 last_result = "-" for week in schedule.weeks: if week.week_number < league_start_week: continue if week.week_number > up_to_week or week.week_type != WeekType.REGULAR: break matchup = next(m for m in week.matchups if m.away and m.away.id == roster.id or m.home and m.home.id == roster.id) if matchup: score_for = matchup.away_score if matchup.away and matchup.away.id == roster.id else matchup.home_score score_against = matchup.home_score if matchup.away and matchup.away.id == roster.id else matchup.away_score total_score_for += score_for total_score_against += score_for won = score_for > score_against lost = score_for < score_against tied = score_for == score_against if won: wins += 1 last_result = "W" if lost: losses += 1 last_result = "L" if tied: ties += 1 last_result = "T" roster.wins = wins roster.losses = losses roster.ties = ties roster.record = Roster.format_record(roster) roster.wl_points = Roster.calculate_wl_points(roster) roster.last_week_result = last_result roster.points_for = total_score_for roster.points_against = total_score_against