def create_track(self, tournament, gender): """Creates a new track for a given tournament and gender. Starts off with an empty scoreboard and mappings for the player stats. :param tournament: The tournament to create the track for. :param gender: The gender of the track to create. :return: The newly created track. """ stats = HashTable() for player_name, player_profile in self.circuit.get_players(gender): season_stats: SeasonStats = self.get_stats(gender).find( player_name) tournament_stats = TournamentStats(player_profile, season_stats) season_stats.tournament_stats.insert(tournament.type.name, tournament_stats) stats.insert(player_name, tournament_stats) winning_score = get_winning_score(gender) forfeit_score = get_forfeit_score(gender) previous_stats = None previous_season_scoreboard = None if tournament.previous is not None: previous_stats = tournament.previous.get_track(gender).stats previous_season_scoreboard = tournament.previous.season.get_scoreboard( gender) track_round = 1 remaining = stats.clone() scoreboard = List() return Track(gender, track_round, stats, remaining, winning_score, forfeit_score, scoreboard, previous_stats, previous_season_scoreboard)
def load_track(tournament, gender, track_round): """Loads a track from file. :param tournament: The tournament this track is part of. :param gender: The gender of players on this track. :param track_round: The round the track is starting from. :return: The track loaded from file. """ stats = HashTable() remaining = HashTable() sorter = Sorter(lambda a, b: b.round_achieved - a.round_achieved) with open('%s/%s/%s/%s.csv' % (OUTPUT, tournament.season.name, tournament.type.name, gender)) as the_file: for line in the_file: # Parse player stats. csv = parse_csv_line(line) player_name = csv[0] round_achieved = int(csv[1]) multiplier = float(csv[2]) points = float(csv[3]) wins = int(csv[4]) losses = int(csv[5]) scores = load_scores(csv[6]) opponent_scores = List() for score in csv[7:]: opponent_scores.append(int(score)) # Create the players' tournament stats profile. season_stats: SeasonStats = tournament.season.get_stats( gender).find(player_name) tournament_stats = TournamentStats(season_stats.player, season_stats, round_achieved, multiplier, points, wins, losses, scores, opponent_scores) tournament_stats.season.tournament_stats.insert( tournament.type.name, tournament_stats) # Add this profile to the tournament players. stats.insert(player_name, tournament_stats) if not tournament.complete and track_round <= round_achieved: remaining.insert(player_name, tournament_stats) if tournament.complete or track_round > round_achieved: sorter.consume(tournament_stats) scoreboard = sorter.sort() if not tournament.complete: linked_scoreboard = List() for stats in scoreboard: linked_scoreboard.append(stats) scoreboard = linked_scoreboard winning_score = get_winning_score(gender) forfeit_score = get_forfeit_score(gender) previous_stats = None previous_season_scoreboard = None if tournament.previous is not None: previous_stats = tournament.previous.get_track(gender).stats previous_season_scoreboard = tournament.previous.season.get_scoreboard( gender) return Track(gender, track_round, stats, remaining, winning_score, forfeit_score, scoreboard, previous_stats, previous_season_scoreboard)