def print_dictionary(player_dictionary): # sorted by number of wins, then by winrate num_columns = 2 teams_dict, blah = cea_team_name_parser.init_dictionary(TEAMS_FILE) sorted_player_dict = sorted( player_dictionary.items(), key=lambda item: ( # teams_dict[item[1].name.lower()], item[1].wins - item[1].losses, len(item[1].games), -1 * (len(item[1].games) - item[1].wins))) for i in range(len(sorted_player_dict)): key = sorted_player_dict[i][0] value = sorted_player_dict[i][1] print("%d : %d %s %s" % (value.wins, value.losses, teams_dict[value.name.lower()] + " " + value.name, value.race))
]) # rename the original to avoid name conflicts and make it clear what's been processed to_rename = "-".join([ week_played, player_teams[0], player_teams[1], player_names[0], player_names[1], player_races[0], player_races[1], map_name ]).replace(" ", "_") + ".SC2Replay" dst = os.path.join(output_directory, to_rename) if src.lower() != dst.lower(): counts['replays processed'] += 1 os.makedirs(output_directory, exist_ok=True) renamed_files[src] = dst else: counts['replays were already processed'] += 1 except: print("Error processing replay: %s" % replay) traceback.print_exc() for key, value in renamed_files.items(): shutil.move(key, value) for count_name, count in sorted(counts.items()): print(count, count_name) # Identify players who are not recognized identify_unknown_players(matchup_dictionary, teams) if __name__ == "__main__": teams, aliases = cea_team_name_parser.init_dictionary(TEAMS_FILE) organize_replays(REPLAY_DIRECTORY, REPLAY_DIRECTORY, teams, aliases)
def make_csv(player_dictionary): teams_dict, nickname_dict = cea_team_name_parser.init_dictionary( TEAMS_FILE) csv_arr = [] headers_arr = [ "Team Name", "Name", "Wins", "Losses", "MMR", "Race", "APM", "Biggest Win (MMR Diff)", "Biggest Loss (MMR Diff)", "Players Defeated (MMR Diff)", "Players Lost To (MMR Diff)" ] with open("cea_season_stats.csv", "w", newline='') as my_csv: csvWriter = csv.writer(my_csv, delimiter=',') csvWriter.writerow(headers_arr) for key, value in player_dictionary.items(): new_entry = [] # Name new_entry.append(teams_dict[value.name.lower()]) new_entry.append(value.name) # Wins new_entry.append(int(value.wins)) # Losses new_entry.append(int(value.losses)) # Rank new_entry.append(value.mmr) # Race new_entry.append(value.race) # APM new_entry.append(int(value.apm)) # Retrieve list of opponents beaten / lost to, with MMR differential. def opponent_func(opponents_list, descending): new_opponents_list = [ opp_nickname for opp_nickname in opponents_list ] new_opponents_list = sorted( new_opponents_list, key=lambda item: (player_dictionary[nickname_dict[item.lower()]].mmr), reverse=descending) new_opponents_list = [ opponent + " ({:+})".format(player_dictionary[ nickname_dict[opponent.lower()]].mmr - value.mmr) for opponent in new_opponents_list ] return new_opponents_list opponents_beaten = opponent_func(value.opponents_beaten, True) opponents_lost_to = opponent_func(value.opponents_lost_to, False) # Biggest win new_entry.append( "" if not opponents_beaten else opponents_beaten[0]) # Biggest loss new_entry.append( "" if not opponents_lost_to else opponents_lost_to[0]) # Opponents beaten / lost to new_entry.append(" ; ".join(opponents_beaten)) new_entry.append(" ; ".join(opponents_lost_to)) csvWriter.writerow(new_entry) csv_arr.append(new_entry) print("Done creating CSV")
opponents_lost_to = opponent_func(value.opponents_lost_to, False) # Biggest win new_entry.append( "" if not opponents_beaten else opponents_beaten[0]) # Biggest loss new_entry.append( "" if not opponents_lost_to else opponents_lost_to[0]) # Opponents beaten / lost to new_entry.append(" ; ".join(opponents_beaten)) new_entry.append(" ; ".join(opponents_lost_to)) csvWriter.writerow(new_entry) csv_arr.append(new_entry) print("Done creating CSV") def print_names(teams_dictionary): for key, value in teams_dictionary.items(): print(key) if __name__ == "__main__": teams_dict, nicknames_dict = cea_team_name_parser.init_dictionary( TEAMS_FILE) print(nicknames_dict) player_dictionary = compile_stats(REPLAY_DIRECTORY, nicknames_dict) make_csv(player_dictionary)
opponents_lost_to = opponent_func(value.opponents_lost_to, False) # Opponents beaten / lost to new_entry.append(" ; ".join(opponents_beaten)) new_entry.append(" ; ".join(opponents_lost_to)) csvWriter.writerow(new_entry) csv_arr.append(new_entry) print("Done creating CSV") if __name__ == "__main__": players = {} extra_games = cea_team_name_parser.init_extra_games(EXTRA_GAMES_FILE) # Instantiate Trueskill trueskill.setup(draw_probability=0) # Iterate seasons descending from oldest to newest for season in reversed(range(len(SEASONS))): #for season in [3]: teams, aliases = cea_team_name_parser.init_dictionary( teams_file(season)) calculate_elo(replay_directory(season), players, teams, aliases, season, extra_games) # Input extra elo for newest season input_extra_elo(players, extra_games, datetime.today(), 0) make_csv(players)