|
|
|
@ -2,14 +2,17 @@ from django.db import models |
|
|
|
from . import Round, GroupStage, FederalMatchCategory |
|
|
|
from . import Round, GroupStage, FederalMatchCategory |
|
|
|
from django.utils import timezone |
|
|
|
from django.utils import timezone |
|
|
|
import uuid |
|
|
|
import uuid |
|
|
|
|
|
|
|
from django.utils import formats |
|
|
|
|
|
|
|
|
|
|
|
class Match(models.Model): |
|
|
|
class Match(models.Model): |
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) |
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) |
|
|
|
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE) |
|
|
|
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE) |
|
|
|
|
|
|
|
name = models.CharField(max_length=200, null=True, blank=True) |
|
|
|
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.CASCADE) |
|
|
|
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.CASCADE) |
|
|
|
start_date = models.DateTimeField(null=True, blank=True) |
|
|
|
start_date = models.DateTimeField(null=True, blank=True) |
|
|
|
end_date = models.DateTimeField(null=True, blank=True) |
|
|
|
end_date = models.DateTimeField(null=True, blank=True) |
|
|
|
index = models.IntegerField(default=0) |
|
|
|
index = models.IntegerField(default=0) |
|
|
|
|
|
|
|
order = models.IntegerField(default=0) |
|
|
|
format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True) |
|
|
|
format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True) |
|
|
|
court = models.CharField(max_length=50, null=True, blank=True) |
|
|
|
court = models.CharField(max_length=50, null=True, blank=True) |
|
|
|
serving_team_id = models.UUIDField(null=True, blank=True) |
|
|
|
serving_team_id = models.UUIDField(null=True, blank=True) |
|
|
|
@ -18,8 +21,8 @@ class Match(models.Model): |
|
|
|
broadcasted = models.BooleanField(default=False) |
|
|
|
broadcasted = models.BooleanField(default=False) |
|
|
|
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
def __str__(self): |
|
|
|
|
|
|
|
match_name = self.name if self.name else self.backup_name() #"x is greater" if x > y else "y is greater" |
|
|
|
items = [self.name(), self.formatted_start_date()] |
|
|
|
items = [match_name, self.formatted_start_date()] |
|
|
|
desc = " - ".join(items) |
|
|
|
desc = " - ".join(items) |
|
|
|
player_names = " / ".join(self.player_names()) |
|
|
|
player_names = " / ".join(self.player_names()) |
|
|
|
if self.round: |
|
|
|
if self.round: |
|
|
|
@ -29,7 +32,7 @@ class Match(models.Model): |
|
|
|
else: |
|
|
|
else: |
|
|
|
return "--" |
|
|
|
return "--" |
|
|
|
|
|
|
|
|
|
|
|
def name(self): |
|
|
|
def backup_name(self): |
|
|
|
items = [] |
|
|
|
items = [] |
|
|
|
if self.round: |
|
|
|
if self.round: |
|
|
|
items.append(self.round.name()) |
|
|
|
items.append(self.round.name()) |
|
|
|
@ -64,16 +67,18 @@ class Match(models.Model): |
|
|
|
if self.started(): |
|
|
|
if self.started(): |
|
|
|
return self.formatted_duration() |
|
|
|
return self.formatted_duration() |
|
|
|
else: |
|
|
|
else: |
|
|
|
start = self.start_date.strftime("%H:%M") |
|
|
|
return formats.date_format(self.start_date, format='SHORT_DATETIME_FORMAT') |
|
|
|
return f"Prévu à {start}" |
|
|
|
# return self.start_date.strftime("%A %d %B à %H:%M") |
|
|
|
|
|
|
|
# return f"Prévu à {start}" |
|
|
|
else: |
|
|
|
else: |
|
|
|
return 'À venir...' |
|
|
|
return 'À venir...' |
|
|
|
|
|
|
|
|
|
|
|
def current_duration(self): |
|
|
|
def current_duration(self): |
|
|
|
if self.end_date: |
|
|
|
if self.start_date: |
|
|
|
return (self.end_date - self.start_date).total_seconds() |
|
|
|
if self.end_date: |
|
|
|
elif self.start_date: |
|
|
|
return (self.end_date - self.start_date).total_seconds() |
|
|
|
return (timezone.now() - self.start_date).total_seconds() |
|
|
|
else: |
|
|
|
|
|
|
|
return (timezone.now() - self.start_date).total_seconds() |
|
|
|
else: |
|
|
|
else: |
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
@ -101,7 +106,7 @@ class Match(models.Model): |
|
|
|
# return (timezone.now() - self.start_date).total_seconds() |
|
|
|
# return (timezone.now() - self.start_date).total_seconds() |
|
|
|
|
|
|
|
|
|
|
|
def live_match(self): |
|
|
|
def live_match(self): |
|
|
|
title = self.name() |
|
|
|
title = self.name |
|
|
|
date = self.formatted_start_date() |
|
|
|
date = self.formatted_start_date() |
|
|
|
duration = self.time_indication() |
|
|
|
duration = self.time_indication() |
|
|
|
court = "" |
|
|
|
court = "" |
|
|
|
@ -110,7 +115,7 @@ class Match(models.Model): |
|
|
|
|
|
|
|
|
|
|
|
livematch = LiveMatch(title, date, duration, court, self.started()) |
|
|
|
livematch = LiveMatch(title, date, duration, court, self.started()) |
|
|
|
|
|
|
|
|
|
|
|
for team_score in self.team_scores.all(): |
|
|
|
for team_score in self.sorted_team_scores(): |
|
|
|
image = team_score.team_registration.logo |
|
|
|
image = team_score.team_registration.logo |
|
|
|
names = team_score.team_names() |
|
|
|
names = team_score.team_names() |
|
|
|
scores = team_score.scores_array() |
|
|
|
scores = team_score.scores_array() |
|
|
|
@ -121,6 +126,19 @@ class Match(models.Model): |
|
|
|
|
|
|
|
|
|
|
|
return livematch |
|
|
|
return livematch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sorted_team_scores(self): |
|
|
|
|
|
|
|
return self.team_scores.order_by('team_registration__bracket_position') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def sort_value(self): |
|
|
|
|
|
|
|
# sort_score = 0 |
|
|
|
|
|
|
|
# if self.round.index: |
|
|
|
|
|
|
|
# sort_score += 1 / (self.round.index + 1) * 1000 ** 2 |
|
|
|
|
|
|
|
# if self.group_stage.index: |
|
|
|
|
|
|
|
# sort_score += 1 / (self.group_stage.index + 1) * 1000 |
|
|
|
|
|
|
|
# sort_score += self.index |
|
|
|
|
|
|
|
# print(sort_score) |
|
|
|
|
|
|
|
# return sort_score |
|
|
|
|
|
|
|
|
|
|
|
class Team: |
|
|
|
class Team: |
|
|
|
def __init__(self, image, names, scores, weight, is_winner): |
|
|
|
def __init__(self, image, names, scores, weight, is_winner): |
|
|
|
self.image = image |
|
|
|
self.image = image |
|
|
|
|