|
|
|
|
@ -4,6 +4,7 @@ from django.contrib.auth.models import AbstractUser |
|
|
|
|
from django.conf import settings |
|
|
|
|
import uuid |
|
|
|
|
import os |
|
|
|
|
from django.utils import timezone |
|
|
|
|
|
|
|
|
|
from django.utils.encoding import Promise |
|
|
|
|
|
|
|
|
|
@ -254,6 +255,64 @@ class Match(models.Model): |
|
|
|
|
return "no date" |
|
|
|
|
# return str(self.start_date) #.strftime("%H:%M") |
|
|
|
|
|
|
|
|
|
def current_duration(self): |
|
|
|
|
if self.end_date: |
|
|
|
|
return (self.end_date - self.start_date).total_seconds() |
|
|
|
|
else: |
|
|
|
|
return (timezone.now() - self.start_date).total_seconds() |
|
|
|
|
|
|
|
|
|
def durationPrefix(self): |
|
|
|
|
if self.current_duration() > 0: |
|
|
|
|
return "Temps de jeu" |
|
|
|
|
else: |
|
|
|
|
return "Démarrage prévu dans" |
|
|
|
|
|
|
|
|
|
def formatted_duration(self): |
|
|
|
|
|
|
|
|
|
_seconds = self.current_duration() |
|
|
|
|
|
|
|
|
|
if _seconds > 0: |
|
|
|
|
_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" |
|
|
|
|
|
|
|
|
|
# def seconds(self): |
|
|
|
|
# return (timezone.now() - self.start_date).total_seconds() |
|
|
|
|
|
|
|
|
|
def live_match(self): |
|
|
|
|
title = f"{self.index}" |
|
|
|
|
date = self.formatted_start_date() |
|
|
|
|
duration = self.formatted_duration() |
|
|
|
|
|
|
|
|
|
livematch = LiveMatch(title, date, duration) |
|
|
|
|
|
|
|
|
|
for team_state in self.team_states: |
|
|
|
|
|
|
|
|
|
image = team_state.team_registration.logo |
|
|
|
|
names = team_state.team_names() |
|
|
|
|
scores = team_state.score |
|
|
|
|
weight = team_state.weight |
|
|
|
|
is_winner = False |
|
|
|
|
team = Team(image, names, scores, weight, is_winner) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
# def __init__(self, image, names, scores, weight, is_winner): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def __init__(self, title, date, teams, duration): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TeamRegistration(models.Model): |
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) |
|
|
|
|
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) |
|
|
|
|
@ -322,6 +381,7 @@ class TeamState(models.Model): |
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) |
|
|
|
|
match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name="team_states") |
|
|
|
|
player_registrations = models.ManyToManyField(PlayerRegistration, blank=True) |
|
|
|
|
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.CASCADE, null=True, blank=True) |
|
|
|
|
score = models.CharField(max_length=50, null=True, blank=True) |
|
|
|
|
walk_out = models.IntegerField(null=True, blank=True) #id, int of the walked_out team |
|
|
|
|
lucky_loser = models.BooleanField() |
|
|
|
|
@ -333,13 +393,36 @@ class TeamState(models.Model): |
|
|
|
|
names = map(lambda player: player.name(), self.player_registrations.all()) |
|
|
|
|
return " - ".join(names) |
|
|
|
|
|
|
|
|
|
# class StageCall: |
|
|
|
|
# def __init__(self, stage): |
|
|
|
|
# self.stage = stage |
|
|
|
|
# self.team_calls = [] |
|
|
|
|
def team_names(self): |
|
|
|
|
names = [] |
|
|
|
|
if self.team_registration.name: |
|
|
|
|
names.append(self.team_registration.name) |
|
|
|
|
else: |
|
|
|
|
names = self.player_names() |
|
|
|
|
|
|
|
|
|
class Team: |
|
|
|
|
def __init__(self, image, names, scores, weight, is_winner): |
|
|
|
|
self.image = image |
|
|
|
|
self.names = [] |
|
|
|
|
self.scores = [] |
|
|
|
|
self.weight = weight |
|
|
|
|
self.is_winner = is_winner |
|
|
|
|
|
|
|
|
|
def add_names(self, name): |
|
|
|
|
self.names.append(name) |
|
|
|
|
|
|
|
|
|
def add_set_score(self, score): |
|
|
|
|
self.scores.append(score) |
|
|
|
|
|
|
|
|
|
class LiveMatch: |
|
|
|
|
def __init__(self, title, date, duration): |
|
|
|
|
self.title = title |
|
|
|
|
self.date = date |
|
|
|
|
self.teams = [] |
|
|
|
|
self.duration = duration |
|
|
|
|
|
|
|
|
|
# def add_team(self, team_call): |
|
|
|
|
# self.team_calls.append(team_call) |
|
|
|
|
def add_team(self, team): |
|
|
|
|
self.teams.append(team) |
|
|
|
|
|
|
|
|
|
class TeamCall: |
|
|
|
|
def __init__(self, names, date, weight, stage, image): |
|
|
|
|
|