1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-24 18:20:33 +02:00

Add continue button for the final tournament

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2023-03-26 11:08:03 +02:00
parent 1bd9cea458
commit 7d8975339e
6 changed files with 156 additions and 52 deletions

View File

@ -34,8 +34,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
.prefetch_related('draw__current_round__current_pool__current_team').aget()
self.participations = []
async for participation in Participation.objects.filter(tournament=self.tournament, valid=True)\
.prefetch_related('team'):
async for participation in self.tournament.participations.filter(valid=True).prefetch_related('team'):
self.participations.append(participation)
user = self.scope['user']
@ -88,6 +87,8 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
await self.reject_problem(**content)
case 'export':
await self.export(**content)
case 'continue_final':
await self.continue_final(**content)
@ensure_orga
async def start_draw(self, fmt, **kwargs):
@ -487,8 +488,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
{'type': 'draw.dice_visibility', 'visible': True})
else:
# Round is ended
# TODO: For the final tournament, add some adjustments
if r.number == 1:
if r.number == 1 and not self.tournament.final:
# Next round
r2 = await self.tournament.draw.round_set.filter(number=2).aget()
self.tournament.draw.current_round = r2
@ -505,6 +505,11 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
{'type': 'draw.dice_visibility', 'visible': True})
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
{'type': 'draw.dice_visibility', 'visible': True})
elif r.number == 1 and self.tournament.final:
# For the final tournament, we wait for a manual update between the two rounds.
msg += "<br><br>Le tirage au sort du tour 1 est terminé."
self.tournament.draw.last_message = msg
await sync_to_async(self.tournament.draw.save)()
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
{'type': 'draw.export_visibility', 'visible': True})
@ -587,6 +592,56 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
{'type': 'draw.export_visibility', 'visible': False})
@ensure_orga
async def continue_final(self, **kwargs):
if not self.tournament.final:
return await self.alert(_("This is only available for the final tournament."), 'danger')
r2 = await self.tournament.draw.round_set.filter(number=2).aget()
self.tournament.draw.current_round = r2
msg = "Le tirage au sort pour le tour 2 va commencer. " \
"L'ordre de passage est déterminé à partir du classement du premier tour."
self.tournament.draw.last_message = msg
await sync_to_async(self.tournament.draw.save)()
pool = await Pool.objects.filter(round=self.tournament.draw.current_round, letter=1).aget()
r2.current_pool = pool
await sync_to_async(r2.save)()
notes = dict()
async for participation in self.tournament.participations.filter(valid=True).prefetch_related('team').all():
notes[participation] = sum([await sync_to_async(pool.average)(participation)
async for pool in self.tournament.pools.filter(participations=participation)
if pool.results_available])
print(participation.team.trigram, notes[participation])
ordered_participations = sorted(notes.keys(), key=lambda x: -notes[x])
async for pool in r2.pool_set.order_by('letter').all():
for i in range(pool.size):
participation = ordered_participations.pop(0)
td = await TeamDraw.objects.aget(round=r2, participation=participation)
td.pool = pool
td.passage_index = i
await sync_to_async(td.save)()
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
{'type': 'draw.send_poules', 'round': r2})
for participation in self.participations:
await self.channel_layer.group_send(
f"tournament-{self.tournament.id}",
{'type': 'draw.dice', 'team': participation.team.trigram, 'result': None})
await self.channel_layer.group_send(f"team-{participation.team.trigram}",
{'type': 'draw.dice_visibility', 'visible': True})
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
{'type': 'draw.dice_visibility', 'visible': True})
await self.channel_layer.group_send(f"volunteer-{self.tournament.id}",
{'type': 'draw.continue_visibility', 'visible': False})
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
{'type': 'draw.set_info', 'draw': self.tournament.draw})
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
{'type': 'draw.set_active', 'draw': self.tournament.draw})
async def draw_alert(self, content):
return await self.alert(**content)
@ -611,6 +666,9 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
async def draw_export_visibility(self, content):
await self.send_json({'type': 'export_visibility', 'visible': content['visible']})
async def draw_continue_visibility(self, content):
await self.send_json({'type': 'continue_visibility', 'visible': content['visible']})
async def draw_send_poules(self, content):
await self.send_json({'type': 'set_poules', 'round': content['round'].number,
'poules': [{'letter': pool.get_letter_display(), 'teams': await pool.atrigrams()}