Skip to content

Commit 2ab31af

Browse files
committed
Clean up and document the new APMTracker.
closes #106
1 parent aa5a5ab commit 2ab31af

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

sc2reader/plugins/replay.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,29 @@ def toDict(replay):
9090

9191
@plugin
9292
def APMTracker(replay):
93+
"""
94+
Builds ``player.aps`` and ``player.apm`` dictionaries where an action is
95+
any Selection, Hotkey, or Ability event.
96+
97+
Also provides ``player.avg_apm`` which is defined as the sum of all the
98+
above actions divided by the number of seconds played by the player (not
99+
necessarily the whole game) multiplied by 60.
100+
"""
93101
for player in replay.players:
94102
player.aps = defaultdict(int)
95103
player.apm = defaultdict(int)
96-
player.seconds_played = replay.length.seconds
104+
seconds_played = replay.length.seconds
97105

98106
for event in player.events:
99107
if event.name == 'SelectionEvent' or 'AbilityEvent' in event.name or 'Hotkey' in event.name:
100108
player.aps[event.second] += 1
101109
player.apm[event.second/60] += 1
102110

103-
if event.name == 'PlayerLeaveEvent':
104-
player.seconds_played = event.second
105-
break
111+
elif event.name == 'PlayerLeaveEvent':
112+
seconds_played = event.second
106113

107114
if len(player.apm) > 0:
108-
player.avg_apm = sum(player.apm.values())/float(player.seconds_played)*60
115+
player.avg_apm = sum(player.aps.values())/float(seconds_played)*60
109116
else:
110117
player.avg_apm = 0
111118

0 commit comments

Comments
 (0)