|
|
|
|
@ -5,6 +5,8 @@ from django.utils import timezone, formats |
|
|
|
|
from datetime import timedelta |
|
|
|
|
import uuid |
|
|
|
|
|
|
|
|
|
from ..utils.extensions import format_seconds |
|
|
|
|
|
|
|
|
|
class Match(models.Model): |
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) |
|
|
|
|
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE) |
|
|
|
|
@ -88,7 +90,7 @@ class Match(models.Model): |
|
|
|
|
def time_indication(self): |
|
|
|
|
if self.end_date: |
|
|
|
|
if self.start_date: |
|
|
|
|
return self.formatted_duration() |
|
|
|
|
return self.magic_duration() |
|
|
|
|
else: |
|
|
|
|
return '' |
|
|
|
|
elif self.start_date: |
|
|
|
|
@ -100,12 +102,36 @@ class Match(models.Model): |
|
|
|
|
else: |
|
|
|
|
return 'À venir...' |
|
|
|
|
|
|
|
|
|
def magic_duration(self): |
|
|
|
|
seconds = (self.end_date - self.start_date).total_seconds() |
|
|
|
|
average_duration = self.average_seconds_duration() |
|
|
|
|
# print(f"{average_duration} / {seconds}") |
|
|
|
|
|
|
|
|
|
if (average_duration / 2) > seconds or seconds > (average_duration * 2): |
|
|
|
|
seconds = average_duration |
|
|
|
|
|
|
|
|
|
return format_seconds(seconds) |
|
|
|
|
|
|
|
|
|
def average_seconds_duration(self): |
|
|
|
|
return 3 * 60 * self.total_number_of_games() |
|
|
|
|
|
|
|
|
|
def total_number_of_games(self): |
|
|
|
|
games = 0 |
|
|
|
|
for team_score in self.team_scores.all(): |
|
|
|
|
games += team_score.number_of_games() |
|
|
|
|
return games |
|
|
|
|
|
|
|
|
|
def current_duration(self): |
|
|
|
|
if self.start_date: |
|
|
|
|
if self.end_date: |
|
|
|
|
return (self.end_date - self.start_date).total_seconds() |
|
|
|
|
else: |
|
|
|
|
return (timezone.now() - self.start_date).total_seconds() |
|
|
|
|
current = (timezone.now() - self.start_date).total_seconds() |
|
|
|
|
if current < self.average_seconds_duration() * 2: |
|
|
|
|
return current |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
# return (timezone.now() - self.start_date).total_seconds() |
|
|
|
|
else: |
|
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
@ -127,17 +153,21 @@ class Match(models.Model): |
|
|
|
|
|
|
|
|
|
def formatted_duration(self): |
|
|
|
|
|
|
|
|
|
_seconds = self.current_duration() |
|
|
|
|
seconds = self.current_duration() |
|
|
|
|
if seconds is None: |
|
|
|
|
return '' |
|
|
|
|
|
|
|
|
|
if _seconds > 0: |
|
|
|
|
_hours = int(_seconds / 3600) |
|
|
|
|
_minutes = int((_seconds % 3600) / 60) |
|
|
|
|
return f"{_hours:02d}h{_minutes:02d}min" |
|
|
|
|
if seconds > 0: |
|
|
|
|
return format_seconds(seconds) |
|
|
|
|
# _hours = int(_seconds / 3600) |
|
|
|
|
# _minutes = int((_seconds % 3600) / 60) |
|
|
|
|
# return f"{_hours:02d}h{_minutes:02d}min" |
|
|
|
|
else : |
|
|
|
|
_seconds = _seconds * -1 |
|
|
|
|
_hours = int(_seconds / 3600) |
|
|
|
|
_minutes = int((_seconds % 3600) / 60) |
|
|
|
|
return f"{_hours:02d}h{_minutes:02d}min" |
|
|
|
|
seconds = seconds * -1 |
|
|
|
|
return format_seconds(seconds) |
|
|
|
|
# _hours = int(_seconds / 3600) |
|
|
|
|
# _minutes = int((_seconds % 3600) / 60) |
|
|
|
|
# return f"{_hours:02d}h{_minutes:02d}min" |
|
|
|
|
|
|
|
|
|
def live_match(self): |
|
|
|
|
title = self.name if self.name else self.backup_name() |
|
|
|
|
|