Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit da43fe8

Browse files
committedFeb 17, 2025·
improve match's scores validation
1 parent 2ee6cbd commit da43fe8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
 

‎insalan/tournament/models/match.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def get_winners_loosers(self) -> List[List[int]]:
119119
scores = self.get_scores()
120120

121121
for team in self.get_teams_id():
122-
if self.bo_type == BestofType.RANKING and scores[team] <= self.get_winning_score():
122+
if self.bo_type == BestofType.RANKING and scores[team] > 0 and scores[team] <= self.get_winning_score():
123123
winners.append((team,scores[team]))
124124
elif self.bo_type != BestofType.RANKING and scores[team] >= self.get_winning_score():
125125
winners.append((team,scores[team]))

‎insalan/tournament/models/validators.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def tournament_registration_full(tournament: "Tournament", exclude=None):
6565
return False
6666

6767
def validate_match_data(match: "Match", data):
68+
winning_score = match.get_winning_score()
69+
winner_count = 0
70+
max_score = match.get_max_score()
71+
6872
if match.status != Match.MatchStatus.ONGOING:
6973
return {
7074
"status" : "Le match n'est pas en cours"
@@ -81,11 +85,30 @@ def validate_match_data(match: "Match", data):
8185
}
8286

8387
for _,score in data["score"].items():
84-
if score > match.get_max_score():
88+
if score > max_score:
8589
return {
8690
"score" : "Le score d'une équipe est trop grand"
8791
}
8892

93+
if score < 0:
94+
return {
95+
"score": "Le score d'une équipe ne peut pas être négatif."
96+
}
97+
98+
if match.bo_type == Match.BestofType.RANKING and score <= winning_score:
99+
winner_count += 1
100+
elif match.bo_type != Match.BestofType.RANKING and score >= winning_score:
101+
winner_count += 1
102+
103+
if (
104+
(match.bo_type == Match.BestofType.RANKING and winner_count != ceil(match.get_team_count()))
105+
or
106+
(match.bo_type != Match.BestofType.RANKING and winner_count != 1)
107+
) :
108+
return {
109+
"score": "Scores incomplets, il y a trop ou pas assez de gagnants."
110+
}
111+
89112
return None
90113

91114
def valid_name(game_param: "game", name: str):

0 commit comments

Comments
 (0)
Please sign in to comment.