import csv from statistics import mean rankings_file = '/home/connor/documents/rankings.csv' matchups_file = '/home/connor/documents/matchups.csv' # First round modified to measure expectations better r1_seeds = [[1,28], [8,9], [5, 12], [4,16], [6,11], [3,18], [7,10], [2,24]] r2_seeds = [[1,8], [5,4], [6,3], [7,2]] r3_seeds = [[1,4], [3,2]] r4_seeds = [[1,4], [3,2]] r5_seeds = [[1,4], [3,2]] r6_seeds = [[1,2]] systems = ['LEF', 'DOK', 'INC', 'LMC', 'TPR'] r2_matchups = [] r3_matchups = [] r4_matchups = [] r5_matchups = [] r6_matchups = [] def pick_winners(matchups, seeds, multiplier): j = 0 winners = [] out_matchups = [] for matchup in matchups: if matchup != []: expected_ranks = [ multiplier*seed for seed in seeds[j%len(seeds)] ] matchup_rankings = [rankings[teams.index(matchup[0])], rankings[teams.index(matchup[1])]] for k in range(2): if expected_ranks[k] > 10: if matchup_rankings[k] < 0.75*expected_ranks[k]: matchup_rankings[k] *= 0.6 elif matchup_rankings[k] < expected_ranks[k]: matchup_rankings[k] *= 0.9 elif matchup_rankings[k] > 1.5*expected_ranks[k]: matchup_rankings[k] *= 2.0 elif matchup_rankings[k] > expected_ranks[k]: matchup_rankings[k] *= 1.1 if matchup_rankings[0] >= matchup_rankings[1]: winner = matchup[1] else: winner = matchup[0] winners.append(winner) j += 1 for i in range(0,len(winners), 2): out_matchups.append([ winners[i], winners[i+1] ]) return winners, out_matchups def convert_float(string): if string.strip() == '': return 400 else: return float(string) with open(rankings_file, newline='\n') as rankings_csv: reader = csv.reader(rankings_csv, delimiter=',', quotechar='"') i = 1 teams = [] rankings = [] for team in reader: if i == 1: sys_entries = [ sys.strip() for sys in team ] sys_indices = [] for system in systems: sys_indices.append(sys_entries.index(system)) if i != 1: rankings.append(mean([ convert_float(team[sys_index]) for sys_index in sys_indices ])) teams.append(team[0].strip()) i += 1 with open(matchups_file, newline='\n') as matchups_csv: reader = csv.reader(matchups_csv, delimiter=',', quotechar='"') r2_teams, r2_matchups = pick_winners(reader, r1_seeds, 4) r3_teams, r3_matchups = pick_winners(r2_matchups, r2_seeds, 4) r4_teams, r4_matchups = pick_winners(r3_matchups, r3_seeds, 4) r5_teams, r5_matchups = pick_winners(r4_matchups, r4_seeds, 2) r6_teams, r6_matchups = pick_winners(r5_matchups, r5_seeds, 1) print(r2_teams) print(r3_teams) print(r4_teams) print(r5_teams) print(r6_teams) final_matchup_rankings = [rankings[teams.index(r6_matchups[0][0])], rankings[teams.index(r6_matchups[0][1])]] if final_matchup_rankings[0] >= final_matchup_rankings[1]: winner = r6_matchups[0][1] else: winner = r6_matchups[0][0] print(winner)