mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 17:18:24 +02:00
Use separate fields for the two dices
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -163,11 +163,11 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
if state == 'DICE_ORDER_POULE':
|
||||
participation = await Participation.objects\
|
||||
.filter(teamdraw__pool=self.tournament.draw.current_round.current_pool,
|
||||
teamdraw__last_dice__isnull=True).prefetch_related('team').afirst()
|
||||
teamdraw__choice_dice__isnull=True).prefetch_related('team').afirst()
|
||||
else:
|
||||
participation = await Participation.objects\
|
||||
.filter(teamdraw__round=self.tournament.draw.current_round,
|
||||
teamdraw__last_dice__isnull=True).prefetch_related('team').afirst()
|
||||
teamdraw__passage_dice__isnull=True).prefetch_related('team').afirst()
|
||||
trigram = participation.team.trigram
|
||||
else:
|
||||
participation = await Participation.objects.filter(team__participants=self.registration)\
|
||||
@ -179,10 +179,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
|
||||
match state:
|
||||
case 'DICE_SELECT_POULES':
|
||||
if team_draw.last_dice is not None:
|
||||
if team_draw.passage_dice is not None:
|
||||
return await self.alert(_("You've already launched the dice."), 'danger')
|
||||
case 'DICE_ORDER_POULE':
|
||||
if team_draw.last_dice is not None:
|
||||
if team_draw.choice_dice is not None:
|
||||
return await self.alert(_("You've already launched the dice."), 'danger')
|
||||
if not await self.tournament.draw.current_round.current_pool.teamdraw_set\
|
||||
.filter(participation=participation).aexists():
|
||||
@ -191,7 +191,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
return await self.alert(_("This is not the time for this."), 'danger')
|
||||
|
||||
res = randint(1, 100)
|
||||
team_draw.last_dice = res
|
||||
if state == 'DICE_SELECT_POULES':
|
||||
team_draw.passage_dice = res
|
||||
else:
|
||||
team_draw.choice_dice = res
|
||||
await sync_to_async(team_draw.save)()
|
||||
|
||||
await self.channel_layer.group_send(
|
||||
@ -199,21 +202,21 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
|
||||
if state == 'DICE_SELECT_POULES' and \
|
||||
not await TeamDraw.objects.filter(round_id=self.tournament.draw.current_round_id,
|
||||
last_dice__isnull=True).aexists():
|
||||
passage_dice__isnull=True).aexists():
|
||||
tds = []
|
||||
async for td in TeamDraw.objects.filter(round_id=self.tournament.draw.current_round_id)\
|
||||
.prefetch_related('participation__team'):
|
||||
tds.append(td)
|
||||
|
||||
dices = {td: td.last_dice for td in tds}
|
||||
dices = {td: td.passage_dice for td in tds}
|
||||
values = list(dices.values())
|
||||
error = False
|
||||
for v in set(values):
|
||||
if values.count(v) > 1:
|
||||
dups = [td for td in tds if td.last_dice == v]
|
||||
dups = [td for td in tds if td.passage_dice == v]
|
||||
|
||||
for dup in dups:
|
||||
dup.last_dice = None
|
||||
dup.passage_dice = None
|
||||
await sync_to_async(dup.save)()
|
||||
await self.channel_layer.group_send(
|
||||
f"tournament-{self.tournament.id}",
|
||||
@ -229,7 +232,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
if error:
|
||||
return
|
||||
|
||||
tds.sort(key=lambda td: td.last_dice)
|
||||
tds.sort(key=lambda td: td.passage_dice)
|
||||
tds_copy = tds.copy()
|
||||
|
||||
async for p in Pool.objects.filter(round_id=self.tournament.draw.current_round_id).order_by('letter').all():
|
||||
@ -247,7 +250,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
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(last_dice=None, pool=None, passage_index=None)
|
||||
.aupdate(passage_dice=None, pool=None, passage_index=None)
|
||||
for td in tds:
|
||||
await self.channel_layer.group_send(
|
||||
f"tournament-{self.tournament.id}",
|
||||
@ -265,13 +268,12 @@ 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.last_dice})"
|
||||
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é."
|
||||
self.tournament.draw.last_message = msg
|
||||
await sync_to_async(self.tournament.draw.save)()
|
||||
|
||||
await TeamDraw.objects.filter(round=self.tournament.draw.current_round).aupdate(last_dice=None)
|
||||
for td in tds:
|
||||
await self.channel_layer.group_send(
|
||||
f"tournament-{self.tournament.id}",
|
||||
@ -296,7 +298,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
{'type': 'draw.set_active', 'draw': self.tournament.draw})
|
||||
elif state == 'DICE_ORDER_POULE' and \
|
||||
not await TeamDraw.objects.filter(pool=self.tournament.draw.current_round.current_pool,
|
||||
last_dice__isnull=True).aexists():
|
||||
choice_dice__isnull=True).aexists():
|
||||
pool = self.tournament.draw.current_round.current_pool
|
||||
|
||||
tds = []
|
||||
@ -304,15 +306,15 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
.prefetch_related('participation__team'):
|
||||
tds.append(td)
|
||||
|
||||
dices = {td: td.last_dice for td in tds}
|
||||
dices = {td: td.choice_dice for td in tds}
|
||||
values = list(dices.values())
|
||||
error = False
|
||||
for v in set(values):
|
||||
if values.count(v) > 1:
|
||||
dups = [td for td in tds if td.last_dice == v]
|
||||
dups = [td for td in tds if td.choice_dice == v]
|
||||
|
||||
for dup in dups:
|
||||
dup.last_dice = None
|
||||
dup.choice_dice = None
|
||||
await sync_to_async(dup.save)()
|
||||
await self.channel_layer.group_send(
|
||||
f"tournament-{self.tournament.id}",
|
||||
@ -328,7 +330,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
|
||||
if error:
|
||||
return
|
||||
|
||||
tds.sort(key=lambda x: -x.last_dice)
|
||||
tds.sort(key=lambda x: -x.choice_dice)
|
||||
for i, td in enumerate(tds):
|
||||
td.choose_index = i
|
||||
await sync_to_async(td.save)()
|
||||
|
@ -0,0 +1,238 @@
|
||||
# Generated by Django 4.1.7 on 2023-03-28 19:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("draw", "0006_pool_associated_pool"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="teamdraw",
|
||||
name="last_dice",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="teamdraw",
|
||||
name="choice_dice",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[
|
||||
(1, 1),
|
||||
(2, 2),
|
||||
(3, 3),
|
||||
(4, 4),
|
||||
(5, 5),
|
||||
(6, 6),
|
||||
(7, 7),
|
||||
(8, 8),
|
||||
(9, 9),
|
||||
(10, 10),
|
||||
(11, 11),
|
||||
(12, 12),
|
||||
(13, 13),
|
||||
(14, 14),
|
||||
(15, 15),
|
||||
(16, 16),
|
||||
(17, 17),
|
||||
(18, 18),
|
||||
(19, 19),
|
||||
(20, 20),
|
||||
(21, 21),
|
||||
(22, 22),
|
||||
(23, 23),
|
||||
(24, 24),
|
||||
(25, 25),
|
||||
(26, 26),
|
||||
(27, 27),
|
||||
(28, 28),
|
||||
(29, 29),
|
||||
(30, 30),
|
||||
(31, 31),
|
||||
(32, 32),
|
||||
(33, 33),
|
||||
(34, 34),
|
||||
(35, 35),
|
||||
(36, 36),
|
||||
(37, 37),
|
||||
(38, 38),
|
||||
(39, 39),
|
||||
(40, 40),
|
||||
(41, 41),
|
||||
(42, 42),
|
||||
(43, 43),
|
||||
(44, 44),
|
||||
(45, 45),
|
||||
(46, 46),
|
||||
(47, 47),
|
||||
(48, 48),
|
||||
(49, 49),
|
||||
(50, 50),
|
||||
(51, 51),
|
||||
(52, 52),
|
||||
(53, 53),
|
||||
(54, 54),
|
||||
(55, 55),
|
||||
(56, 56),
|
||||
(57, 57),
|
||||
(58, 58),
|
||||
(59, 59),
|
||||
(60, 60),
|
||||
(61, 61),
|
||||
(62, 62),
|
||||
(63, 63),
|
||||
(64, 64),
|
||||
(65, 65),
|
||||
(66, 66),
|
||||
(67, 67),
|
||||
(68, 68),
|
||||
(69, 69),
|
||||
(70, 70),
|
||||
(71, 71),
|
||||
(72, 72),
|
||||
(73, 73),
|
||||
(74, 74),
|
||||
(75, 75),
|
||||
(76, 76),
|
||||
(77, 77),
|
||||
(78, 78),
|
||||
(79, 79),
|
||||
(80, 80),
|
||||
(81, 81),
|
||||
(82, 82),
|
||||
(83, 83),
|
||||
(84, 84),
|
||||
(85, 85),
|
||||
(86, 86),
|
||||
(87, 87),
|
||||
(88, 88),
|
||||
(89, 89),
|
||||
(90, 90),
|
||||
(91, 91),
|
||||
(92, 92),
|
||||
(93, 93),
|
||||
(94, 94),
|
||||
(95, 95),
|
||||
(96, 96),
|
||||
(97, 97),
|
||||
(98, 98),
|
||||
(99, 99),
|
||||
(100, 100),
|
||||
],
|
||||
default=None,
|
||||
null=True,
|
||||
verbose_name="choice dice",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="teamdraw",
|
||||
name="passage_dice",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[
|
||||
(1, 1),
|
||||
(2, 2),
|
||||
(3, 3),
|
||||
(4, 4),
|
||||
(5, 5),
|
||||
(6, 6),
|
||||
(7, 7),
|
||||
(8, 8),
|
||||
(9, 9),
|
||||
(10, 10),
|
||||
(11, 11),
|
||||
(12, 12),
|
||||
(13, 13),
|
||||
(14, 14),
|
||||
(15, 15),
|
||||
(16, 16),
|
||||
(17, 17),
|
||||
(18, 18),
|
||||
(19, 19),
|
||||
(20, 20),
|
||||
(21, 21),
|
||||
(22, 22),
|
||||
(23, 23),
|
||||
(24, 24),
|
||||
(25, 25),
|
||||
(26, 26),
|
||||
(27, 27),
|
||||
(28, 28),
|
||||
(29, 29),
|
||||
(30, 30),
|
||||
(31, 31),
|
||||
(32, 32),
|
||||
(33, 33),
|
||||
(34, 34),
|
||||
(35, 35),
|
||||
(36, 36),
|
||||
(37, 37),
|
||||
(38, 38),
|
||||
(39, 39),
|
||||
(40, 40),
|
||||
(41, 41),
|
||||
(42, 42),
|
||||
(43, 43),
|
||||
(44, 44),
|
||||
(45, 45),
|
||||
(46, 46),
|
||||
(47, 47),
|
||||
(48, 48),
|
||||
(49, 49),
|
||||
(50, 50),
|
||||
(51, 51),
|
||||
(52, 52),
|
||||
(53, 53),
|
||||
(54, 54),
|
||||
(55, 55),
|
||||
(56, 56),
|
||||
(57, 57),
|
||||
(58, 58),
|
||||
(59, 59),
|
||||
(60, 60),
|
||||
(61, 61),
|
||||
(62, 62),
|
||||
(63, 63),
|
||||
(64, 64),
|
||||
(65, 65),
|
||||
(66, 66),
|
||||
(67, 67),
|
||||
(68, 68),
|
||||
(69, 69),
|
||||
(70, 70),
|
||||
(71, 71),
|
||||
(72, 72),
|
||||
(73, 73),
|
||||
(74, 74),
|
||||
(75, 75),
|
||||
(76, 76),
|
||||
(77, 77),
|
||||
(78, 78),
|
||||
(79, 79),
|
||||
(80, 80),
|
||||
(81, 81),
|
||||
(82, 82),
|
||||
(83, 83),
|
||||
(84, 84),
|
||||
(85, 85),
|
||||
(86, 86),
|
||||
(87, 87),
|
||||
(88, 88),
|
||||
(89, 89),
|
||||
(90, 90),
|
||||
(91, 91),
|
||||
(92, 92),
|
||||
(93, 93),
|
||||
(94, 94),
|
||||
(95, 95),
|
||||
(96, 96),
|
||||
(97, 97),
|
||||
(98, 98),
|
||||
(99, 99),
|
||||
(100, 100),
|
||||
],
|
||||
default=None,
|
||||
null=True,
|
||||
verbose_name="passage dice",
|
||||
),
|
||||
),
|
||||
]
|
@ -314,11 +314,18 @@ class TeamDraw(models.Model):
|
||||
verbose_name=_("accepted problem"),
|
||||
)
|
||||
|
||||
last_dice = models.PositiveSmallIntegerField(
|
||||
passage_dice = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 101), range(1, 101)),
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_("last dice"),
|
||||
verbose_name=_("passage dice"),
|
||||
)
|
||||
|
||||
choice_dice = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 101), range(1, 101)),
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_("choice dice"),
|
||||
)
|
||||
|
||||
purposed = models.PositiveSmallIntegerField(
|
||||
@ -335,6 +342,10 @@ class TeamDraw(models.Model):
|
||||
verbose_name=_('rejected problems'),
|
||||
)
|
||||
|
||||
@property
|
||||
def last_dice(self):
|
||||
return self.passage_dice if self.round.draw.get_state() == 'DICE_SELECT_POULES' else self.choice_dice
|
||||
|
||||
@property
|
||||
def penalty_int(self):
|
||||
return max(0, len(self.rejected) - (settings.PROBLEM_COUNT - 5))
|
||||
|
Reference in New Issue
Block a user