-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccumulator.py
59 lines (46 loc) · 1.78 KB
/
accumulator.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sims4.commands, services
from sims4.commands import CommandType, CommandRestrictionFlags, Output
import PublicUnlock, sims4.log
_normal_logger = sims4.log.LoggerClass('Interactions')
logger = _normal_logger
class CommandsChanged:
__qualname__ = 'CommandsChanged'
ComList = {}
@PublicUnlock.rewrite(sims4.commands, 'Command')
def tm_allcheats_command_write(target, *aliases, command_type=CommandType.DebugOnly, command_restrictions=CommandRestrictionFlags.UNRESTRICTED, pack=None, console_type=None):
logger.info('this runs second')
CommandsChanged.ComList[aliases[0]] = str(command_type)
s = target(*aliases, command_type=CommandType.Live, command_restrictions=CommandRestrictionFlags.UNRESTRICTED, pack=None, console_type=None)
logger.info('this runs third')
return s
@PublicUnlock.rewrite(Output, '__call__')
def tm_allcheats_output_write(target, self, s):
logger.info('Hit class output')
return sims4.commands.cheat_output(s, self._context)
@PublicUnlock.rewrite(sims4.commands, 'output')
def tm_allcheats_output_write(target, s, context):
logger.info('Hit plain output')
return sims4.commands.cheat_output(s, context)
class HarmonicMeanAccumulator:
__qualname__ = 'HarmonicMeanAccumulator'
def __init__(self, seq=None):
self._fault = False
self.num_items = 0
self.total = 0
if seq is not None:
for value in seq:
while not self.fault():
self.add(value)
def add(self, value):
if value <= 0:
self._fault = True
return
def fault(self):
return self._fault
def value(self):
try:
if self._fault:
return 0
return self.num_items / self.total
except:
return 0