Exemple #1
0
def tournament(client, tourn_name):
    """ Create the north 40 tournament, return loaded object. """
    delete_tournament(tourn_name)
    assert tourn_name not in get_saved_tournament_names()
    tour_type = "LimitedRound"
    url = f"/create_tournament_{tour_type}_{tourn_name}"
    data = dict(players_per_round=4, number_of_plays=2)
    client.post(url, data=data, follow_redirects=True)
    assert tourn_name in get_saved_tournament_names()
    yield load_tournament(tourn_name)
    delete_tournament(tourn_name)
Exemple #2
0
def run_tournament(name):
    """ page for running the tournament """

    # if tournament is not loaded decide to load or create
    if name in TOURNAMENT:
        tour = TOURNAMENT[name]
    elif name in get_saved_tournament_names():
        return redirect(url_for("load_tournament", name=name))
    else:
        return redirect(url_for("index"))

    kwargs = dict(name=name)
    matches = tour.get_next_matchups(2)

    # create form
    form = make_up_first_form(matches[0] if len(matches) else [])
    undo_form = UndoEntry()

    # undo was clicked
    if undo_form.undo.data:
        tour.undo()
        return redirect(url_for("run_tournament", **kwargs))

    # data is being submitted
    if request.method == "POST":
        if form.validate_on_submit():
            # set values
            if len(matches):
                for num, player in enumerate(matches[0]):
                    player_name = f"player{num}"
                    val = float(getattr(form, player_name).data)
                    tour.set_time(player, val)
                # redirect to input to clear form state
                tour.save()
                return redirect(url_for("run_tournament", **kwargs))
            else:
                flash("Tournament complete!")
        else:
            flash("All fields must be numbers greater than 0")

    # get table to display
    df = tour.get_ratings().round(decimals=3)
    car_table = df.to_html(classes="aTable")
    progress_string = f"{tour.heat} / {tour.total_heats}"
    kwargs = dict(
        matches=matches,
        form=form,
        name=name,
        car_table=car_table,
        undo_form=undo_form,
        progress_string=progress_string,
    )
    return render_template("run_tournament.html", **kwargs)
Exemple #3
0
 def test_save(self, tournament_util, tmpdir):
     """ ensure the tournament can be saved. """
     path = Path(tmpdir)
     tournament_util.save(path=path)
     assert tournament_util.name in get_saved_tournament_names(path)
Exemple #4
0
 def test_create_new_tournament(self, tournament):
     """ Create a new tournament with a different default name. """
     assert tournament.name in get_saved_tournament_names()
Exemple #5
0
class LoadTournamentForm(FlaskForm):
    """ A form for creating a new tournament """

    choices = [(x, x) for x in get_saved_tournament_names()]
    name = wtforms.SelectField(label="Saved Tournaments", choices=choices)
    load_tournament = wtforms.SubmitField(label="Load Tournament")