From f4fd27a5c15f3ebe8d2a6a75d992cc4e28885f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Sender=C3=A1k?= Date: Wed, 22 Apr 2020 18:18:48 +0200 Subject: [PATCH] added points summary --- api/routes.py | 7 ++++++- api/static/style.css | 8 ++++++++ api/templates/_guess_form.html | 2 +- api/templates/status.html | 7 ++++++- api/utils.py | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 api/utils.py diff --git a/api/routes.py b/api/routes.py index 2cbf8ac..6bd2812 100644 --- a/api/routes.py +++ b/api/routes.py @@ -3,6 +3,7 @@ from bridzik import Bridzik, Card, Card_colors, Card_values, BridzikException import json from flask import render_template, url_for, flash, redirect from api.forms import GuessForm, PlayForm, AdminForm +from api.utils import get_points_sums b = Bridzik() @@ -25,6 +26,7 @@ def status(player): form = None player_cards = Card.sort_card_list(b.series[-1].get_last_round().player_cards[player]) game_status['player_cards'] = [str(c) for c in player_cards] + points_sums = get_points_sums(game_status['standings']) if b.is_completed() or b.series[-1].get_last_round().get_active_player() != player: pass elif not b.series[-1].get_last_round().is_guessing_completed(): @@ -34,7 +36,10 @@ def status(player): form = PlayForm() form.card.choices = [(str(c), str(c)) for c in player_cards] action = 'play' - return render_template('status.html', status=game_status, player=player, action=action, form=form, players=players) + return render_template( + 'status.html', status=game_status, player=player, action=action, + form=form, players=players, points_sums=points_sums + ) @app.route('/bridzik//guess', methods=['POST']) def guess(player): diff --git a/api/static/style.css b/api/static/style.css index a4393bc..60358f5 100644 --- a/api/static/style.css +++ b/api/static/style.css @@ -29,3 +29,11 @@ width: 82px; height: 150px; } + +#points_summary_row { + border-top: 1px solid black; +} + +table { + border-collapse: collapse; +} diff --git a/api/templates/_guess_form.html b/api/templates/_guess_form.html index 314ae0d..7034afe 100644 --- a/api/templates/_guess_form.html +++ b/api/templates/_guess_form.html @@ -2,7 +2,7 @@ {{ form.hidden_tag() }}

{{ form.guess.label }}: - {{ form.guess(size=15) }} + {{ form.guess(size=15, autocomplete="off") }} {% for error in form.guess.errors %} [{{ error }}] {% endfor %} diff --git a/api/templates/status.html b/api/templates/status.html index d89983a..ffa7d5f 100644 --- a/api/templates/status.html +++ b/api/templates/status.html @@ -126,13 +126,13 @@

Výsledky

- {% for series in status['standings'] %} + {% for series in status['standings'] %} {% if series %} {% for round in series %} {% if round %} @@ -145,6 +145,11 @@ {% endfor %} {% endif %} {% endfor %} + + {% for player in points_sums %} + + {% endfor %} +
{{ players[0] }} {{ players[1] }} {{ players[2] }} {{ players[3] }}
{{ player }}
diff --git a/api/utils.py b/api/utils.py new file mode 100644 index 0000000..d4e156f --- /dev/null +++ b/api/utils.py @@ -0,0 +1,7 @@ +def get_points_sums(standings: []): + sums = [0] * 4 + for series in standings: + for round in series: + for player, points in enumerate(round): + sums[player] += points + return sums