mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-22 00:38:23 +02:00
Use more complex calculus to mix teams for the second day
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -93,7 +93,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
@ensure_orga
|
||||
async def start_draw(self, fmt, **kwargs):
|
||||
try:
|
||||
fmt = list(map(int, fmt.split('+')))
|
||||
fmt = sorted(map(int, fmt.split('+')), reverse=True)
|
||||
except ValueError as e:
|
||||
return await self.alert(_("Invalid format"), 'danger')
|
||||
|
||||
@ -102,6 +102,9 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
_("The sum must be equal to the number of teams: expected {len}, got {sum}")\
|
||||
.format(len=len(self.participations), sum=sum(fmt)), 'danger')
|
||||
|
||||
if fmt.count(5) > 1:
|
||||
return await self.alert(_("There can be at most one pool with 5 teams."), 'danger')
|
||||
|
||||
draw = await Draw.objects.acreate(tournament=self.tournament)
|
||||
r1 = None
|
||||
for i in [1, 2]:
|
||||
@ -236,31 +239,31 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
tds_copy = tds.copy()
|
||||
|
||||
async for p in Pool.objects.filter(round_id=self.tournament.draw.current_round_id).order_by('letter').all():
|
||||
while (c := await TeamDraw.objects.filter(pool=p).acount()) < p.size:
|
||||
td = tds_copy.pop(0)
|
||||
pool_tds = sorted(tds_copy[:p.size], key=lambda td: (td.passage_dice * 27) % 100)
|
||||
tds_copy = tds_copy[p.size:]
|
||||
for i, td in enumerate(pool_tds):
|
||||
td.pool = p
|
||||
td.passage_index = c
|
||||
td.passage_index = i
|
||||
await sync_to_async(td.save)()
|
||||
|
||||
if self.tournament.draw.current_round.number == 2 \
|
||||
and await self.tournament.draw.current_round.pool_set.acount() >= 2:
|
||||
# Check that we don't have a same pool as the first day
|
||||
async for p1 in Pool.objects.filter(round__draw=self.tournament.draw, round__number=1).all():
|
||||
async for p2 in Pool.objects.filter(round_id=self.tournament.draw.current_round_id).all():
|
||||
if await sync_to_async(lambda: set(td['id'] for td in p1.teamdraw_set.values('id')))() \
|
||||
== await sync_to_async(lambda:set(td['id'] for td in p2.teamdraw_set.values('id')))():
|
||||
await TeamDraw.objects.filter(round=self.tournament.draw.current_round)\
|
||||
.aupdate(passage_dice=None, pool=None, passage_index=None)
|
||||
for td in tds:
|
||||
await self.channel_layer.group_send(
|
||||
f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.dice', 'team': td.participation.team.trigram, 'result': None})
|
||||
await self.channel_layer.group_send(
|
||||
f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.alert',
|
||||
'message': _('Two pools are identical. Please relaunch your dices.'),
|
||||
'alert_type': 'warning'})
|
||||
return
|
||||
tds_copy = tds.copy()
|
||||
round2 = await self.tournament.draw.round_set.filter(number=2).aget()
|
||||
round2_pools = await sync_to_async(lambda: list(Pool.objects.filter(
|
||||
round__draw__tournament=self.tournament, round=round2).order_by('letter').all()))()
|
||||
current_pool_id, current_passage_index = 0, 0
|
||||
for i, td in enumerate(tds_copy):
|
||||
if i == len(tds) - 1 and round2_pools[0].size == 5:
|
||||
current_pool_id = 0
|
||||
current_passage_index = 4
|
||||
|
||||
td2 = await TeamDraw.objects.filter(participation=td.participation, round=round2).aget()
|
||||
td2.pool = round2_pools[current_pool_id]
|
||||
td2.passage_index = current_passage_index
|
||||
current_pool_id += 1
|
||||
if current_pool_id == len(round2_pools):
|
||||
current_pool_id = 0
|
||||
current_passage_index += 1
|
||||
await sync_to_async(td2.save)()
|
||||
|
||||
pool = await Pool.objects.filter(round=self.tournament.draw.current_round, letter=1).aget()
|
||||
self.tournament.draw.current_round.current_pool = pool
|
||||
@ -269,8 +272,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
msg = "Les résultats des dés sont les suivants : "
|
||||
msg += await sync_to_async(lambda: ", ".join(
|
||||
f"<strong>{td.participation.team.trigram}</strong> ({td.passage_dice})"
|
||||
for td in self.tournament.draw.current_round.team_draws))()
|
||||
msg += ". L'ordre de passage et les compositions des différentes poules sont affiché⋅es sur le côté."
|
||||
for td in tds))()
|
||||
msg += ". L'ordre de passage et les compositions des différentes poules sont affiché⋅es sur le côté. "
|
||||
msg += "Attention : les ordres de passage sont déterminés à partir des scores des dés, mais ne sont pas "
|
||||
msg += "directement l'ordre croissant des dés, afin d'avoir des poules mélangées."
|
||||
self.tournament.draw.last_message = msg
|
||||
await sync_to_async(self.tournament.draw.save)()
|
||||
|
||||
@ -291,6 +296,9 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.send_poules',
|
||||
'round': self.tournament.draw.current_round})
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.send_poules',
|
||||
'round': await self.tournament.draw.round_set.filter(number=2).aget()})
|
||||
|
||||
await self.channel_layer.group_send(f"tournament-{self.tournament.id}",
|
||||
{'type': 'draw.set_info', 'draw': self.tournament.draw})
|
||||
|
Reference in New Issue
Block a user