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