mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-24 11:08:46 +02:00
Reorder teams for 5-teams pools
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# Copyright (C) 2023 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from collections import OrderedDict
|
||||
from random import randint
|
||||
|
||||
from asgiref.sync import sync_to_async
|
||||
@ -436,6 +436,37 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
{'type': 'draw.box_visibility', 'visible': True})
|
||||
else:
|
||||
# Pool is ended
|
||||
if pool.size == 5:
|
||||
# Maybe reorder teams if the same problem is presented twice
|
||||
problems = OrderedDict()
|
||||
async for td in pool.team_draws:
|
||||
problems.setdefault(td.accepted, [])
|
||||
problems[td.accepted].append(td)
|
||||
p_index = 0
|
||||
for pb, tds in problems.items():
|
||||
if len(tds) == 2:
|
||||
tds[0].passage_index = p_index
|
||||
tds[1].passage_index = p_index + 1
|
||||
p_index += 2
|
||||
await sync_to_async(tds[0].save)()
|
||||
await sync_to_async(tds[1].save)()
|
||||
for pb, tds in problems.items():
|
||||
if len(tds) == 1:
|
||||
tds[0].passage_index = p_index
|
||||
p_index += 1
|
||||
await sync_to_async(tds[0].save)()
|
||||
|
||||
print(p_index)
|
||||
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}", {
|
||||
'type': 'draw.reorder_pool',
|
||||
'round': r.number,
|
||||
'pool': pool.get_letter_display(),
|
||||
'teams': [td.participation.team.trigram
|
||||
async for td in pool.team_draws.prefetch_related('participation__team')],
|
||||
'problems': [td.accepted async for td in pool.team_draws],
|
||||
})
|
||||
|
||||
msg += f"<br><br>Le tirage de la poule {pool.get_letter_display()}{r.number} est terminé. " \
|
||||
f"Le tableau récapitulatif est en bas."
|
||||
self.tournament.draw.last_message = msg
|
||||
@ -451,7 +482,6 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
else:
|
||||
# Round is ended
|
||||
# TODO: For the final tournament, add some adjustments
|
||||
# TODO: Make some adjustments for 5-teams-pools
|
||||
if r.number == 1:
|
||||
# Next round
|
||||
r2 = await self.tournament.draw.round_set.filter(number=2).aget()
|
||||
@ -583,3 +613,8 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
async def draw_reject_problem(self, content):
|
||||
await self.send_json({'type': 'reject_problem', 'round': content['round'],
|
||||
'team': content['team'], 'rejected': content['rejected']})
|
||||
|
||||
async def draw_reorder_pool(self, content):
|
||||
await self.send_json({'type': 'reorder_poule', 'round': content['round'],
|
||||
'poule': content['pool'], 'teams': content['teams'],
|
||||
'problems': content['problems']})
|
||||
|
Reference in New Issue
Block a user