broadcast matches draft

clubs
Laurent 2 years ago
parent 156044e41a
commit b952b72a0d
  1. 15
      tournaments/models/round.py
  2. 46
      tournaments/models/tournament.py

@ -15,16 +15,6 @@ class Round(models.Model):
else: else:
return f"{self.tournament.name} - {self.name()}" return f"{self.tournament.name} - {self.name()}"
# def stage_call(self):
# stage_call = StageCall(f"1/{self.index}")
# for match in self.match_set.all():
# names = map(lambda ts: ts.player_names(), match.teamstate_set.all())
# if names:
# team_call = TeamCall(names, match.formatted_start_date)
# stage_call.add_team(team_call)
# return stage_call
def name(self): def name(self):
if self.loser: if self.loser:
return "Matchs de classement" return "Matchs de classement"
@ -50,3 +40,8 @@ class Round(models.Model):
matches.extend(child_matches) matches.extend(child_matches)
matches.extend(child.ranking_matches(hide_empty_matches)) matches.extend(child.ranking_matches(hide_empty_matches))
return matches return matches
def all_matches(self):
matches = self.match_set.all()
matches.extend(self.ranking_matches(True))
return matches

@ -19,7 +19,6 @@ class Tournament(models.Model):
bracket_sort_mode = models.IntegerField(default=0) bracket_sort_mode = models.IntegerField(default=0)
group_stage_count = models.IntegerField(default=0) group_stage_count = models.IntegerField(default=0)
rank_source_date = models.DateTimeField(null=True, blank=True) rank_source_date = models.DateTimeField(null=True, blank=True)
# custom_name = models.CharField(max_length=100, null=True, blank=True)
day_duration = models.IntegerField(default=0) day_duration = models.IntegerField(default=0)
team_count = models.IntegerField(default=0) team_count = models.IntegerField(default=0)
team_sorting = models.IntegerField(default=0) team_sorting = models.IntegerField(default=0)
@ -34,7 +33,6 @@ class Tournament(models.Model):
prioritize_club_members = models.BooleanField() prioritize_club_members = models.BooleanField()
qualified_per_group_stage = models.IntegerField(default=0) qualified_per_group_stage = models.IntegerField(default=0)
teams_per_group_stage = models.IntegerField(default=0) teams_per_group_stage = models.IntegerField(default=0)
#estimated_end_date = models.DateTimeField(null=True, blank=True)
def __str__(self): def __str__(self):
if self.name: if self.name:
@ -133,6 +131,50 @@ class Tournament(models.Model):
def live_group_stages(self): def live_group_stages(self):
return [gs.live_group_stages() for gs in self.groupstage_set.all()] return [gs.live_group_stages() for gs in self.groupstage_set.all()]
def live_matches(self):
matches = []
last_started_match = self.last_match()
current_round = last_started_match.round
if current_round:
previous_round = self.round_for_index(current_round.index - 1)
if previous_round:
matches.extend(current_round.all_matches())
matches.extend(previous_round.all_matches())
else:
matches.extend(current_round.all_matches())
# todo on veut les matchs du round et les poules, comment ça marche ?
# dans le monde idéal on veut afficher plusieurs pages de plusieurs types différents
# est-ce que je construis un json avec des types différents dans un même array ?
# je veux pas que des types différents apparaissent sur une même page
else:
matches = self.group_stages_matches()
return matches
def last_match(self):
matches = []
for round in self.round_set.all():
matches.extend(round.match_set.all())
for group_stage in self.groupstage_set.all():
matches.extend(group_stage.match_set.all())
matches = [m for m in matches if m.start_date]
matches.sort(key=lambda m: -m.start_date)
return matches[0]
def round_for_index(self, index):
return self.round_set.filter(index=index).first()
def group_stages_matches(self):
matches = []
for group_stage in self.groupstage_set.all():
matches.extend(group_stage.match_set.all())
matches = [m for m in matches if m.should_appear()]
matches.sort(key=lambda m: -m.start_date)
return matches
class MatchGroup: class MatchGroup:
def __init__(self, name, matches): def __init__(self, name, matches):
self.name = name self.name = name

Loading…
Cancel
Save