def test_group_size(self): # 9C9 self.assertEqual( len(main.group([9], ['aldo', 'beat', 'carla', 'david', 'evi', 'flip', 'gary', 'hugo', 'ida'])), 1) # 9C5 * 4C4 self.assertEqual( len(main.group([5, 4], ['aldo', 'beat', 'carla', 'david', 'evi', 'flip', 'gary', 'hugo', 'ida'])), 126) # 9C2 * 7C3 * 4C4 self.assertEqual( len(main.group([2, 3, 4], ['aldo', 'beat', 'carla', 'david', 'evi', 'flip', 'gary', 'hugo', 'ida'])), 1260)
def test_simple_message(self): message = """23/01/2022, 13:16 - Vicky: Wordle 218 3/6 ⬛⬛⬛⬛⬛ 🟨🟩🟩🟨⬛ 🟩🟩🟩🟩🟩 """ grouped = group(lines) self.assertEqual(message, grouped)
def test_transcodeToALL_chord(self, mock_chord): self.app.post('/transcodeALL') transcoding_tasks = main.group( main.transcode_1080p.signature(queue='tasks', priority=1, immutable=True), main.transcode_720p.signature(queue='tasks', priority=2, immutable=True), main.transcode_480p.signature(queue='tasks', priority=3, immutable=True), main.transcode_360p.signature(queue='tasks', priority=4, immutable=True) ) # main.end_processing.signature(queue='tasks', immutable=True) -- Not used in chord?! mock_chord.assert_called_once_with(transcoding_tasks)
def getHeadToHeadTable(tourney_id): """returns a table of the player's head to head results. see end of the function for exactly what is returned""" #Load all finished games finishedGames = clot.getFinishedGames(tourney_id) logging.info("finishedGames:") logging.info(finishedGames) #get player_id : name dict players_id_name_dict = clot.getPlayersIDNameDict(tourney_id) logging.info('players_id_name_dict') logging.info(players_id_name_dict) #get list of players, sorted by currentRank, highest First. players_sorted_by_rank = [[p.player_id, p.currentRank] for p in players.Player.all().filter("tourney_id =", tourney_id)] players_sorted_by_rank.sort(key=lambda x: x[1]) players_ids_sorted_by_rank = [int(p[0]) for p in players_sorted_by_rank] ##logging.info('players_ids_sorted_by_rank') ##logging.info(players_ids_sorted_by_rank) #Group finished games by who won finishedGamesGroupedByWinner = main.group(finishedGames, lambda g: g.winner) logging.info("finishedGamesGroupedByWinner:") logging.info(finishedGamesGroupedByWinner) #make the head-to-head table head_to_head_2d = [[getHeadToHead(p,o,finishedGamesGroupedByWinner) for o in players_ids_sorted_by_rank] for p in players_ids_sorted_by_rank] players_for_h2h = [p for p in players_ids_sorted_by_rank] logging.info('head_to_head_2d:') logging.info(head_to_head_2d) #now package it up for the html biggermat = deepcopy(head_to_head_2d) biggermat.insert(0,players_for_h2h) players_for_h2h_padded = deepcopy(players_for_h2h) players_for_h2h_padded_22 = [str(player) + '::'+str(players_id_name_dict[player]) for player in players_for_h2h_padded] logging.info(players_for_h2h_padded_22) players_for_h2h_padded_22.insert(0,'player_id') for i,j in zip(biggermat, players_for_h2h_padded_22): i.insert(0,j) logging.info(biggermat) #biggermat [x][y] for x,y>0 is the number of games player x won against player y. #biggermat [0][y] for y>0 is the player_id of player y. #biggermat [x][0] for x>0 is the player_id of player x. return biggermat, head_to_head_2d
def setRanks_ByNumWinsOnly(tourney_id): """This looks at what games everyone has won and sets their currentRank field. The current algorithm is very simple - just award ranks based on number of games won. You should replace this with your own ranking logic.""" logging.info('in setRanks()') #Load all finished games finishedGames = games.Game.all().filter("winner !=", None).filter("tourney_id =", tourney_id) logging.info("finishedGames:") logging.info(finishedGames) players_id_name_dict = getPlayersIDNameDict(tourney_id) logging.info('players_id_name_dict') logging.info(players_id_name_dict) #Group them by who won finishedGamesGroupedByWinner = main.group(finishedGames, lambda g: g.winner) logging.info("finishedGamesGroupedByWinner:") logging.info(finishedGamesGroupedByWinner) for game in games.Game.all().filter("tourney_id =", tourney_id): logging.info('game:') logging.info(game) if game.winner != None: pass #Get rid of the game data, and replace it with the number of games each player won winCounts = dict(map(lambda (playerID,the_games): (playerID, len(the_games)), finishedGamesGroupedByWinner.items())) #Map this from Player.all() to ensure we have an entry for every player, even those with no wins playersMappedToNumWins = [(p, winCounts.get(p.key().id(), 0)) for p in players.Player.all().filter("tourney_id =", tourney_id)] #sort by the number of wins each player has. playersMappedToNumWins.sort(key=lambda (player,numWins): numWins, reverse=True) #Now that it's sorted, we can just loop through each player and set their currentRank for index,(player,numWins) in enumerate(playersMappedToNumWins): player.currentRank = index + 1 #index is 0-based, and we want our top player to be ranked #1, so we add one. player.numWins = numWins #added by unkn player.save() logging.info('player:') logging.info(player) logging.info('setRanks finished')
def index_new(request,tourney_id): """Request / """ logging.info('in index_new(' +str(tourney_id)+ ')') tourney_id = int(tourney_id) logging.info('tourney_id = '+str(tourney_id)) tourney_clotconfig = main.getClotConfig(tourney_id) if not main.doesTourneyExist(tourney_id, tourney_clotconfig): logging.info('tourney does not exist, redirecting user to tourneys info instead') return shortcuts.render_to_response('tourney_does_not_exist.html' ) #arrange players by rank the_players = players.Player.all().filter("tourney_id =", tourney_id)#.run(batch_size=1000) the_players = sorted(the_players, key=lambda z: z.currentRank) gamePlayers = main.group(games.GamePlayer.all().filter("tourney_id =", tourney_id), lambda z: z.gameID) #.run(batch_size=1000) #arrange games by reverse of created date the_games = games.Game.all().filter("tourney_id =", tourney_id)#.run(batch_size=1000) the_games = sorted(the_games, key=lambda z: z.dateCreated, reverse=True) #for game in the_games: # logging.info('game: '+str(game)) # logging.info('game.winningTeamName = '+str(game.winningTeamName)) #do the head-to-head table biggermat, head_to_head_2d = new_utility_functions.getHeadToHeadTable(tourney_id) biggermat_str = deepcopy(biggermat) for i in range(1,len(biggermat_str)): for j in range(1,len(biggermat_str[i])): if i==j: biggermat_str[i][j] = "---" else: biggermat_str[i][j] = str(biggermat_str[i][j][0]) + "-" + str(biggermat_str[i][j][1]) #see if players are gated players_gated_string = "players may join or leave" if main.arePlayersGated(tourney_id, tourney_clotconfig): players_gated_string = "players may NOT join or leave" #get tourney_status_string tourney_status_string = 'Tourney Not Yet Started' if main.isTourneyInPlay(tourney_id, tourney_clotconfig): if str(main.getTourneyType(tourney_id, tourney_clotconfig)) == 'swiss': tourney_status_string = 'Tourney In Progress. Round '+str(main.getRoundNumber(tourney_id, tourney_clotconfig))+' of '+str(main.getNumRounds(tourney_id, tourney_clotconfig)) else: tourney_status_string = 'Tourney In Progress.' elif main.hasTourneyFinished(tourney_id, tourney_clotconfig): winner = the_players[0] winner_name = winner.name tourney_status_string = 'Tourney has finished. Congratulations to '+str(winner_name)+'!' minNumPlayersString= 'minNumPlayers: '+str(main.getMinimumNumberOfPlayers(tourney_id, tourney_clotconfig)) maxNumPlayersString= 'maxNumPlayers: '+str(main.getMaximumNumberOfPlayers(tourney_id, tourney_clotconfig)) starttimeString = 'starttime will be: '+str(main.getStarttime(tourney_id, tourney_clotconfig))+' provided we have minimum number of players.' currentTimeString = 'current time = '+str(main.getCurrentTime()) tourney_type_string = str(main.getTourneyType(tourney_id, tourney_clotconfig)) + ' tourney' how_long_you_have_to_join_games_string = 'You have '+str(main.getHowLongYouHaveToJoinGames(tourney_id, tourney_clotconfig))+' minutes to join your auto-created games. After that you may lose that game!!' template_id = main.getTemplateID(tourney_id, tourney_clotconfig) #things for specific tourney types if main.getTourneyType(tourney_id, tourney_clotconfig)=='swiss': swiss_games_info_table = tournament_swiss.getTourneyRoundsAndGameInfo(tourney_id) else: swiss_games_info_table = 0 #end of things for specific tourney types return shortcuts.render_to_response('tourney_home.html',{'players': the_players, 'config': tourney_clotconfig, 'games': the_games, 'biggermat':biggermat_str, 'players_gated_string':players_gated_string, 'minNumPlayersString':minNumPlayersString, 'maxNumPlayersString':maxNumPlayersString, 'tourney_status_string':tourney_status_string, 'starttimeString':starttimeString, 'currentTimeString':currentTimeString, 'tourney_type_string':tourney_type_string, 'how_long_you_have_to_join_games_string':how_long_you_have_to_join_games_string, 'template_title_string':'Game Template', 'template_id':template_id, 'swiss_games_info_table':swiss_games_info_table, 'join_url':'/tourneys/'+str(tourney_id)+'/join', 'leave_url':'/tourneys/'+str(tourney_id)+'/leave', 'tourney_id':str(tourney_id) })
def test_group(self): groups = main.group([2, 3, 4], ['aldo', 'beat', 'carla', 'david', 'evi', 'flip', 'gary', 'hugo', 'ida']) self.assertEqual(len(groups), 1260) self.assertTrue([['aldo', 'beat'], ['carla', 'david', 'evi'], ['flip', 'gary', 'hugo', 'ida']] in groups) self.assertTrue([['hugo', 'ida'], ['evi', 'flip', 'gary'], ['aldo', 'beat', 'carla', 'david']] in groups)