1
- from ..models import Team , Tournament , SwissRound , SwissMatch , SwissSeeding
1
+ from ..models import Team , Tournament , SwissRound , SwissMatch , SwissSeeding , BestofType
2
2
from math import ceil
3
3
from random import shuffle
4
4
5
- def create_swiss_matchs (swiss : SwissRound ):
5
+ def create_swiss_matchs (swiss : SwissRound , bo_type ):
6
6
teams = swiss .get_sorted_teams ()
7
7
team_per_match = swiss .tournament .get_game ().get_team_per_match ()
8
8
nb_matchs = ceil (len (teams )/ team_per_match )
@@ -17,7 +17,7 @@ def create_swiss_matchs(swiss: SwissRound):
17
17
# first round
18
18
matchs = []
19
19
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 ))
21
21
22
22
matchs_per_score_group_per_round .append ([nb_matchs ])
23
23
@@ -32,20 +32,20 @@ def create_swiss_matchs(swiss: SwissRound):
32
32
match_idx = 0
33
33
34
34
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 )
36
36
37
37
match_idx += idx + 1
38
38
matchs_per_score_group_per_round .append ([match_idx ])
39
39
40
40
for j in range (round_idx - 1 ):
41
41
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 )
43
43
44
44
matchs_per_score_group_per_round [- 1 ].append (idx + 1 )
45
45
match_idx += idx + 1
46
46
47
47
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 )
49
49
50
50
matchs_per_score_group_per_round [- 1 ].append (idx + 1 )
51
51
@@ -57,12 +57,12 @@ def create_swiss_matchs(swiss: SwissRound):
57
57
58
58
for j in range (2 * swiss .min_score - round_idx - 1 ):
59
59
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 )
61
61
62
62
matchs_per_score_group_per_round [- 1 ].append (idx + 1 )
63
63
match_idx += idx + 1
64
64
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 ):
66
66
teams = tournament .teams .filter (validated = True )
67
67
swiss = SwissRound .objects .create (tournament = tournament , min_score = min_score )
68
68
@@ -75,7 +75,7 @@ def create_swiss_rounds(tournament: Tournament, min_score: int, use_seeding: boo
75
75
if team != None :
76
76
SwissSeeding .objects .create (swiss = swiss , seeding = 0 , team = team )
77
77
78
- create_swiss_matchs (swiss )
78
+ create_swiss_matchs (swiss , bo_type )
79
79
80
80
def get_winners_loosers_per_score_group (matchs_per_score_group ):
81
81
winners_per_score_group , loosers_per_score_group = [], []
0 commit comments