1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 01:58:23 +02:00

Add debug feature for problem draw, useful for final tournament

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-04-22 23:36:52 +02:00
parent 943276ef71
commit 0bc5ef0a7f
6 changed files with 253 additions and 134 deletions

View File

@ -637,6 +637,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
and isinstance(kwargs['problem'], int) and (1 <= kwargs['problem'] <= len(settings.PROBLEMS)):
# Admins can force the draw
problem = int(kwargs['problem'])
break
# Check that the user didn't already accept this problem for the first round
# if this is the second round

View File

@ -292,7 +292,7 @@ class Pool(models.Model):
"""
Returns a query set ordered by passage index of all team draws in this pool.
"""
return self.teamdraw_set.order_by('passage_index').all()
return self.teamdraw_set.all()
@property
def trigrams(self) -> list[str]:
@ -545,4 +545,5 @@ class TeamDraw(models.Model):
class Meta:
verbose_name = _('team draw')
verbose_name_plural = _('team draws')
ordering = ('round__draw__tournament__name', 'round__number', 'pool__letter', 'passage_index',)
ordering = ('round__draw__tournament__name', 'round__number', 'pool__letter', 'passage_index',
'choice_dice', 'passage_dice',)

View File

@ -40,6 +40,20 @@ function drawDice(tid, trigram = null, result = null) {
socket.send(JSON.stringify({'tid': tid, 'type': 'dice', 'trigram': trigram, 'result': result}))
}
/**
* Fetch the requested dice from the buttons and request to draw it.
* Only available for debug purposes and for admins.
* @param tid The tournament id
*/
function drawDebugDice(tid) {
let dice_10 = parseInt(document.querySelector(`input[name="debug-dice-${tid}-10"]:checked`).value)
let dice_1 = parseInt(document.querySelector(`input[name="debug-dice-${tid}-1"]:checked`).value)
let result = (dice_10 + dice_1) || 100
let team_div = document.querySelector(`div[id="dices-${tid}"] > div > div[class*="text-bg-warning"]`)
let team = team_div.getAttribute("data-team")
drawDice(tid, team, result)
}
/**
* Request to draw a new problem.
* @param tid The tournament id
@ -203,6 +217,14 @@ document.addEventListener('DOMContentLoaded', () => {
elem.classList.add('text-bg-success')
elem.innerText = `${trigram} 🎲 ${result}`
}
let nextTeam = document.querySelector(` div[id="dices-${tid}"] > div > div[class*="text-bg-warning"]`).getAttribute("data-team")
if (nextTeam) {
// If there is one team that does not have launched its dice, then we update the debug section
let debugSpan = document.getElementById(`debug-dice-${tid}-team`)
if (debugSpan)
debugSpan.innerText = nextTeam
}
}
/**
@ -212,10 +234,15 @@ document.addEventListener('DOMContentLoaded', () => {
*/
function updateDiceVisibility(tid, visible) {
let div = document.getElementById(`launch-dice-${tid}`)
if (visible)
let div_debug = document.getElementById(`debug-dice-form-${tid}`)
if (visible) {
div.classList.remove('d-none')
else
div_debug.classList.remove('d-none')
}
else {
div.classList.add('d-none')
div_debug.classList.add('d-none')
}
}
/**
@ -225,10 +252,15 @@ document.addEventListener('DOMContentLoaded', () => {
*/
function updateBoxVisibility(tid, visible) {
let div = document.getElementById(`draw-problem-${tid}`)
if (visible)
let div_debug = document.getElementById(`debug-problem-form-${tid}`)
if (visible) {
div.classList.remove('d-none')
else
div_debug.classList.remove('d-none')
}
else {
div.classList.add('d-none')
div_debug.classList.add('d-none')
}
}
/**
@ -582,6 +614,11 @@ document.addEventListener('DOMContentLoaded', () => {
let teamLi = document.getElementById(`recap-${tid}-round-${round}-team-${team}`)
if (teamLi !== null)
teamLi.classList.add('list-group-item-info')
let debugSpan = document.getElementById(`debug-problem-${tid}-team`)
if (debugSpan && team) {
debugSpan.innerText = team
}
}
/**

View File

@ -37,6 +37,7 @@
{% for td in tournament.draw.current_round.team_draws %}
<div class="col-md-1" style="order: {{ forloop.counter }};">
<div id="dice-{{ tournament.id }}-{{ td.participation.team.trigram }}"
data-team="{{ td.participation.team.trigram }}"
class="badge rounded-pill text-bg-{% if td.last_dice %}success{% else %}warning{% endif %}"
{% if request.user.registration.is_volunteer %}
{# Volunteers can click on dices to launch the dice of a team #}
@ -186,6 +187,66 @@
{% endif %}
{% endif %}
</div>
{% if user.registration.is_admin %}
<div class="card my-3">
<div class="card-header">
<div style="cursor: pointer;" data-bs-toggle="collapse" data-bs-target="#debug-draw-{{ tournament.id }}-body"
aria-controls="debug-draw-{{ tournament.id }}-body" aria-expanded="false">
<h4>{% trans "Debug draw" %}</h4>
</div>
</div>
<div class="card-body collapse" id="debug-draw-{{ tournament.id }}-body">
<div id="debug-dice-form-{{ tournament.id }}" {% if tournament.draw.get_state != 'DICE_SELECT_POULES' and tournament.draw.get_state != 'DICE_ORDER_POULE' %}class="d-none"{% endif %}>
<h5>
{% trans "Draw dice for" %}
<span id="debug-dice-{{ tournament.id }}-team">
{% regroup tournament.draw.current_round.team_draws by last_dice as td_dices %}
{% for group in td_dices %}
{% if group.grouper is None %}
{{ group }}
{% with group.list|first as td %}
{{ td.participation.team.trigram }}
{% endwith %}
{% endif %}
{% endfor %}
</span>
</h5>
<div class="btn-group w-100" role="group">
{% for i in range_100 %}
<input type="radio" class="btn-check" name="debug-dice-{{ tournament.id }}-10" id="debug-dice-{{ tournament.id }}-{{ i|stringformat:"02d" }}" value="{{ i }}" {% if i == 0 %}checked{% endif %}>
<label class="btn btn-outline-warning" for="debug-dice-{{ tournament.id }}-{{ i|stringformat:"02d" }}">{{ i|stringformat:"02d" }}</label>
{% endfor %}
</div>
<div class="btn-group w-100" role="group">
{% for i in range_10 %}
<input type="radio" class="btn-check" name="debug-dice-{{ tournament.id }}-1" id="debug-dice-{{ tournament.id }}-{{ i }}" value="{{ i }}" {% if i == 0 %}checked{% endif %}>
<label class="btn btn-outline-warning" for="debug-dice-{{ tournament.id }}-{{ i }}">{{ i }}</label>
{% endfor %}
</div>
<div class="my-2 text-center">
<button class="btn btn-success" onclick="drawDebugDice({{ tournament.id }})">
{% trans "Draw dice" %} 🎲
</button>
</div>
</div>
<div id="debug-problem-form-{{ tournament.id }}" {% if tournament.draw.get_state != 'WAITING_DRAW_PROBLEM' %}class="d-none"{% endif %}>
<h5>
{% trans "Draw problem for" %}
<span id="debug-problem-{{ tournament.id }}-team">{{ tournament.draw.current_round.current_pool.current_team.participation.team.trigram }}</span>
</h5>
<div class="btn-group w-100" role="group">
{% for problem in problems %}
<button class="btn btn-outline-info" id="debug-problem-{{ tournament.id }}-{{ forloop.counter }}" onclick="drawProblem({{ tournament.id }}, {{ forloop.counter }})">
{% trans "Pb." %} {{ forloop.counter }}
</button>
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}
</div>
</div>

View File

@ -40,4 +40,7 @@ class DisplayView(LoginRequiredMixin, TemplateView):
context['tournaments_simplified'] = [{'id': t.id, 'name': t.name} for t in tournaments]
context['problems'] = settings.PROBLEMS
context['range_100'] = range(0, 100, 10)
context['range_10'] = range(0, 10, 1)
return context