forked from rspeer/dominionstats
-
Notifications
You must be signed in to change notification settings - Fork 17
/
small_gain_stat.py
38 lines (31 loc) · 1.38 KB
/
small_gain_stat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from primitive_util import ListSlotPrimitiveConversion
from stats import MeanVarStat
class SmallGainStat(ListSlotPrimitiveConversion):
__slots__ = ('win_given_any_gain',
'win_given_no_gain',
'win_weighted_gain')
def __init__(self):
self.win_given_any_gain = MeanVarStat()
self.win_given_no_gain = MeanVarStat()
self.win_weighted_gain = MeanVarStat()
def merge(self, other):
self.win_given_any_gain.merge(other.win_given_any_gain)
self.win_given_no_gain.merge(other.win_given_no_gain)
self.win_weighted_gain.merge(other.win_weighted_gain)
def avail(self):
return self.win_given_any_gain.freq() + self.win_given_no_gain.freq()
def __str__(self):
return 'a <%s> n <%s> w <%s>' % (self.win_given_any_gain,
self.win_given_no_gain,
self.win_weighted_gain)
def to_readable_primitive_object(self):
ret = {}
for name in self.__slots__:
ret[name] = getattr(self, name).to_primitive_object()
return ret
def from_raw_stats_dict(raw_stats_dict):
ret = SmallGainStat()
ret.win_given_any_gain = raw_stats_dict['win_given_any_gain']
ret.win_given_no_gain = raw_stats_dict['win_given_no_gain']
ret.win_weighted_gain = raw_stats_dict['win_weighted_gain']
return ret