Skip to content

Commit f50c7ad

Browse files
committed
add bo type selection when creating swiss round matchs
1 parent 89467ae commit f50c7ad

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

insalan/tournament/manage/swiss.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from ..models import Team, Tournament, SwissRound, SwissMatch, SwissSeeding
1+
from ..models import Team, Tournament, SwissRound, SwissMatch, SwissSeeding, BestofType
22
from math import ceil
33
from random import shuffle
44

5-
def create_swiss_matchs(swiss: SwissRound):
5+
def create_swiss_matchs(swiss: SwissRound, bo_type):
66
teams = swiss.get_sorted_teams()
77
team_per_match = swiss.tournament.get_game().get_team_per_match()
88
nb_matchs = ceil(len(teams)/team_per_match)
@@ -17,7 +17,7 @@ def create_swiss_matchs(swiss: SwissRound):
1717
# first round
1818
matchs = []
1919
for match_idx in range(nb_matchs):
20-
matchs.append(SwissMatch.objects.create(round_number=1,index_in_round=match_idx+1,swiss=swiss,score_group=0))
20+
matchs.append(SwissMatch.objects.create(round_number=1,index_in_round=match_idx+1,swiss=swiss,score_group=0, bo_type=bo_type))
2121

2222
matchs_per_score_group_per_round.append([nb_matchs])
2323

@@ -32,20 +32,20 @@ def create_swiss_matchs(swiss: SwissRound):
3232
match_idx = 0
3333

3434
for idx in range(ceil(matchs_per_score_group_per_round[round_idx - 1][0] / 2)):
35-
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=idx + 1,swiss=swiss,score_group=0)
35+
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=idx + 1,swiss=swiss,score_group=0, bo_type=bo_type)
3636

3737
match_idx += idx + 1
3838
matchs_per_score_group_per_round.append([match_idx])
3939

4040
for j in range(round_idx - 1):
4141
for idx in range(ceil(sum(matchs_per_score_group_per_round[round_idx - 1][j:j+2]) / 2)):
42-
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=match_idx + idx + 1,swiss=swiss,score_group=j+1)
42+
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=match_idx + idx + 1,swiss=swiss,score_group=j+1, bo_type=bo_type)
4343

4444
matchs_per_score_group_per_round[-1].append(idx+1)
4545
match_idx += idx + 1
4646

4747
for idx in range(ceil(matchs_per_score_group_per_round[round_idx - 1][-1] / 2)):
48-
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=match_idx + idx + 1,swiss=swiss,score_group=round_idx)
48+
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=match_idx + idx + 1,swiss=swiss,score_group=round_idx, bo_type=bo_type)
4949

5050
matchs_per_score_group_per_round[-1].append(idx+1)
5151

@@ -57,12 +57,12 @@ def create_swiss_matchs(swiss: SwissRound):
5757

5858
for j in range(2*swiss.min_score - round_idx - 1):
5959
for idx in range(ceil(sum(matchs_per_score_group_per_round[round_idx - 1][j:j+2]) / 2)):
60-
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=match_idx + idx + 1,swiss=swiss,score_group=j)
60+
SwissMatch.objects.create(round_number=round_idx+1,index_in_round=match_idx + idx + 1,swiss=swiss,score_group=j, bo_type=bo_type)
6161

6262
matchs_per_score_group_per_round[-1].append(idx+1)
6363
match_idx += idx + 1
6464

65-
def create_swiss_rounds(tournament: Tournament, min_score: int, use_seeding: bool):
65+
def create_swiss_rounds(tournament: Tournament, min_score: int, use_seeding: bool, bo_type: BestofType):
6666
teams = tournament.teams.filter(validated=True)
6767
swiss = SwissRound.objects.create(tournament=tournament, min_score=min_score)
6868

@@ -75,7 +75,7 @@ def create_swiss_rounds(tournament: Tournament, min_score: int, use_seeding: boo
7575
if team != None:
7676
SwissSeeding.objects.create(swiss=swiss, seeding=0, team=team)
7777

78-
create_swiss_matchs(swiss)
78+
create_swiss_matchs(swiss, bo_type)
7979

8080
def get_winners_loosers_per_score_group(matchs_per_score_group):
8181
winners_per_score_group, loosers_per_score_group = [], []

insalan/tournament/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class CreateSwissRoundsSerializer(serializers.Serializer):
204204
tournament = serializers.PrimaryKeyRelatedField(queryset=Tournament.objects.all())
205205
min_score = serializers.IntegerField(min_value=1)
206206
use_seeding = serializers.BooleanField()
207+
bo_type = serializers.ChoiceField(BestofType)
207208

208209
class GenerateSwissRoundRoundSerializer(serializers.Serializer):
209210
tournament = serializers.PrimaryKeyRelatedField(queryset=Tournament.objects.all())

0 commit comments

Comments
 (0)