def show_teams(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return teams = processes._open_tournament.teams max_team_name = 6 if len(teams) > 0: max_team_name = max(max([len(t.name) for t in teams]) + 1, max_team_name) max_pv = len('Performance Value') print('{name:{name_width}}{pv:{pv_width}}'.format(name='Name', name_width=max_team_name, pv='Performance Value', pv_width=max_pv)) print('-' * (max_team_name + max_pv)) for t in teams: print('{name:{name_width}}{pv:>{pv_width}}'.format( name=t.name, name_width=max_team_name, pv=t.performance_value, pv_width=max_pv)) processes.close_tournament()
def show_round(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # check tournament is started if not processes.check_tournament_started(): print('Tournament has not started yet, so there is no round to show. ' 'Use "start-tournament" to start the tournament.') processes.close_tournament() return # check round number, and use latest round if none or invalid is given round_number = _check_round_number(args.round[0]) teams = processes._open_tournament.teams max_team_name = 6 if max([len(t.name) for t in teams]) + 2 < 6 else max( [len(t.name) for t in teams]) + 2 points_width = 8 game_width = len('Number') + 2 print('Round', str(round_number + 1)) print('{game_number:{game_width}}{team_a:{team_width}}{team_b:{' 'team_width}}{points_a:{points_width}}{points_b:{' 'points_width}}'.format(game_number='Number', game_width=game_width, team_a='Team A', team_b='Team B', team_width=max_team_name, points_a='Points', points_b='', points_width=points_width)) print('-' * (game_width + max_team_name * 2 + points_width * 2)) for g in processes._open_tournament.rounds[round_number].games: print('{game_number:<{game_width}}{team_a:{team_width}}{team_b:{' 'team_width}}{points_a:{points_width}}{points_b:{' 'points_width}}'.format( game_number=g.id, game_width=game_width, team_a=g.team_a, team_b=g.team_b if g.team_b is not None else 'free', team_width=max_team_name, points_a='' if g.points_a == -1 else g.points_a, points_b='' if g.points_b == -1 else g.points_b, points_width=points_width)) processes.close_tournament()
def export_standings(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return if not processes.check_tournament_started(): print('Tournament has not started. Nothing to export.') processes.close_tournament() return # update standings and export them processes.calculate_standings() processes.export_standings() processes.close_tournament()
def export_round(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return if not processes.check_tournament_started(): print('Tournament has not started. Nothing to export.') processes.close_tournament() return # check round number, and use latest round if none is given round_number = _check_round_number(args.round[0]) # create latex file and build it with pdflatex processes.export_round(round_number) processes.close_tournament()
def remove_team(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return if processes.check_tournament_started(): print('Tournament has already started. It is not possible to remove ' 'teams. Just enter results as lost games.') processes.close_tournament() return try: processes.remove_team(args.name[0]) except ValueError: print('The team you wanted to remove has not been added to the tournament.') processes.close_tournament()
def revert_round(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # check tournament is started if not processes.check_tournament_started(): print('Tournament has not started yet. No round to revert.') processes.close_tournament() return if ask_yes_no( 'Do you really want to revert the current round? All results will ' 'be deleted.'): processes.revert_round() processes.close_tournament()
def stop_tournament(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # check not yet started if not processes.check_tournament_started(): print('Tournament not started yet, so there is nothing to stop.') processes.close_tournament() return # check performance values of teams and assign random values if ask_yes_no( 'Do you really want to stop the tournament? All progress will be ' 'deleted.'): processes.stop_tournament() processes.close_tournament()
def start_tournament(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # check already started if processes.check_tournament_started(): print('Tournament already started and cannot be started again.') processes.close_tournament() return # check performance values of teams and assign random values try: processes.start_tournament() except NoTeamsError: print('There are no teams in this tournament. Use the "add-team" command.') processes.close_tournament()
def add_team(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return if processes.check_tournament_started(): print('Tournament already started. It is not possible to add more ' 'teams.') processes.close_tournament() return if processes.check_team_already_exists(args.name[0]): if not ask_yes_no( 'There is already a team with the same name. Do you want to ' 'overwrite existing team?'): processes.close_tournament() return else: processes.remove_team(name=args.name[0]) processes.add_team(args.name[0], args.performance[0]) processes.close_tournament()
def next_round(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # check tournament is started if not processes.check_tournament_started(): print('Tournament has not started yet. Starting the tournament with ' '"start-tournament" command, will automatically determine the ' 'first round.') processes.close_tournament() return # check current round is finished if not processes.check_current_round_is_finished(): print('The current round is not finished yet. Use "show-round" ' 'command to see all matches of the current round and ' '"enter-result {game} {points_a} {points_b}" command to enter ' 'the result.') processes.close_tournament() return # calculate standings, calculate next round processes.calculate_next_round() processes.close_tournament()
def enter_result(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # Check tournament is started if not processes.check_tournament_started(): print( 'Tournament has not been started. Use "start-tournament" command.') processes.close_tournament() return # check the game number exists if args.game[0] < 1 or args.game[0] > len( processes._open_tournament.rounds) * len( processes._open_tournament.rounds[0].games): print('Game number does not exist. Use "show-round" command to see ' 'games of current round.') processes.close_tournament() return # check points >= 0 if args.a[0] < 0 or args.b[0] < 0: print('Points scored by a team must be greater or equal to 0. At the ' 'moment there is no way to enter negative scores.') processes.close_tournament() return # check remis if args.a[0] == args.b[0]: print( 'At the moment remis are not supported. There has to be a winner!') processes.close_tournament() return # check if game already has a result and ask whether it should be # overwritten game = processes._open_tournament.get_game_by_id(args.game[0]) if game.is_finished(): if not ask_yes_no( 'Result for this game has already been entered. Do you want ' 'to overwrite the result?'): processes.close_tournament() return # add result processes.add_result(game, args.a[0], args.b[0]) processes.close_tournament()
def show_standings(args): try: processes.load_tournament(args.tournament[0]) except FileNotFoundError: print('Could not open the tournament. Have you created the tournament, yet?', 'if not, try the "create-tournament" command.') return # check tournament is started if not processes.check_tournament_started(): print('Tournament has not started yet, so there no standings to show. ' 'Use "start-tournament" to start the tournament.') processes.close_tournament() return # update standings processes.calculate_standings() teams = sorted(processes._open_tournament.teams, key=attrgetter('position')) max_team_name = 6 if max([len(t.name) for t in teams]) + 2 < 6 else max( [len(t.name) for t in teams]) + 2 position_width = len('Position') + 2 wins_width = len('Wins') + 2 losses_width = len('Losses') + 2 bh_width = len('BH') + 2 fbh_width = len('FBH') + 2 sb_width = len('SB') + 2 koya_width = len('Kayo') + 2 points_diff_width = len('Points difference') + 2 points_width = len('Points') + 2 points_against_width = len('Points against') + 2 fl_width = len('FR') + 2 pv_width = len('PV') + 2 print('{position:{position_width}}{team:{team_width}}{wins:{wins_width}}{' 'losses:{losses_width}}{bh:{bh_width}}{fbh:{fbh_width}}{sb:{' 'sb_width}}{koya:{koya_width}}{points_diff:{points_diff_width}}{' 'points:{points_width}}{points_against:{points_against_width}}{fl:{' 'fl_width}}{pv:{pv_width}}'.format( position='Position', position_width=position_width, team='Team', team_width=max_team_name, wins='Wins', wins_width=wins_width, losses='Losses', losses_width=losses_width, bh='BH', bh_width=bh_width, fbh='FBH', fbh_width=fbh_width, sb='SB', sb_width=sb_width, koya='Koya', koya_width=koya_width, points_diff='Points difference', points_diff_width=points_diff_width, points='Points', points_width=points_width, points_against='Points against', points_against_width=points_against_width, fl='FR', fl_width=fl_width, pv='PV', pv_width=pv_width)) print('-' * ( position_width + max_team_name + wins_width + losses_width + bh_width + fbh_width + sb_width + koya_width + points_diff_width + points_width + points_against_width + fl_width + pv_width)) for t in teams: print('{position:<{position_width}}{team:{team_width}}{wins:{' 'wins_width}}{losses:{losses_width}}{bh:{bh_width}}{fbh:{' 'fbh_width}}{sb:{sb_width}}{koya:{koya_width}}{points_diff:{' 'points_diff_width}}{points:{points_width}}{points_against:{' 'points_against_width}}{fl:{fl_width}}{pv:{pv_width}}'.format( position=t.position, position_width=position_width, team=t.name, team_width=max_team_name, wins=t.wins, wins_width=wins_width, losses=t.losses, losses_width=losses_width, bh=t.bh, bh_width=bh_width, fbh=t.fbh, fbh_width=fbh_width, sb=t.sb, sb_width=sb_width, koya=t.koya, koya_width=koya_width, points_diff=t.points - t.points_against, points_diff_width=points_diff_width, points=t.points, points_width=points_width, points_against=t.points_against, points_against_width=points_against_width, fl=t.fl, fl_width=fl_width, pv=t.performance_value, pv_width=pv_width)) processes.close_tournament()