add time played stat

sync_v2
Raz 6 months ago
parent c31b54c0cc
commit d15e43d84b
  1. 5
      tournaments/models/match.py
  2. 9
      tournaments/models/team_registration.py
  3. 13
      tournaments/templates/tournaments/team_stats.html

@ -345,13 +345,16 @@ class Match(SideStoreModel):
return 'À venir...' return 'À venir...'
def magic_duration(self): 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() seconds = (self.end_date - self.start_date).total_seconds()
average_duration = self.average_seconds_duration() average_duration = self.average_seconds_duration()
if (average_duration / 2) > seconds or seconds > (average_duration * 2): if (average_duration / 2) > seconds or seconds > (average_duration * 2):
seconds = average_duration seconds = average_duration
return format_seconds(seconds) return seconds
def average_seconds_duration(self): def average_seconds_duration(self):
return 3 * 60 * self.total_number_of_games() return 3 * 60 * self.total_number_of_games()

@ -5,6 +5,7 @@ from django.utils import timezone
from .enums import RegistrationStatus from .enums import RegistrationStatus
from .player_enums import PlayerPaymentType from .player_enums import PlayerPaymentType
from ..services.email_service import TournamentEmailService, TeamEmailType from ..services.email_service import TournamentEmailService, TeamEmailType
from ..utils.extensions import format_seconds
class TeamRegistration(SideStoreModel): class TeamRegistration(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
@ -205,6 +206,7 @@ class TeamRegistration(SideStoreModel):
'initial_stage': self.get_initial_stage(), 'initial_stage': self.get_initial_stage(),
'matches_played': self.count_matches_played(), 'matches_played': self.count_matches_played(),
'victory_ratio': self.calculate_victory_ratio(), 'victory_ratio': self.calculate_victory_ratio(),
'time_played': self.calculate_time_played(),
'team_rank': self.team_rank_label(), 'team_rank': self.team_rank_label(),
'total_teams': self.total_teams(), 'total_teams': self.total_teams(),
} }
@ -287,6 +289,13 @@ class TeamRegistration(SideStoreModel):
def count_matches_played(self): def count_matches_played(self):
return self.get_matches().filter(end_date__isnull=False).count() 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): def calculate_victory_ratio(self):
matches = self.get_matches().filter(end_date__isnull=False) matches = self.get_matches().filter(end_date__isnull=False)
total_matches = matches.count() total_matches = matches.count()

@ -78,6 +78,19 @@
</div> </div>
</div> </div>
{% if stats.time_played %}
<div class="match-result top-border">
<div class="player">
<div class="semibold">
<strong>Heures jouées</strong>
</div>
</div>
<div class="scores">
<span class="score ws numbers">{{ stats.time_played }}</span>
</div>
</div>
{% endif %}
{% if stats.victory_ratio %} {% if stats.victory_ratio %}
<div class="match-result top-border"> <div class="match-result top-border">
<div class="player"> <div class="player">

Loading…
Cancel
Save