예제 #1
0
def assign_judges_to_pairing(request):
    current_round_number = TabSettings.objects.get(key="cur_round").value - 1
    if request.method == "POST":
        panel_points, errors = [], []
        potential_panel_points = [
            k for k in list(request.POST.keys()) if k.startswith("panel_")
        ]
        for point in potential_panel_points:
            try:
                point = int(point.split("_")[1])
                num = float(request.POST["panel_{0}".format(point)])
                if num > 0.0:
                    panel_points.append((Round.objects.get(id=point), num))
            except Exception as e:
                emit_current_exception()
                errors.append(e)

        panel_points.reverse()
        rounds = list(Round.objects.filter(round_number=current_round_number))
        judges = [
            ci.judge
            for ci in CheckIn.objects.filter(round_number=current_round_number)
        ]
        try:
            backup.backup_round("round_%s_before_judge_assignment" %
                                current_round_number)
            assign_judges.add_judges(rounds, judges, panel_points)
        except Exception as e:
            emit_current_exception()
            return redirect_and_flash_error(
                request, "Got error during judge assignment")
    return redirect("/pairings/status/")
예제 #2
0
def manual_backup(request):
    try:
        cur_round, btime = TabSettings.objects.get(key="cur_round").value, int(
            time.time())
        now = datetime.datetime.fromtimestamp(btime).strftime("%Y-%m-%d_%I:%M")
        backup.backup_round("manual_backup_round_{}_{}_{}".format(
            cur_round, btime, now))
    except:
        emit_current_exception()
        return render_to_response('error.html', {
            'error_type':
            "Manual Backup",
            'error_name':
            "Backups",
            'error_info':
            "Could not backup database. Something is wrong with your AWS setup."
        },
                                  context_instance=RequestContext(request))
    return render_to_response('thanks.html', {
        'data_type':
        "Backing up database",
        'data_name':
        " for round {} as version number {}".format(cur_round, btime)
    },
                              context_instance=RequestContext(request))
예제 #3
0
def assign_judges_to_pairing(request):
    current_round_number = TabSettings.objects.get(key="cur_round").value - 1
    if request.method == 'POST':
        panel_points, errors = [], []
        potential_panel_points = [k for k in list(request.POST.keys()) if k.startswith('panel_')]
        for point in potential_panel_points:
           try:
               point = int(point.split("_")[1])
               num = float(request.POST["panel_{0}".format(point)])
               if num > 0.0:
                   panel_points.append((Round.objects.get(id=point), num))
           except Exception as e:
               emit_current_exception()
               errors.append(e)
               pass

        panel_points.reverse()
        rounds = list(Round.objects.filter(round_number=current_round_number))
        judges = [ci.judge for ci in CheckIn.objects.filter(round_number=current_round_number)]
        try:
            backup.backup_round("round_%s_before_judge_assignment" % current_round_number)
            assign_judges.add_judges(rounds, judges, panel_points)
        except Exception as e:
            emit_current_exception()
            return redirect_and_flash_error(request,
                    "Got error during judge assignment")
    return redirect('/pairings/status/')
예제 #4
0
def manual_backup(request):
    try:
        cur_round, btime = TabSettings.objects.get(key="cur_round").value, int(time.time())
        now = datetime.datetime.fromtimestamp(btime).strftime("%Y-%m-%d_%I:%M")
        backup.backup_round("manual_backup_round_{}_{}_{}".format(cur_round, btime, now))
    except:
        emit_current_exception()
        return redirect_and_flash_error(request, "Error creating backup")
    return redirect_and_flash_success(request,
            "Backup created for round {} at timestamp {}".format(cur_round, btime))
예제 #5
0
def break_teams(request):
    if request.method == "POST":
        # Perform the break
        backup.backup_round("before_the_break_%s" %
                            (timezone.now().strftime("%H:%M"), ))

        success, msg = outround_tab_logic.perform_the_break()

        if success:
            return redirect_and_flash_success(request,
                                              msg,
                                              path="/outround_pairing")
        return redirect_and_flash_error(request, msg, path="/")

    # See if we can pair the round
    title = "Pairing Outrounds"
    current_round_number = 0

    previous_round_number = TabSettings.get("tot_rounds", 5)

    check_status = []

    msg = "All Rounds properly entered for Round %s" % (previous_round_number)

    ready_to_pair = "Yes"
    ready_to_pair_alt = "Checks passed!"
    try:
        tab_logic.have_properly_entered_data(current_round_number)
        check_status.append((msg, "Yes", "All rounds look good"))
    except PrevRoundNotEnteredError as e:
        ready_to_pair = "No"
        ready_to_pair_alt = str(e)
        check_status.append(
            (msg, "No", "Not all rounds are entered. %s" % str(e)))
    except ByeAssignmentError as e:
        ready_to_pair = "No"
        ready_to_pair_alt = str(e)
        check_status.append(
            (msg, "No", "You have a bye and results. %s" % str(e)))
    except NoShowAssignmentError as e:
        ready_to_pair = "No"
        ready_to_pair_alt = str(e)
        check_status.append(
            (msg, "No", "You have a noshow and results. %s" % str(e)))

    rooms = outround_tab_logic.have_enough_rooms_before_break()
    msg = "N/2 Rooms available Round Out-rounds? Need {0}, have {1}".format(
        rooms[1][1], rooms[1][0])
    if rooms[0]:
        check_status.append((msg, "Yes", "Rooms are checked in"))
    else:
        check_status.append((msg, "No", "Not enough rooms"))

    return render(request, "pairing/pair_round.html", locals())
예제 #6
0
def manual_backup(request):
    try:
        cur_round, btime = TabSettings.objects.get(key="cur_round").value, int(
            time.time())
        now = datetime.datetime.fromtimestamp(btime).strftime("%Y-%m-%d_%I:%M")
        backup.backup_round("manual_backup_round_{}_{}_{}".format(
            cur_round, btime, now))
    except Exception:
        emit_current_exception()
        return redirect_and_flash_error(request, "Error creating backup")
    return redirect_and_flash_success(
        request,
        "Backup created for round {} at timestamp {}".format(cur_round, btime))
예제 #7
0
def manual_backup(request):
    try:
        cur_round, btime = TabSettings.objects.get(key="cur_round").value, int(time.time())
        now = datetime.datetime.fromtimestamp(btime).strftime("%Y-%m-%d_%I:%M")
        backup.backup_round("manual_backup_round_{}_{}_{}.db".format(cur_round, btime, now))
    except:
        traceback.print_exc(file=sys.stdout)
        return render_to_response('error.html',
                                 {'error_type': "Manual Backup",'error_name': "Backups",
                                  'error_info': "Could not backup database. Something is wrong with your AWS setup."},
                                  context_instance=RequestContext(request))
    return render_to_response('thanks.html',
                             {'data_type': "Backing up database",
                              'data_name': " for round {} as version number {}".format(cur_round, btime)},
                               context_instance=RequestContext(request))
예제 #8
0
def pair_round(request):
    cache_logic.clear_cache()
    current_round = TabSettings.objects.get(key="cur_round")
    next_round = current_round.value 
    if request.method == 'POST':
        try:
            backup.backup_round("round_%i_before_pairing.db" % (next_round))
            tab_logic.pair_round()
            backup.backup_round("round_%i_after_pairing.db" % (next_round))
        except Exception, e:
            traceback.print_exc(file=sys.stdout)
            return render_to_response('error.html', 
                                 {'error_type': "Pair Next Round",
                                  'error_name': "Pairing Round %s" % (current_round.value + 1),
                                  'error_info':"Could not pair next round because of: [%s]" %(e)}, 
                                  context_instance=RequestContext(request))           
        current_round.value = current_round.value + 1
        current_round.save() 
        return view_status(request)
예제 #9
0
def assign_judges_to_pairing(request):
    current_round_number = TabSettings.objects.get(key="cur_round").value - 1
    if request.method == 'POST':
        panel_points, errors = [], []
        potential_panel_points = [
            k for k in request.POST.keys() if k.startswith('panel_')
        ]
        for point in potential_panel_points:
            try:
                point = int(point.split("_")[1])
                num = float(request.POST["panel_{0}".format(point)])
                if num > 0.0:
                    panel_points.append((Round.objects.get(id=point), num))
            except Exception as e:
                emit_current_exception()
                errors.append(e)
                pass

        panel_points.reverse()
        rounds = list(Round.objects.filter(round_number=current_round_number))
        judges = [
            ci.judge
            for ci in CheckIn.objects.filter(round_number=current_round_number)
        ]
        try:
            backup.backup_round("round_%s_before_judge_assignment" %
                                current_round_number)
            assign_judges.add_judges(rounds, judges, panel_points)
        except Exception as e:
            emit_current_exception()
            return render_to_response('error.html', {
                'error_type': "Judge Assignment",
                'error_name': "",
                'error_info': str(e)
            },
                                      context_instance=RequestContext(request))
    return redirect('/pairings/status/')
예제 #10
0
def pair_next_outround(request, num_teams, type_of_round):
    if request.method == "POST":
        backup.backup_round("before_pairing_%s_%s" %
                            (num_teams / 2, type_of_round))

        Outround.objects.filter(num_teams__lt=num_teams,
                                type_of_round=type_of_round).delete()

        outround_tab_logic.pair(type_of_round)

        return redirect_and_flash_success(request,
                                          "Success!",
                                          path=reverse("outround_pairing_view",
                                                       kwargs={
                                                           "num_teams":
                                                           int(num_teams / 2),
                                                           "type_of_round":
                                                           type_of_round
                                                       }))

    # See if we can pair the round
    title = "Pairing Outrounds"
    current_round_number = 0

    previous_round_number = TabSettings.get("tot_rounds", 5)

    check_status = []

    judges = outround_tab_logic.have_enough_judges_type(type_of_round)
    rooms = outround_tab_logic.have_enough_rooms_type(type_of_round)

    msg = "Enough judges checked in for Out-rounds? Need {0}, have {1}".format(
        judges[1][1], judges[1][0])

    if num_teams <= 2:
        check_status.append(("Have more rounds?", "No", "Not enough teams"))
    else:
        check_status.append(("Have more rounds?", "Yes", "Have enough teams!"))

    if judges[0]:
        check_status.append((msg, "Yes", "Judges are checked in"))
    else:
        check_status.append((msg, "No", "Not enough judges"))

    msg = "N/2 Rooms available Round Out-rounds? Need {0}, have {1}".format(
        rooms[1][1], rooms[1][0])
    if rooms[0]:
        check_status.append((msg, "Yes", "Rooms are checked in"))
    else:
        check_status.append((msg, "No", "Not enough rooms"))

    round_label = "[%s] Ro%s" % ("N" if type_of_round else "V", num_teams)
    msg = "All Rounds properly entered for Round %s" % (round_label)
    ready_to_pair = "Yes"
    ready_to_pair_alt = "Checks passed!"
    try:
        outround_tab_logic.have_properly_entered_data(num_teams, type_of_round)
        check_status.append((msg, "Yes", "All rounds look good"))
    except PrevRoundNotEnteredError as e:
        ready_to_pair = "No"
        ready_to_pair_alt = str(e)
        check_status.append(
            (msg, "No", "Not all rounds are entered. %s" % str(e)))

    return render(request, "pairing/pair_round.html", locals())
예제 #11
0
def pair_round(request):
    cache_logic.clear_cache()
    current_round = TabSettings.objects.get(key="cur_round")
    current_round_number = current_round.value
    if request.method == 'POST':
        # We should pair the round
        try:
            TabSettings.set('pairing_released', 0)
            backup.backup_round("round_%i_before_pairing.db" % (current_round_number))
            # TODO(benjaminmarks): Re-implement atomicity
            # with transaction.atomic():
            tab_logic.pair_round()
            current_round.value = current_round.value + 1
            current_round.save()
            backup.backup_round("round_%i_after_pairing.db" % (current_round_number))
        except Exception as exp:
            traceback.print_exc(file=sys.stdout)
            return render_to_response('error.html',
                                      {'error_type': "Pair Next Round",
                                       'error_name': "Pairing Round %s" % (current_round.value + 1),
                                       'error_info': "Could not pair next round because of: [{0}]".format(exp)},
                                        context_instance=RequestContext(request))
        return view_status(request)
    else:
        # See if we can pair the round
        title = "Pairing Round %s" % (current_round_number)
        check_status = []

        judges = tab_logic.have_enough_judges(current_round_number)
        rooms = tab_logic.have_enough_rooms(current_round_number)

        msg = "N/2 Judges checked in for Round {0}? Need {1}, have {2}".format(
              current_round_number, judges[1][1], judges[1][0])
        if judges[0]:
            check_status.append((msg, "Yes", "Judges are checked in"))
        else:
            check_status.append((msg, "No", "Not enough judges"))

        msg = "N/2 Rooms available Round {0}? Need {1}, have {2}".format(
              current_round_number, rooms[1][1], rooms[1][0])
        if rooms[0]:
            check_status.append((msg, "Yes", "Rooms are checked in"))
        else:
            check_status.append((msg, "No", "Not enough rooms"))

        msg = "All Rounds properly entered for Round %s" % (current_round_number - 1)
        ready_to_pair = "Yes"
        ready_to_pair_alt = "Checks passed!"
        try:
            tab_logic.have_properly_entered_data(current_round_number)
            check_status.append((msg, "Yes", "All rounds look good"))
        except PrevRoundNotEnteredError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append((msg, "No", "Not all rounds are entered. %s" % str(e)))
        except ByeAssignmentError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append((msg, "No", "You have a bye and results. %s" % str(e)))
        except NoShowAssignmentError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e) 
            check_status.append((msg, "No", "You have a noshow and results. %s" % str(e)))

        return render_to_response('pair_round.html',
                                  locals(),
                                  context_instance=RequestContext(request))
예제 #12
0
def pair_round(request):
    cache_logic.clear_cache()
    current_round = TabSettings.objects.get(key="cur_round")
    current_round_number = current_round.value
    if request.method == 'POST':
        # We should pair the round
        try:
            TabSettings.set('pairing_released', 0)
            backup.backup_round("round_%i_before_pairing" %
                                (current_round_number))

            with transaction.atomic():
                tab_logic.pair_round()
                current_round.value = current_round.value + 1
                current_round.save()
        except Exception as exp:
            emit_current_exception()
            return render_to_response('error.html', {
                'error_type':
                "Pair Next Round",
                'error_name':
                "Pairing Round %s" % (current_round.value + 1),
                'error_info':
                "Could not pair next round because of: [{0}]".format(exp)
            },
                                      context_instance=RequestContext(request))
        return view_status(request)
    else:
        # See if we can pair the round
        title = "Pairing Round %s" % (current_round_number)
        check_status = []

        judges = tab_logic.have_enough_judges(current_round_number)
        rooms = tab_logic.have_enough_rooms(current_round_number)

        msg = "N/2 Judges checked in for Round {0}? Need {1}, have {2}".format(
            current_round_number, judges[1][1], judges[1][0])
        if judges[0]:
            check_status.append((msg, "Yes", "Judges are checked in"))
        else:
            check_status.append((msg, "No", "Not enough judges"))

        msg = "N/2 Rooms available Round {0}? Need {1}, have {2}".format(
            current_round_number, rooms[1][1], rooms[1][0])
        if rooms[0]:
            check_status.append((msg, "Yes", "Rooms are checked in"))
        else:
            check_status.append((msg, "No", "Not enough rooms"))

        msg = "All Rounds properly entered for Round %s" % (
            current_round_number - 1)
        ready_to_pair = "Yes"
        ready_to_pair_alt = "Checks passed!"
        try:
            tab_logic.have_properly_entered_data(current_round_number)
            check_status.append((msg, "Yes", "All rounds look good"))
        except PrevRoundNotEnteredError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append(
                (msg, "No", "Not all rounds are entered. %s" % str(e)))
        except ByeAssignmentError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append(
                (msg, "No", "You have a bye and results. %s" % str(e)))
        except NoShowAssignmentError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append(
                (msg, "No", "You have a noshow and results. %s" % str(e)))

        return render_to_response('pair_round.html',
                                  locals(),
                                  context_instance=RequestContext(request))
예제 #13
0
def pair_round(request):
    cache_logic.clear_cache()
    current_round = TabSettings.objects.get(key="cur_round")
    current_round_number = current_round.value
    if request.method == 'POST':
        # We should pair the round
        try:
            TabSettings.set('pairing_released', 0)
            backup.backup_round("round_%i_before_pairing" % (current_round_number))

            with transaction.atomic():
                tab_logic.pair_round()
                current_round.value = current_round.value + 1
                current_round.save()
        except Exception as exp:
            emit_current_exception()
            return redirect_and_flash_error(request,
                    "Could not pair next round, got error: {}".format(exp))
        return view_status(request)
    else:
        # See if we can pair the round
        title = "Pairing Round %s" % (current_round_number)
        check_status = []

        judges = tab_logic.have_enough_judges(current_round_number)
        rooms = tab_logic.have_enough_rooms(current_round_number)

        msg = "N/2 Judges checked in for Round {0}? Need {1}, have {2}".format(
              current_round_number, judges[1][1], judges[1][0])
        if judges[0]:
            check_status.append((msg, "Yes", "Judges are checked in"))
        else:
            check_status.append((msg, "No", "Not enough judges"))

        msg = "N/2 Rooms available Round {0}? Need {1}, have {2}".format(
              current_round_number, rooms[1][1], rooms[1][0])
        if rooms[0]:
            check_status.append((msg, "Yes", "Rooms are checked in"))
        else:
            check_status.append((msg, "No", "Not enough rooms"))

        msg = "All Rounds properly entered for Round %s" % (current_round_number - 1)
        ready_to_pair = "Yes"
        ready_to_pair_alt = "Checks passed!"
        try:
            tab_logic.have_properly_entered_data(current_round_number)
            check_status.append((msg, "Yes", "All rounds look good"))
        except PrevRoundNotEnteredError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append((msg, "No", "Not all rounds are entered. %s" % str(e)))
        except ByeAssignmentError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e)
            check_status.append((msg, "No", "You have a bye and results. %s" % str(e)))
        except NoShowAssignmentError as e:
            ready_to_pair = "No"
            ready_to_pair_alt = str(e) 
            check_status.append((msg, "No", "You have a noshow and results. %s" % str(e)))

        return render(request, 'pairing/pair_round.html', locals())
예제 #14
0
    def handle(self, *args, **options):
        backup_dir = options["backup_directory"]
        path = BACKUP_PREFIX

        self.stdout.write(
            "Creating directory for current tournament in backup directory")
        tournament_dir = os.path.join(backup_dir, str(int(time.time())))

        if not os.path.exists(tournament_dir):
            os.makedirs(tournament_dir)

        if not os.path.exists(path + "/backups"):
            os.makedirs(path + "/backups")

        self.stdout.write(
            "Copying current tournament state to backup tournament directory: %s"
            % tournament_dir)
        backup_round("before_new_tournament")
        try:
            shutil.rmtree(tournament_dir + "/backups", ignore_errors=True)
            shutil.copytree(path + "/backups", tournament_dir + "/backups")
        except (IOError, os.error) as why:
            self.stdout.write("Failed to backup current tournament state")
            print(why)
            sys.exit(1)

        self.stdout.write("Clearing data from database")
        try:
            call_command("flush", interactive=False)
        except (IOError, os.error) as why:
            self.stdout.write("Failed to clear database")
            print(why)
            sys.exit(1)

        self.stdout.write("Creating tab/entry users")
        tab = User.objects.create_user("tab", None, options["tab_password"])
        tab.is_staff = True
        tab.is_admin = True
        tab.is_superuser = True
        tab.save()
        User.objects.create_user("entry", None, options["entry_password"])

        self.stdout.write("Setting default tab settings")
        TabSettings.set("tot_rounds", 5)
        TabSettings.set("lenient_late", 0)
        TabSettings.set("cur_round", 1)

        self.stdout.write("Cleaning up old backups")
        try:
            shutil.rmtree(path + "/backups")
            os.makedirs(path + "/backups")
        except (IOError, os.error) as why:
            self.stdout.write(
                "Failed to copy clean database to pairing_db.sqlite3")
            print(why)
            sys.exit(1)

        self.stdout.write(
            "Done setting up tournament, after backing up old one. "
            "New tournament information:")
        self.stdout.write(
            "%s | %s" % ("Username".ljust(10, " "), "Password".ljust(10, " ")))
        self.stdout.write(
            "%s | %s" %
            ("tab".ljust(10, " "), options["tab_password"].ljust(10, " ")))
        self.stdout.write(
            "%s | %s" %
            ("entry".ljust(10, " "), options["entry_password"].ljust(10, " ")))