def set_late_round_winner(rnd, result, region): rnd_str = "round%s" % rnd teams = read_from_file('teams') players = read_from_file('players') rounds = read_from_file('rounds') players_and_teams = {} for reg, team_list in teams.items(): players_and_teams = get_players_and_teams_by_team_id( players, rnd_str, team_list, players_and_teams) team_id_1 = getTeamIdByAbbrev(result[0].get("abbrev")) team_id_2 = getTeamIdByAbbrev(result[1].get("abbrev")) found_game = None for game in rounds.get(rnd_str): if game[0] in (team_id_1, team_id_2) and game[1] in (team_id_1, team_id_2): found_game = game break winner, winner_id, fav, spread = get_winner(found_game, players_and_teams) update_tables(winner, rnd + 1, region, winner_id) return { "winner": winner, "round": rnd + 1, "region": region, "winner_id": winner_id }
def set_winner(rnd, region, result): # I have the seed, rnd and region of the teams, that should give me the players if rnd >= 5: return set_late_round_winner(rnd, result, region) rnd_str = "round%s" % rnd teams = read_from_file('teams') players = read_from_file('players') rounds = read_from_file('rounds') team_list = teams.get(region) players_and_teams = get_players_and_teams(players, rnd_str, team_list) # find the game seed1 = result[0].get("seed") seed2 = result[1].get("seed") found_game = None for game in rounds.get(region).get(rnd_str): if game[0] in (seed1, seed2) and game[1] in (seed1, seed2): found_game = game break winner, seed_winner, fav, spread = get_winner(found_game, players_and_teams) if rnd == 4: seed_winner = getTeamBySeed(region, seed_winner)[0] update_tables(winner, rnd + 1, region, seed_winner) return { "winner": winner, "round": rnd + 1, "region": region, "seed": seed_winner }
def update_player_file(player, rnd, team_id): round_str = "round%s" % rnd players = read_from_file('players') players[player][round_str].append(team_id) write_to_file('players', players)
def setscore(rnd, region, seed1, score1, seed2, score2, fav, spread, time_left): round_str = "round%s" % rnd rounds = read_from_file('rounds') if rnd < 5: matchup, slot = get_matchup_and_slot(rnd, seed1) while len(rounds[region][round_str][matchup]) < 7: rounds[region][round_str][matchup].append(None) rounds[region][round_str][matchup][slot + 2] = score1 matchup, slot = get_matchup_and_slot(rnd, seed2) rounds[region][round_str][matchup][slot + 2] = score2 rounds[region][round_str][matchup][4] = fav rounds[region][round_str][matchup][5] = spread rounds[region][round_str][matchup][6] = time_left else: matchup, slot = hacky_hack(seed1, rnd) while len(rounds[round_str][matchup]) < 7: rounds[round_str][matchup].append(None) rounds[round_str][matchup][slot + 2] = score1 matchup, slot = hacky_hack(seed2, rnd) rounds[round_str][matchup][slot + 2] = score2 rounds[round_str][matchup][4] = fav rounds[round_str][matchup][5] = spread rounds[round_str][matchup][6] = time_left write_to_file('rounds', rounds)
def get_later_round(rnd): rnd_str = "round%s" % rnd teams = read_from_file('teams') rounds = read_from_file('rounds') players = read_from_file('players') players_and_teams = {} for region, team_list in teams.items(): players_and_teams = get_players_and_teams_by_team_id( players, rnd_str, team_list, players_and_teams) pairs = [] for game in rounds.get(rnd_str): pairs.append(get_pair(game, players_and_teams)) return jsonify(pairs)
def getTeamIdByAbbrev(abbrev): teams = read_from_file('teams') for key, region in teams.items(): for id, curr_team in region.items(): if curr_team[0] == abbrev: team_id = id break return int(team_id)
def getTeamBySeed(region, seed): teams = read_from_file('teams') teamList = teams.get(region) for id, curr_team in teamList.items(): if curr_team[1] == seed: team_id = id team = curr_team break return int(team_id), team
def update_round_file(region, rnd, seed): round_str = "round%s" % rnd rounds = read_from_file('rounds') if rnd >= 5: matchup, slot = hacky_hack(seed, rnd) rounds[round_str][matchup][slot] = seed else: matchup, slot = get_matchup_and_slot(rnd, seed) rounds[region][round_str][matchup][slot] = seed write_to_file('rounds', rounds)
def get_round(rnd): if rnd >= 5: return get_later_round(rnd) rnd_str = "round%s" % rnd teams = read_from_file('teams') rounds = read_from_file('rounds') players = read_from_file('players') result = {} for region, team_list in teams.items(): players_and_teams = get_players_and_teams(players, rnd_str, team_list) pairs = [] for game in rounds.get(region).get(rnd_str): pairs.append(get_pair(game, players_and_teams)) result[region] = pairs return jsonify(result)
def get_game_score_web(): games = read_from_file("games") updating_games = [] for game_id, game in games.get("games").items(): if game_started(game): result, fav, spread, region, rnd, time_left = get_game_score( game_id) score1 = result[0].get("score") score2 = result[1].get("score") if rnd >= 5: s1 = result[0].get("abbrev") s2 = result[1].get("abbrev") else: s1, score1 = result[0].get("seed"), result[0].get("score") s2, score2 = result[1].get("seed"), result[1].get("score") setscore(rnd, region, s1, score1, s2, score2, fav, spread, time_left) if 'Final' in time_left: set_winner(rnd, region, result) remove_game(game_id) else: updating_games.append(game_id) print(updating_games)
def getTeamById(team_id): teams = read_from_file('teams') for region in teams.items(): if team_id in region: return region.get(team_id)[0]
def remove_game(game_id): games = read_from_file("games") if game_id in games["games"]: games["games"][game_id]["finished"] = True write_to_file("games", games)
def get_players(): players = read_from_file('players') return jsonify(list(players.keys()))
def get_current_round(): games = read_from_file("games") rounds = games.get("rounds") rounds = OrderedDict(sorted(rounds.items())) result = find_current_round(rounds) return jsonify(result)