Improvements in broadcasted match display

clubs
Laurent 1 year ago
parent 6b8b3315a5
commit 36580db18a
  1. 7
      tournaments/models/group_stage.py
  2. 3
      tournaments/models/match.py
  3. 31
      tournaments/models/tournament.py
  4. 2
      tournaments/views.py

@ -95,6 +95,13 @@ class GroupStage(models.Model):
lgs.add_team(team) lgs.add_team(team)
return lgs return lgs
def starts_soon(self):
if self.start_date:
early_start = self.start_date - timedelta(minute=30)
return datetime.now() > early_start
else:
return False
class LiveGroupStage: class LiveGroupStage:
def __init__(self, title): def __init__(self, title):
self.title = title self.title = title

@ -147,6 +147,9 @@ class Match(models.Model):
if self.disabled is True: if self.disabled is True:
return False return False
elif self.group_stage is None: elif self.group_stage is None:
if len(self.team_scores.all()) == 2:
return True
else:
return (self.start_date or self.end_date) and len(self.team_scores.all()) > 0 return (self.start_date or self.end_date) and len(self.team_scores.all()) > 0
else: else:
return len(self.team_scores.all()) > 0 return len(self.team_scores.all()) > 0

@ -102,7 +102,9 @@ class Tournament(models.Model):
def filter_name(self): def filter_name(self):
components = [self.formatted_start_date(), self.short_base_name()] components = [self.formatted_start_date(), self.short_base_name()]
if self.event.name: if self.event and self.event.club and self.event.club.name:
components.append(self.event.club.name)
elif self.event.name:
components.append(self.event.name) components.append(self.event.name)
elif self.name: elif self.name:
components.append(self.name) components.append(self.name)
@ -337,7 +339,6 @@ class Tournament(models.Model):
else: else:
matches = [m for m in matches if m.disabled is False] matches = [m for m in matches if m.disabled is False]
if matches: if matches:
group = self.create_match_group(round.name(), matches, broadcasted) group = self.create_match_group(round.name(), matches, broadcasted)
groups.append(group) groups.append(group)
@ -360,7 +361,7 @@ class Tournament(models.Model):
live_matches = [match.live_match() for match in matches] live_matches = [match.live_match() for match in matches]
return MatchGroup(name, live_matches) return MatchGroup(name, live_matches)
def live_group_stages(self): def broadcasted_group_stages(self):
group_stages = list(self.groupstage_set.all()) group_stages = list(self.groupstage_set.all())
group_stages.sort(key=lambda gs: gs.index) group_stages.sort(key=lambda gs: gs.index)
return [gs.live_group_stages() for gs in group_stages] return [gs.live_group_stages() for gs in group_stages]
@ -400,8 +401,8 @@ class Tournament(models.Model):
group_stages = [] group_stages = []
if self.group_stages_running(): if self.group_stages_running():
group_stages = self.live_group_stages() group_stages = self.broadcasted_group_stages()
matches = self.group_stages_matches() matches = self.broadcasted_group_stages_matches()
else: else:
# last_started_match = self.first_unfinished_match() # last_started_match = self.first_unfinished_match()
current_round = self.round_to_show() current_round = self.round_to_show()
@ -413,7 +414,7 @@ class Tournament(models.Model):
matches.extend(previous_round.get_matches_recursive(True)) matches.extend(previous_round.get_matches_recursive(True))
else: else:
matches.extend(current_round.all_matches(True)) matches.extend(current_round.all_matches(True))
group_stages = self.live_group_stages() group_stages = self.broadcasted_group_stages()
return matches, group_stages return matches, group_stages
@ -471,16 +472,24 @@ class Tournament(models.Model):
def round_for_index(self, index): def round_for_index(self, index):
return self.round_set.filter(index=index, parent=None).first() return self.round_set.filter(index=index, parent=None).first()
def group_stages_matches(self): def broadcasted_group_stages_matches(self):
matches = [] matches = []
for group_stage in self.groupstage_set.all(): group_stages = self.elected_broadcast_group_stages()
group_stages.sort(key=lambda gs: (gs.index, gs.start_date is None, gs.start_date))
for group_stage in group_stages:
matches.extend(group_stage.match_set.all()) matches.extend(group_stage.match_set.all())
matches = [m for m in matches if m.should_appear()] matches = [m for m in matches if m.should_appear()]
# matches.sort(key=lambda m: (m.non_null_start_date(), m.index), reverse=True)
matches.sort(key=lambda m: (m.start_date is None, m.end_date is not None, m.start_date, m.index)) matches.sort(key=lambda m: (m.start_date is None, m.end_date is not None, m.start_date, m.index))
return matches return matches
def elected_broadcast_group_stages(self):
group_stages = list(self.groupstage_set.all())
started = [gs for gs in group_stages if gs.starts_soon()]
if len(started) > 0:
return started
else:
return group_stages
def display_rankings(self): def display_rankings(self):
if self.publish_rankings is True and self.end_date is not None: if self.publish_rankings is True and self.end_date is not None:
return True return True
@ -587,7 +596,7 @@ class Tournament(models.Model):
return date.replace(hour=8, minute=0, second=0, microsecond=0) return date.replace(hour=8, minute=0, second=0, microsecond=0)
def supposedly_in_progress(self): def supposedly_in_progress(self):
end = self.start_date + timedelta(days=self.day_duration + 2) end = self.start_date + timedelta(days=self.day_duration + 1)
return self.start_date.replace(hour=0, minute=0) <= timezone.now() <= end return self.start_date.replace(hour=0, minute=0) <= timezone.now() <= end
def display_points_earned(self): def display_points_earned(self):

@ -224,7 +224,7 @@ def tournament_broadcasted_group_stages(request, tournament_id):
def tournament_live_group_stage_json(request, tournament_id): def tournament_live_group_stage_json(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id) tournament = get_object_or_404(Tournament, pk=tournament_id)
gs_dicts = [gs.to_dict() for gs in tournament.live_group_stages()] gs_dicts = [gs.to_dict() for gs in tournament.broadcasted_group_stages()]
# group_stages = tournament.live_group_stages() # group_stages = tournament.live_group_stages()
data = json.dumps(gs_dicts) data = json.dumps(gs_dicts)
return HttpResponse(data, content_type='application/json') return HttpResponse(data, content_type='application/json')

Loading…
Cancel
Save