Fix group stage team sort and results

clubs
Laurent 2 years ago
parent 0da7ce0bdc
commit 4385232017
  1. 65
      tournaments/models/group_stage.py

@ -43,40 +43,47 @@ class GroupStage(models.Model):
team_scores = match.team_scores.all()
if len(team_scores) == 2:
for team_score in match.team_scores.all():
team_registration = team_score.team_registration
if team_registration in gs_teams:
team = gs_teams[team_registration]
if match.winning_team_id == team_registration.id:
team.wins += 1
else:
team.losses += 1
ts1 = team_scores[0]
ts2 = team_scores[1]
scores1 = ts1.scores()
scores2 = ts2.scores()
total1 = 0
total2 = 0
if len(scores1) == len(scores2):
if len(scores1) > 1: # multiple sets
for i in range(len(scores1)):
if scores1[i] > scores2[i]:
total1 += 1
if len(scores1) == len(scores2) and len(scores1) > 0:
for team_score in match.team_scores.all():
team_registration = team_score.team_registration
if team_registration in gs_teams:
team = gs_teams[team_registration]
if match.winning_team_id == team_registration.id:
team.wins += 1
else:
total2 += 1
elif len(scores1) == 1:
total1 = scores1[0]
total2 = scores2[0]
if ts1.team_registration in gs_teams and ts2.team_registration in gs_teams:
team1 = gs_teams[ts1.team_registration]
team2 = gs_teams[ts2.team_registration]
team1.diff = total1 - total2
team2.diff = total2 - total1
teams = sorted(gs_teams.values(), key=lambda t: t.position)
team.losses += 1
total1 = 0
total2 = 0
if len(scores1) == len(scores2):
if len(scores1) > 1: # multiple sets
for i in range(len(scores1)):
if scores1[i] > scores2[i]:
total1 += 1
else:
total2 += 1
elif len(scores1) == 1:
total1 = scores1[0]
total2 = scores2[0]
if ts1.team_registration in gs_teams and ts2.team_registration in gs_teams:
team1 = gs_teams[ts1.team_registration]
team2 = gs_teams[ts2.team_registration]
team1.diff = total1 - total2
team2.diff = total2 - total1
if len(self.match_set.all()) == 0:
teams = sorted(gs_teams.values(), key=lambda team: team.position)
else:
teams = sorted(gs_teams.values(), key=lambda team: -team.wins)
for team in teams:
lgs.add_team(team)
return lgs

Loading…
Cancel
Save