def report_all_players(self): '''reports all players in a tournament''' players_table = db.table('players') all_players = players_table.all() tournament_table = db.table('tournaments') all_tournament = tournament_table.all() user_answer = Views.which_name_tournament() players = [] for tournament in all_tournament: if user_answer == tournament['name']: for player in tournament['players']: for play in all_players: if player == play['name']: players.append(play) user_answer = Views.sorted_report() if user_answer == 1: sorted_players = sorted(players, key=itemgetter('name')) for player in sorted_players: print('name: ' + str(player['name']) + ' Firstname: ' + str(player['firstname']) + ' ranking: ' + str(player['ranking'])) elif user_answer == 2: sorted_players = sorted(players, key=itemgetter('ranking')) for player in sorted_players: print('name: ' + str(player['name']) + ' Firstname: ' + str(player['firstname']) + ' ranking: ' + str(player['ranking']))
def call_subpipelines(self): only = self.only cache = self.debug if not only or "views" in only: Views(cache, self.hours_per_day).run(self.sort_by) if not only or "citations" in only: Citations(cache).run(self.sort_by)
def generate_rounds(self, list_of_players): '''Makes the link between the round model and the views in order to generate the rounds and pair the players''' # create the round round = Views.create_round() round.tournament_name = self.tournament.name # initialize match list because python keep in memory the last match list in the instance round round.match_list = [] # generate the round and return the list of matchs # if it is the first round, lauch first round algorithm if int(round.name) == 1: list_of_matchs = round.first_rnd(list_of_players) # if it is a round other than the first one elif int(round.name) > 1 and int(round.name) <= int( self.tournament.number_of_tours): list_of_matchs = round.round(list_of_players) # if the number of rounds is exceeded else: Views.all_rounds_played() return # show generated matchs Views.show_match(list_of_matchs) # enter scores for match in list_of_matchs: # enter player's score for each match score_1 = Views.propose_to_enter_scores(match[0].name) # set the score in the player instance match[0].set_score(score_1) # same procedure for the second player of the match score_2 = Views.propose_to_enter_scores(match[1].name) match[1].set_score(score_2) # update in round, each match and scores round.match_list.append([(match[0].name, score_1), (match[1].name, score_2)]) # save the round in the db round.save() # add opponent in each player instance for match in list_of_matchs: match[0].add_opponents(match[1]) match[1].add_opponents(match[0]) # update players in list of instances in tournament list_play_instances = [] for match in list_of_matchs: for player in match: list_play_instances.append(player) self.tournament.players_i = list_play_instances # update rounds list in the tournament instance self.tournament.rounds.append(round.name) # final phrase and results if the round is the last one if int(round.name) == int(self.tournament.number_of_tours): Views.print_final_scores(list_of_players)
def report_rounds_tournament(self): '''reports all rounds in a certain tournamnent''' rounds_table = db.table('rounds') all_rounds = rounds_table.all() user_answer = Views.which_name_tournament() for round in all_rounds: if round['tournament_name'] == user_answer: print('-------------') print('name: ' + str(round['name']), 'date: ' + str(round['date']), 'time: ' + str(round['time']))
def report_matchs_tournament(self): '''reports all matchs in a certain tournament''' rounds_table = db.table('rounds') all_rounds = rounds_table.all() user_answer = Views.which_name_tournament() for round in all_rounds: print('-----------------') print('Round: ') print(round['name']) if round['tournament_name'] == user_answer: match_list = round['match_list'] for match in match_list: print(match[0][0] + ' against ' + match[1][0])
def generate_reports(self): '''Menu of the reports''' report = Report() user_answer = Views.reports() if user_answer == 1: report.report_all_actors() elif user_answer == 2: report.report_all_players() elif user_answer == 3: report.report_all_tournaments() elif user_answer == 4: report.report_rounds_tournament() elif user_answer == 5: report.report_matchs_tournament()
def report_all_actors(self): '''reports all actors in the db''' actors_table = db.table('players') all_actors = actors_table.all() user_answer = Views.sorted_report() if user_answer == 1: sorted_actors = sorted( all_actors, key=itemgetter('name'), ) for actor in sorted_actors: print('name: ' + str(actor['name']) + ' Firstname: ' + str(actor['firstname']) + ' ranking: ' + str(actor['ranking'])) elif user_answer == 2: sorted_actors = sorted( all_actors, key=itemgetter('ranking'), ) for actor in sorted_actors: print('name: ' + str(actor['name']) + ' Firstname: ' + str(actor['firstname']) + ' ranking: ' + str(actor['ranking']))
def menu(self): '''Main menu of the program, makes the link between the views and the models to allow the user access every fonctionality of the application''' # create or load tour if self.tournament == "": user_answer = Views.print_create_or_load() # if user wants to create tour if user_answer == 1: self.tournament = Views.create_new_tournament() # if user wants to load a tour elif user_answer == 2: self.tournament = Views.propose_to_load_tour() # other answer else: Views.print_create_or_load() # load players if players that allready are in the loaded tour if len(self.tournament.players) != 0: for player in self.tournament.players: self.tournament.players_i.append( Player.load_player(player)) # create players user_answer = Views.print_main_menu() if user_answer == 1: # check if there is too many players if Player.check_max_player(self.tournament.players): Views.players_full() # create the player else: player = Views.create_new_player() # add to the list of players self.tournament.players_i.append(player) # add to the tour instance self.tournament.players.append(player.name) self.menu() # generate rounds elif user_answer == 2: # check if there is enough players if len(self.tournament.players) == int( self.tournament.number_of_players): # generate the round with the list of players self.generate_rounds(self.tournament.players_i) self.menu() # if not enough players return an alert else: Views.not_enough_players() self.menu() # go to the reports menu elif user_answer == 3: self.generate_reports() self.menu() # exit elif user_answer == 9: answer = Views.exit() # if wants to save if answer == 1: # erase the players in the db # save the players in list of players players_table = db.table('players') play = Query() for player in self.tournament.players_i: players_table.remove(play.name == player.name) player.save() # erase list of player instances to save self.tournament.players_i = [] # erase the tournaments in the db tournament_table = db.table('tournaments') tour = Query() tournament_table.remove(tour.name == self.tournament.name) # save the tour self.tournament.save() Views.tournament_saved() exit(0) if answer == 2: Views.goodbye() exit(0) else: self.menu()
from views.views import Views if __name__ == "__main__": while True: user_choice = Views.main_menue_view() try: if int(user_choice) == 1: Views.create_tournament_view() elif int(user_choice) == 2: Views.generate_round_view() elif int(user_choice) == 3: Views.get_round_results_view() elif int(user_choice) == 4: Views.get_report_view() elif int(user_choice) == 5: Views.create_player_view() elif int(user_choice) == 6: Views.get_player_info_view() elif int(user_choice) == 7: Views.set_new_elo_view() elif int(user_choice) == 8: Views.show_provisional_ranking() else: Views.error_message_view() except ValueError: if user_choice in {"q", "Q"}: break else: Views.error_message_view()