source: geniuswebcore/geniusweb/protocol/session/SessionResult.py@ 93

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

Refactor to help reusing partiesserver.

File size: 3.1 KB
Line 
1from typing import Dict, Optional
2
3from geniusweb.actions.PartyId import PartyId
4from geniusweb.inform.Agreements import Agreements
5from geniusweb.references.PartyWithProfile import PartyWithProfile
6from geniusweb.utils import toStr, toTuple
7
8
9class SessionResult:
10 '''
11 All results collected from running a session. Normally this does not contain
12 all the details, only the final outcome and other global notes.
13 '''
14 def __init__(self, participants : Dict[PartyId, PartyWithProfile],
15 agreements:Agreements , penalties:Dict[PartyId, float] ,
16 error:Optional[Exception]):
17 '''
18 @param participants the list oof {@link PartyWithProfile}. Should never
19 be null. Some of them may have entered later of left
20 early. This list should contain them all.
21 @param agreements the final Agreements.
22 @param penalties the penalties in [0,1] for each participant.
23 @param error a fatal error that terminated the session. Non-fatal
24 errors (warnings) are not to be reported. Null if no
25 fatal error occured (session ended following the
26 protocol). Normally, a fatal error results in no
27 agreement but there might be protocols that allow a
28 session to end with an error but stick with a already
29 reached agreement as well.
30 '''
31 self._participants = dict(participants)
32 self._agreements = agreements
33 self._penalties = dict(penalties)
34 self._error = error
35
36 def getParticipants(self) ->Dict[PartyId, PartyWithProfile] :
37 '''
38 @return the map with for each {@link PartyId} the
39 {@link PartyWithProfile}. Should never be null. Some of them may
40 have entered later of left early. This list should contain them
41 all.
42 '''
43 return dict(self._participants)
44
45 def getAgreements(self) -> Agreements :
46 '''
47 @return the final {@link Agreements} of the session. May be empty, not
48 null
49 '''
50 return self._agreements;
51
52 def getPenalties(self ) -> Dict[PartyId, float] :
53 '''
54 @return Map of penalties,
55 '''
56 return dict(self._penalties)
57
58 def getError(self) -> Optional[Exception] :
59 '''
60 @return a fatal error that terminated the session. Non-fatal errors
61 (warnings) are not to be reported. Null if no fatal error occured
62 (session ended following the protocol). Normally, a fatal error
63 results in no agreement but there might be protocols that allow a
64 session to end with an error but stick with a already reached
65 agreement as well.
66 '''
67 return self._error
68
69 def __repr__(self)->str:
70 return "SessionResult[" + toStr(self._participants) + "," + str(self._agreements) + ","\
71 + toStr(self._penalties) + "," + str(self._error) + "]"
72
73 def __hash__(self):
74 return hash(( toTuple(self._participants ), toTuple(self._penalties ), self._agreements))
75
76 def __eq__(self, other):
77 return isinstance(other, self.__class__) and \
78 self._participants == other._participants and \
79 self._agreements == other._agreements and\
80 self._penalties == other._penalties and \
81 self._error == other._error
Note: See TracBrowser for help on using the repository browser.