22first level class
33"""
44import enum
5- from email .policy import default
65import json
7- from random import choices
8-
9- from numpy import require
106
117from database .db import db , CustomQuerySet
128
@@ -27,29 +23,29 @@ class Match(db.Document):
2723 player_dist1 = db .ListField (db .IntField ())
2824 player_dist2 = db .ListField (db .IntField ())
2925 # allies or axis
30- side1 = db .StringField (choices = ('Axis' , 'Allies' ))
31- side2 = db .StringField (choices = ('Axis' , 'Allies' ))
26+ side1 = db .StringField (choices = ('Axis' , 'Allies' ))
27+ side2 = db .StringField (choices = ('Axis' , 'Allies' ))
3228 # strong points hold at the end of the game
33- caps1 = db .IntField (required = True , choices = (0 , 1 , 2 , 3 , 4 , 5 ))
34- caps2 = db .IntField (required = True , choices = (0 , 1 , 2 , 3 , 4 , 5 ))
29+ caps1 = db .IntField (required = True , choices = (0 , 1 , 2 , 3 , 4 , 5 ))
30+ caps2 = db .IntField (required = True , choices = (0 , 1 , 2 , 3 , 4 , 5 ))
3531 # number of players on each side (assuming both teams had the same number of players)
36- players = db .IntField ()
37- map = db .StringField (required = True )
32+ players = db .IntField ()
33+ map = db .StringField (required = True )
3834 strongpoints = db .ListField (db .StringField (), max_length = 5 )
39- date = db .DateTimeField (required = True )
35+ date = db .DateTimeField (required = True )
4036 # how long the game lasted, max is 90 min
41- duration = db .IntField ()
37+ duration = db .IntField ()
4238 # competitive factor, see HeLO calculations
43- factor = db .FloatField (default = 1.0 )
39+ factor = db .FloatField (default = 1.0 )
4440 # name of the tournament, of just a training match
45- event = db .StringField ()
41+ event = db .StringField ()
4642 # confirmation, very important
4743 # match must be confirmed from both sides (representatives) in order to
4844 # take the match into account
4945 # user id of the user who confirmed the match for clan1
50- conf1 = db .StringField ()
46+ conf1 = db .StringField ()
5147 # user id of the user who confirmed the match for clan2
52- conf2 = db .StringField ()
48+ conf2 = db .StringField ()
5349 # flag to check whether corresponding score objects to the match exist or not
5450 score_posted = db .BooleanField ()
5551 # reserved for admins, necessary to start a recalculate process for this match
@@ -67,14 +63,19 @@ class Match(db.Document):
6763 }
6864
6965 def clean (self ):
70- if self .player_dist1 is not None or self .player_dist2 is not None :
71- if sum (self .player_dist1 ) > 50 or sum (self .player_dist2 ) > 50 :
72- raise ValueError ("player distributions cannot exceed 50 players" )
73- if self .players > 100 :
74- raise ValueError ("players cannot exceed 100 players" )
66+ if self .__playerCount () > 100 :
67+ raise ValueError ("player_dist cannot exceed 100 players" )
68+
7569 if (self .player_dist1 is not None or self .player_dist2 is not None ) and self .players != 0 :
7670 raise ValueError ("players and player distributions cannot both be set" )
7771
72+ def __playerCount (self ):
73+ if self .players != 0 :
74+ return self .players
75+ if self .player_dist1 is not None and self .player_dist2 is not None :
76+ return sum (self .player_dist1 , sum (self .player_dist2 ))
77+ raise ValueError ("neither players, not player_dist1 and player_dist2 are set" )
78+
7879 def needs_confirmations (self ):
7980 if (self .conf1 != "" and self .conf1 is not None ) and (self .conf2 != "" and self .conf2 is not None ):
8081 # do the calcs then
@@ -105,4 +106,5 @@ def can_be_deleted(self, user_id: str, user_clans: list[str]) -> bool:
105106 if r in self .clans2_ids :
106107 is_clan2_member = True
107108
108- return not self .score_posted and (is_clan1_member or is_clan2_member or self .conf1 == user_id and self .conf2 == user_id )
109+ return not self .score_posted and (
110+ is_clan1_member or is_clan2_member or self .conf1 == user_id and self .conf2 == user_id )
0 commit comments