Skip to content

Commit

Permalink
stats: Change ratio only on score change
Browse files Browse the repository at this point in the history
  • Loading branch information
SibiAkkash committed Nov 29, 2024
1 parent 1112403 commit c853cbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
18 changes: 9 additions & 9 deletions server/tournament/match_stats_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ def handle_score(
if team.id != match.stats.current_possession.id:
return 422, {"message": "Team does not match the team in current possession"}

# previous_score_events = MatchEvent.objects.filter(stats=match.stats, team=team, type=MatchEvent.EventType.SCORE).order_by("-time")

# if not previous_score_events:
# team_that_started_on_offense = match.stats.initial_possession.id
# started_on = MatchEvent.Mode.OFFENSE if team.id == team_that_started_on_offense else MatchEvent.Mode.DEFENSE
# else:
# latest_score_event = previous_score_events[0]
# started_on =

new_match_event = MatchEvent(
stats=match.stats,
team=team,
Expand All @@ -92,6 +83,15 @@ def handle_score(
match.stats.score_team_2 += 1
match.stats.current_possession = match.team_1

score_sum = match.stats.score_team_1 + match.stats.score_team_2

# Change ratio when sum of score is odd
if score_sum % 2 == 1:
if match.stats.current_ratio == MatchStats.GenderRatio.MALE:
match.stats.current_ratio = MatchStats.GenderRatio.FEMALE
elif match.stats.current_ratio == MatchStats.GenderRatio.FEMALE:
match.stats.current_ratio = MatchStats.GenderRatio.MALE

match.stats.save()

return 200, match.stats
Expand Down
16 changes: 1 addition & 15 deletions server/tournament/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from django.db import models
from django.db.models.signals import m2m_changed, pre_save
from django.db.models.signals import m2m_changed
from django.dispatch import receiver
from django.utils.translation import gettext_lazy as _
from django_prometheus.models import ExportModelOperationsMixin
Expand Down Expand Up @@ -352,20 +352,6 @@ class GenderRatio(models.TextChoices):
)


@receiver(pre_save, sender=MatchStats)
def match_stats_ratio_callback(
sender: Any, instance: MatchStats, *args: Any, **kwargs: Any
) -> None:
score_sum = instance.score_team_1 + instance.score_team_2

# Change ratio when sum of score is odd
if score_sum % 2 == 1:
if instance.current_ratio == MatchStats.GenderRatio.MALE:
instance.current_ratio = MatchStats.GenderRatio.FEMALE
elif instance.current_ratio == MatchStats.GenderRatio.FEMALE:
instance.current_ratio = MatchStats.GenderRatio.MALE


class MatchEvent(models.Model):
class EventType(models.TextChoices):
LINE_SELECTED = "LS", _("Line Selected")
Expand Down

0 comments on commit c853cbf

Please sign in to comment.