diff --git a/tournaments/models/match.py b/tournaments/models/match.py index 4dc43fe..c0f22b2 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -345,13 +345,16 @@ class Match(SideStoreModel): return 'À venir...' def magic_duration(self): + return format_seconds(self.smart_time_played()) + + def smart_time_played(self): seconds = (self.end_date - self.start_date).total_seconds() average_duration = self.average_seconds_duration() if (average_duration / 2) > seconds or seconds > (average_duration * 2): seconds = average_duration - return format_seconds(seconds) + return seconds def average_seconds_duration(self): return 3 * 60 * self.total_number_of_games() diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 4be79ee..02575f7 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -5,6 +5,7 @@ from django.utils import timezone from .enums import RegistrationStatus from .player_enums import PlayerPaymentType from ..services.email_service import TournamentEmailService, TeamEmailType +from ..utils.extensions import format_seconds class TeamRegistration(SideStoreModel): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) @@ -205,6 +206,7 @@ class TeamRegistration(SideStoreModel): 'initial_stage': self.get_initial_stage(), 'matches_played': self.count_matches_played(), 'victory_ratio': self.calculate_victory_ratio(), + 'time_played': self.calculate_time_played(), 'team_rank': self.team_rank_label(), 'total_teams': self.total_teams(), } @@ -287,6 +289,13 @@ class TeamRegistration(SideStoreModel): def count_matches_played(self): return self.get_matches().filter(end_date__isnull=False).count() + def calculate_time_played(self): + total_seconds = 0 + for match in self.get_matches().filter(end_date__isnull=False): + total_seconds += match.smart_time_played() + + return format_seconds(total_seconds) + def calculate_victory_ratio(self): matches = self.get_matches().filter(end_date__isnull=False) total_matches = matches.count() diff --git a/tournaments/templates/tournaments/team_stats.html b/tournaments/templates/tournaments/team_stats.html index 7a7fc56..55f9cd8 100644 --- a/tournaments/templates/tournaments/team_stats.html +++ b/tournaments/templates/tournaments/team_stats.html @@ -78,6 +78,19 @@ + {% if stats.time_played %} +