source: geniuswebcore/geniusweb/protocol/session/TeamInfo.py@ 94

Last change on this file since 94 was 90, checked in by Bart Vastenhouw, 3 years ago

Refactor to help reusing partiesserver.

File size: 1.8 KB
Line 
1from typing import List
2from pyson.JsonTypeInfo import Id, As
3from pyson.JsonTypeInfo import JsonTypeInfo
4
5from geniusweb.protocol.tournament.Team import Team
6from geniusweb.references.Parameters import Parameters
7from geniusweb.references.PartyWithProfile import PartyWithProfile
8
9
10@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
11class TeamInfo :
12 '''
13 Contains a functional team, eg in SHAOP a team would be a SHAOP together with
14 his COB partner. In SAOP this is just a SAOP party.
15 '''
16
17 def __init__(self, parties: List[PartyWithProfile]):
18 self._parties = parties
19
20
21 def getParties(self) ->List[PartyWithProfile] :
22 '''
23 @return the list of all parties involved, which is the parties in all
24 teams combined.
25 '''
26 return list(self._parties)
27
28
29 def getSize(self)-> int:
30 '''
31 @return the number of parties in the team.
32 '''
33 return len(self._parties)
34
35 def __repr__(self)->str:
36 return "TeamInfo[" +str( self._parties) + "]"
37
38 def __hash__(self):
39 return hash(tuple(self._parties))
40
41 def __eq__(self, other):
42 return isinstance(other, self.__class__) and \
43 self._parties == other._parties
44
45 def With(self, parameters:Parameters ) ->"TeamInfo" :
46 '''
47 @param parameters a set of {@link Parameters} to be merged with the
48 existing parameters of the first team member.
49 @return updated TeamInfo
50 '''
51 updatedparties = list(self._parties)
52 party1 = updatedparties[0]
53 newparams1 = party1.getParty().getParameters().WithParameters(parameters)
54 party1update = PartyWithProfile(
55 party1.getParty().With(newparams1), party1.getProfile())
56 updatedparties[0]= party1update
57 return TeamInfo(updatedparties)
58
59
60 def getTeam(self)->Team:
61 '''
62 @return the Team, without the profiles
63 '''
64 return Team ([party.getParty() for party in self._parties])
65
Note: See TracBrowser for help on using the repository browser.