def getMatchesEvent(year, event): matches = [] event_time = getEventTime(event) for match in read_tba.get("event/" + str(event) + "/matches/simple"): # correctly orders matches pre 2016 match["actual_time"] = getMatchTime(match, event_time) red_teams = len(match["alliances"]["red"]["team_keys"]) blue_teams = len(match["alliances"]["blue"]["team_keys"]) if (year > 2004 and red_teams == 3 and blue_teams == 3): matches.append(Match(match)) elif (year <= 2004 and red_teams >= 2 and blue_teams >= 2): matches.append(Match(match)) matches.sort() return matches
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Our Round Data should be completely empty round_data = {} # Generate our rounds for gender in players: # Generate 'x' amount of rounds for r in range(season.settings()['round_count']): # Default Values round_name = "round_" + str(r) round_cap = 3 # Create our gendered rounds if (not gender in round_data): # Do we have a Round Cap overrider for this gender? if (gender + "_cap" in season.settings()): roundCap = season.settings()[gender + "_cap"] # Update our round data round_data.update({round_name: {gender: []}}) # Create our match data from players rand_players = random.sample(players[gender], len(players[gender])) for i in range(int(len(rand_players) / 2)): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if (who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match #round_data[gender].append({ p_one.name(): p_one_score, p_two.name(): p_two_score }) round_data[round_name][gender].append( Match.Match(round_name, p_one, p_two, p_one_score, p_two_score)) # Set our Round Data to our season season.set_rounds_raw(round_data) # Debug if (self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format( season.name(), season.settings()['round_count'])) print(len(season.rounds()["male"])) for match in season.rounds()["male"]: print(match.versuses())
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if (gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Create our first round _round_one = Round.Round(self.app, gender, "round_1") _round_one.set_cap(round_cap) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if (who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match #round_data[gender].append({ p_one.name(): p_one_score, p_two.name(): p_two_score }) #round_data[round_name][gender].append(Match.Match(round_name, p_one, p_two, p_one_score, p_two_score)) _round_one.add_match( Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Get the winners from each round for r in range(2, season.settings()['round_count'] + 1): # Define variables round_name = "round_" + str(r) print(round_name) # Debug if (self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format( season.name(), season.settings()['round_count']))
def parse_file(file_name): with open(file_name, 'r') as f: info = yaml.load(f) try: if info["info"]["gender"] != "male": return False team1 = info["info"]["teams"][0] team2 = info["info"]["teams"][1] if info["info"]["toss"]["decision"] == "bat" : if team1 == info["info"]["toss"]["winner"] : match = Match(team1, team2) else : match = Match(team2, team1) else : if team2 == info["info"]["toss"]["winner"] : match = Match(team1, team2) else : match = Match(team2, team1) if "result" in info["info"]["outcome"] and info["info"]["outcome"]["result"] in ["no result", "tie"]: return False if "winner" not in info["info"]["outcome"] : winner = -1 else : winner = info["info"]["outcome"]["winner"] if team1 not in teams : teams[team1] = Team(team1, 0, 0, 0, 0, 0, 0) if team2 not in teams : teams[team2] = Team(team2, 0, 0, 0, 0, 0, 0) teams[team1].matches += 1 teams[team2].matches += 1 if winner != -1: teams[winner].wins += 1 else : teams[team1].wins += 0.5 teams[team2].wins += 0.5 deliveries = info["innings"][0]["1st innings"]["deliveries"] + info["innings"][1]["2nd innings"]["deliveries"] if (info["innings"][0]["1st innings"]["team"] == team1) : match = process_deliveries(info["innings"][0]["1st innings"]["deliveries"], team1, team2, 1, match) match = process_deliveries(info["innings"][1]["2nd innings"]["deliveries"], team2, team1, 2, match) else : match = process_deliveries(info["innings"][0]["1st innings"]["deliveries"], team2, team1, 1, match) match = process_deliveries(info["innings"][1]["2nd innings"]["deliveries"], team1, team2, 2, match) if info["info"]["outcome"]["winner"] == match.team_1 : match.outcome = 1 else : match.outcome = 0 match.normalize() matches.append(match) except Exception as e: print("Error: ", e) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season season.add_round(gender, _r) # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count']))
def generate_matches(players, max_matches = 10): """Changes player state """ matches = [] for _ in range(max_matches): match_raw = generate_a_match(players) for player in match_raw: player.matches_assigned += 1 #STATE CHANGE ALERT match = Match(match_raw) matches.append(match) return matches
async def veto(self, ctx: cmds.Context, team1: Union[Role, Member, Team], team2: Union[Role, Member, Team], gametype='2v2', bestof=3): """Start a veto between two teams.""" teams = [] for i, team in enumerate([team1, team2]): if not isinstance(team, Team): teams.append(Team(team)) else: teams.append(team) veto_menu = menus.VetoMenu(self.bot, Match(teams[0], teams[1], gametype, bestof)) await veto_menu.run(ctx) await get5.commands.generate_config(veto_menu.match) await self.startmatch(ctx)
def generate_round(self, seasonId, tournamentName, roundId, genderName): # Get our Season Object season = self.get_season(seasonId) players = season.players() # Ensure we have a valid Season object if(season == None): return print("Invalid Season ID: {}".format(seasonId)) # Get our Tournament Object tournament = season.tournament(tournamentName) # Ensure we have a valid Tournament object if(tournament == None): return print("Invalid Tournament Name: {}".format(tournamentName)) # Ensure we have valid round data previous_round = tournament.round(genderName, "round_{}".format(roundId - 1)) if(previous_round == None and not (roundId - 1) == 0): return print("You can only generate this round when the rounds before Round {0} for {1}, {2} have been generated or manually inputed.".format(roundId, genderName.title(), tournamentName)) # Start Generation of Round if(previous_round == None): rand_players = random.sample(players[genderName], len(players[genderName])) else: rand_players = random.sample(previous_round.winners(), len(previous_round.winners())) # Check if this round has some data this_round = tournament.round(genderName, "round_{}".format(roundId)) if(this_round != None): # Clean up our rand_players array with matches that may exist for p in this_round.players(): if(p in rand_players): del rand_players[rand_players.index(p)] # Check if we have a round to take data from match_cap = (len(rand_players) // 2) if (previous_round == None) else (len(previous_round.winners()) // 2) # Generate our matches from the data we have round_cap = 3 if(genderName + "_cap" in season.settings()): round_cap = season.settings()[genderName + "_cap"] # Check if our round already exists _r = None if(this_round == None): _r = Round.Round(self.app, genderName, "round_{0}".format(roundId), tournament, match_cap) else: _r = this_round # Set our round attributes _r.set_previous_round(previous_round) _r.set_cap(round_cap) for w in range(len(rand_players) // 2): # Define our players p_one = rand_players[w * 2] p_two = rand_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to the tournament tournament.add_round(genderName, _r) # Save Data self.handle_save_rounds(tournament) return True
def input_round(self, seasonId, tournamentName, roundId, genderName): # Get our Season Object season = self.get_season(seasonId) players = None # Get our Tournament Object tournament = season.tournament(tournamentName) # Ensure we have a valid Tournament object if(tournament == None): return print("Invalid Tournament Name: {}".format(tournamentName)) # Ensure we have valid round data previous_round = tournament.round(genderName, "round_{}".format(roundId - 1)) if(previous_round == None and not (roundId - 1) == 0): return print("You can only generate this round when the rounds before Round {0} for {1}, {2} have been generated or manually inputed.".format(roundId, genderName.title(), tournamentName)) # Get the available players for this particular Round if(previous_round == None): players = season.players()[genderName] else: players = previous_round.winners() # Lets loop until all of our players have been used up available_players = players.copy() # Check if this round has some data this_round = tournament.round(genderName, "round_{}".format(roundId)) if(this_round != None): # Clean up our available_players array with matches that may exist for p in this_round.players(): if(p in available_players): del available_players[available_players.index(p)] # Get our input try: tryAgain = False tryAgainError = "" # Get our caps match_cap = (len(available_players) // 2) if (previous_round == None) else (len(previous_round.winners()) // 2) # Round Cap round_cap = 3 if(genderName + "_cap" in season.settings()): round_cap = season.settings()[genderName + "_cap"] # Check if our round already exists _r = None if(this_round == None): _r = Round.Round(self.app, genderName, "round_{0}".format(roundId), tournament, match_cap) else: _r = this_round # Update Round details _r.set_previous_round(previous_round) _r.set_cap(round_cap) # Add our round to the tournament tournament.add_round(genderName, _r) while(len(available_players) != 0): # Clear the Terminal call("cls") # Print out our available players print("Available Players for input on Round {0}:\n{1}".format(roundId, ", ".join([ p.name() for p in available_players ]))) # Handle Error if(tryAgain): print("\nError:\n{0}\n".format(tryAgainError)) tryAgain = False # Match Specific Variables winnerCount = 0 plyr_one = input("Please enter Player A: ") if(plyr_one in [ p.name() for p in available_players ]): plyr_one_score = input("Please enter the score for Player A: ") if(plyr_one_score.isdigit() and int(plyr_one_score) <= _r.cap()): # Type Conversion plyr_one_score = int(plyr_one_score) # Increment our Winner Count if(plyr_one_score == _r.cap()): winnerCount += 1 # Player B plyr_two = input("Please enter Player B: ") if(plyr_two in [ p.name() for p in available_players ] and plyr_two != plyr_one): plyr_two_score = input("Please enter the score for Player B: ") if(plyr_two_score.isdigit() and int(plyr_two_score) <= _r.cap()): # Type Conversion plyr_two_score = int(plyr_two_score) # Increment our Winner Count if(plyr_two_score == _r.cap()): winnerCount += 1 # Ensure we have one winner if(winnerCount == 1): # Get Player Objects p_one = next(( p for p in available_players if(p.name() == plyr_one)), None) p_two = next(( p for p in available_players if(p.name() == plyr_two)), None) # Ensure our Player's exist if(p_one and p_two): # Add this Match to the Round _m = Match.Match(_r, p_one, p_two, plyr_one_score, plyr_two_score) _r.add_match(_m) # Pop our players from the array del available_players[available_players.index(p_one)] del available_players[available_players.index(p_two)] # Save this match straight away self.handle_save_rounds(tournament) # Hold User input("Match ({0}) successfully added. Press <Return> to continue...\n".format(_m.versuses(True))) else: # Try Again tryAgainError = "The Players seize to exist within the available player list." tryAgain = True else: # Try Again tryAgainError = "A winner was not elected for this Match." if (winnerCount == 0) else "Matches cannot be left as a draw - only one player can win." tryAgain = True else: # Try Again tryAgainError = "The score entered for Player B ({0}) is invalid.".format(plyr_two_score) tryAgain = True else: # Try Again tryAgainError = "The player you entered ({0}) does not exist.".format(plyr_two) if plyr_two != plyr_one else "Player B cannot be the same as Player A." tryAgain = True continue else: # Try Again tryAgainError = "The score entered for Player A ({0}) is invalid.".format(plyr_one_score) tryAgain = True continue else: # Try Again tryAgainError = "The player you entered ({0}) does not exist.".format(plyr_one) tryAgain = True continue # Finalise the save to our tournament self.handle_save_rounds(tournament) except KeyboardInterrupt: # Clear Terminal call("cls") # Show user what happens when they restart print("You have tried to exit the program using Ctrl + C whilst inputting matches.", "\n") print("If you load previous rounds in your next session, you will be able to continue") print("from where you left off from this session.") # Exit Program Builder._app.exit() except Exception as err: # Clear Terminal call("cls") # Show user error print("An unknown error has occured:\n{0}".format(err)) traceback.print_exc() # Exit Program Builder._app.exit() return True
def generate_rounds(self, seasonId, minRoundId, maxRoundId): # Write our new data to memory season = self.get_season(seasonId) players = season.players() # For each tournament, generate rounds for tournament_name in season.tournaments(): # Get our tournament object tournament = season.tournament(tournament_name) # Generate our rounds for gender in players: for r in range(0, season.settings()["{}_round_count".format(gender)]): # Define Round Variables r_name = "round_" + str(r + 1) # Make sure we're not generating over our requested generation amount if (r < minRoundId): continue elif (r >= maxRoundId): break else: pass # Default Values round_cap = 3 # Data to Check prev_r = tournament.round(gender, "round_" + str(r)) # Check if we have a round to take data from match_cap = (len(players[gender]) // 2) if (prev_r == None) else (len(prev_r.winners()) // 2) # Do we have a Round Cap overrider for this gender? round_cap = 3 if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] _r = Round.Round(self.app, gender, r_name, tournament, match_cap) _r.set_cap(round_cap) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) _r.set_previous_round(prev_r) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season tournament.add_round(gender, _r) # Debug if(self.app.debug): print("{} --- Round Added: [{}]".format([ w.name() for w in _r.winners() ], r_name)) # Import our data into JSON format for saving reference for g in tournament.rounds(): for r_id, r in enumerate(tournament.rounds()[g], 1): # Make sure our round exists within the raw data if(not "round_{0}".format(r_id) in tournament._rounds_raw): tournament._rounds_raw.update({ "round_{0}".format(r_id): { } }) # Make sure our gender exists within the raw data if(not g in tournament._rounds_raw["round_{0}".format(r_id)]): tournament._rounds_raw["round_{0}".format(r_id)].update({ g: [ ] }) # Insert our data tournament._rounds_raw["round_{0}".format(r_id)][g] = [ { m.player_one()[0].name(): m.player_one()[1], m.player_two()[0].name(): m.player_two()[1] } for m in tournament.round(g, r).matches() ] # Save Tournament Rounds (if enabled) if(tournament.file_saving()): tournament.save_rounds() # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}', minRound: {2}, maxRound: {3}".format(season.name(), season.settings()['round_count'], minRoundId, maxRoundId))
def load_previous_rounds(self, seasonId): # Get our Season Object season = self.get_season(seasonId) players = season.players() raw_json = season._j_data # Check that we have tournament data if(not "tournaments" in raw_json): raise("There are no tournaments within 'seasons.json'") # Check if the season has previous round data (through raw JSON) for tournament_name in raw_json['tournaments']: # Get our Tournament Object tournament = season.tournament(tournament_name) r_error_found = False error_found = False prev_round = { } # Check our rounds stored within the JSON data if("rounds" in raw_json['tournaments'][tournament_name]): # Load data in for rnd in raw_json['tournaments'][tournament_name]['rounds']: r_path = raw_json['tournaments'][tournament_name]['rounds'][rnd] for gdr in r_path: # Check if we had a previous round if(gdr not in prev_round): prev_round.update({ gdr: None }) rg_path = r_path[gdr] # Check if we have a round to take data from match_cap = (len(players[gdr]) // 2) if (prev_round[gdr] == None) else (len(prev_round[gdr].winners()) // 2) # Create our Round round_cap = 3 if(gdr + "_cap" in season.settings()): round_cap = season.settings()[gdr + "_cap"] _r = Round.Round(self.app, gdr, rnd, tournament, match_cap) _r.set_previous_round(prev_round[gdr]) _r.set_cap(round_cap) tournament.add_round(gdr, _r) # Add our Matches for match in rg_path: plyr_one = None plyr_two = None for i, plyr in enumerate(match, 0): if(i == 0): plyr_one = [plyr, match[plyr]] elif(i == 1): plyr_two = [plyr, match[plyr]] else: break # Setup our Match _m = Match.Match(_r, season.player(gdr, plyr_one[0]), season.player(gdr, plyr_two[0]), plyr_one[1], plyr_two[1]) # Check if errors occurred, if they have - we want to update our file to fix these issues m_error = True if _m.validate() > 0 else False if(m_error): error_found = True # Add our Match and Players to our round _r.add_match(_m) # Check if errors occurred, if they have - we want to update our file to fix these issues r_error = True if _r.validate() > 0 else False if(r_error): r_error_found = True # Set our previous round if(gdr in prev_round): prev_round[gdr] = _r # If errors have occurred, update file with fixes if(error_found or r_error_found): self.handle_save_rounds(tournament) # Update Raw Rounds tournament.update_rounds_raw()
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if (gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from rnd_players = [] if (prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if (who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match( Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season print(len(season.add_round(gender, _r).winners())) #TODO: remove break break """# Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Create our first round _round_one = Round.Round(self.app, gender, "round_1") _round_one.set_cap(round_cap) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round_one.add_match(Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Get the winners from each round for r in range(2, season.settings()['round_count'] + 1): # Define variables round_name = "round_"+str(r) # Define our Round _round = Round.Round(self.app, gender, round_name) # Get our winners from the previous Round prev_round_name = "round_"+str(r-1) _prev_round = season.round(gender, prev_round_name) _winners = _prev_round.winners() for w in range(len(_winners) // 2): # Grab our versus players p_one = _winners[w * 2] p_two = _winners[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round.add_match(Match.Match(_round, p_one, p_two, p_one_score, p_two_score)) # Add our round to the season season.add_round(gender, _round)""" # Debug if (self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format( season.name(), season.settings()['round_count']))
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: # Default Values round_name = "round_1" round_cap = 3 # Create our gendered rounds if(not gender in season.rounds()): # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): roundCap = season.settings()[gender + "_cap"] # Update our round data season. round_data.update({ round_name: { gender: [ ] } }) # Create our first round _round_one = Round.Round(self.app, gender, round_name) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match #round_data[gender].append({ p_one.name(): p_one_score, p_two.name(): p_two_score }) #round_data[round_name][gender].append(Match.Match(round_name, p_one, p_two, p_one_score, p_two_score)) _round_one.add_match(Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Get the winners from each round for r in range(1, season.settings()['round_count']): winners = season.round(r).winners() rand_players = random.sample(winners, len(winners)) for winner in range(rand_players): print("debug", winner) # Set our Round Data to our season season.set_rounds_raw(round_data) # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count'])) print(len(season.rounds()["male"])) for match in season.rounds()["male"]: print(match.versuses(), match.round())
def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if (gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Create our first round _round_one = Round.Round(self.app, gender, "round_1") _round_one.set_cap(round_cap) # Create our first round data rand_players = random.sample(players[gender], len(players[gender])) for i in range(len(rand_players) // 2): # Grab our versus players p_one = rand_players[i * 2] p_two = rand_players[(i * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if (who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match #round_data[gender].append({ p_one.name(): p_one_score, p_two.name(): p_two_score }) #round_data[round_name][gender].append(Match.Match(round_name, p_one, p_two, p_one_score, p_two_score)) _round_one.add_match( Match.Match(_round_one, p_one, p_two, p_one_score, p_two_score)) # Append our first round to our season season.add_round(gender, _round_one) # Items in Round print("{0} has {1} matches".format(_round_one.name(), _round_one.match_count())) # Get the winners from each round for r in range(2, season.settings()['round_count'] + 1): # Define variables round_name = "round_" + str(r) # Define our Round _round = Round.Round(self.app, gender, round_name) # Get our winners from the previous Round prev_round_name = "round_" + str(r - 1) _prev_round = season.round(gender, prev_round_name) _winners = _prev_round.winners() for w in range(len(_winners) // 2): # Grab our versus players p_one = _winners[w * 2] p_two = _winners[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if (who == 0): p_one_score = round_cap else: p_two_score = round_cap # Append our random data as a Match _round.add_match( Match.Match(_round, p_one, p_two, p_one_score, p_two_score)) print("added: {0} vs {1}".format( p_one.name(), p_two.name())) # Add our round to the season season.add_round(gender, _round) #TODO: Remove break break # Debug if (self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format( season.name(), season.settings()['round_count'])) for rnd in season.rounds()["male"]: print(season.rounds()["male"][rnd].match_count())
def load_tournaments(self): for seasonId in self.seasons: # Get our Season Object season = self.get_season(seasonId) # Grab Tournaments from raw JSON data stored in the Season for tournament_name in season._j_data['tournaments']: tournament_json = season._j_data['tournaments'][tournament_name] # Create our Tournament tournament = Tournament.Tournament(tournament_name) tournament.set_prize_money([money for money in tournament_json if(not "_difficulty" in money)]) season.add_tournament(tourn # Generate our rounds from our player list from scratch def generate_rounds(self): # Write our new data to memory for seasonId in self.get_seasons(): season = self.get_season(seasonId) players = season.players() # Generate our rounds for gender in players: for r in range(0, season.settings()["round_count"]): # Default Values round_cap = 3 # Do we have a Round Cap overrider for this gender? if(gender + "_cap" in season.settings()): round_cap = season.settings()[gender + "_cap"] # Define Round Variables r_id = (r + 1) r_name = "round_" + str(r_id) _r = Round.Round(self.app, gender, r_name) # Data to Check prev_r = season.round(gender, "round_" + str(r)) # Check if we have a round to take data from rnd_players = [ ] if(prev_r == None): rnd_players = random.sample(players[gender], len(players[gender])) else: rnd_players = random.sample(prev_r.winners(), len(prev_r.winners())) # Generate our matches from the data we have for w in range(len(rnd_players) // 2): # Define our players p_one = rnd_players[w * 2] p_two = rnd_players[(w * 2) + 1] # Generate some scores p_one_score = random.randint(0, round_cap - 1) p_two_score = random.randint(0, round_cap - 1) # Make a random player the winner who = random.randint(0, 1) if(who == 0): p_one_score = round_cap else: p_two_score = round_cap # Add the match _r.add_match(Match.Match(_r, p_one, p_two, p_one_score, p_two_score)) # Add our round to our season season.add_round(gender, _r) # Debug if(self.app.debug): print("[LOAD]: Generated {1} rounds for season: '{0}'".format(season.name(), season.settings()['round_count'])) # End of generate_rounds() # Used to load prize money def load_prize_money(self): with open('./data/rankingPoints.json') as tData: data = json.load(tData) # Fallback on a non-existant occurrence if(self.player_count == None): self.player_count = 100 # Make our prize_money a dictionary if(self.prize_money == None): self.prize_money = { } # Set the prize money to the actual rank and points received self.prize_money = [ pts for pts in data for rank in data[pts] ] # We want to set the prize money for all indexes possible via the player self.prize_money += [ 0 ] * ( self.player_count - len(self.prize_money)) # Used to load players from all seasons into memory def load_players(self): # Set our player (in gender) count self.player_count = 0 with open('./data/players.json') as tData: data = json.load(tData) # Players are classed within Seasons for season in data: # If the season does not yet exist, ignore this input if(not season in self.get_seasons()): continue # Players are then stored within Gender classifications for gender in data[season]: if(not gender in self.get_season(season).players()): self.get_season(season).players()[gender] = [ ] # Append our player in the season, within the gender for player in data[season][gender]: #TODO: Change to using Player class self.get_season(season).add_player(player, gender) # Update our player count if(len(self.get_season(season).players()[gender]) > self.player_count): self.player_count = len(self.get_season(season).players()[gender]) def get_seasons(self): return self.seasons def get_season(self, season_id): if(season_id in self.seasons): return self.seasons[season_id] else: return None