-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapm.py
More file actions
90 lines (75 loc) · 3.62 KB
/
apm.py
File metadata and controls
90 lines (75 loc) · 3.62 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals, division
from collections import defaultdict
class APMTracker(object):
"""
Builds ``player.aps`` and ``player.apm`` dictionaries where an action is
any Selection, ControlGroup, or Ability event.
Also provides ``player.avg_apm`` which is defined as the sum of all the
above actions divided by the number of seconds played by the player (not
necessarily the whole game) multiplied by 60.
APM is 0 for games under 1 minute in length.
"""
name = 'APMTracker'
def handleInitGame(self, event, replay):
for human in replay.humans:
human.apm = defaultdict(int) #actions per minute
human.aps = defaultdict(int) #actions per second
human.epm = defaultdict(int) #effective actions per minte
human.eps = defaultdict(int) #effective actions per second
human.spm = defaultdict(int) #spam actions per minute
human.sps = defaultdict(int) #spam actions per second
human.ipm = defaultdict(int) #ineffective actions per minute
human.ips = defaultdict(int) #inneffective actions per second
human.last_event = event; #The most recent action event
human.seconds_played = replay.length.seconds
def handleControlGroupEvent(self, event, replay):
event.player.aps[event.second] += 1
event.player.apm[int(event.second/60)] += 1
if event.player.last_event == event:
event.player.sps[event.second] += 1
event.player.spm[int(event.second/60)] += 1
else:
event.player.last_event = event
event.player.eps[event.second] += 1
event.player.epm[int(event.second/60)] += 1
def handleSelectionEvent(self, event, replay):
event.player.aps[event.second] += 1
event.player.apm[int(event.second/60)] += 1
if event.player.last_event == event:
event.player.sps[event.second] += 1
event.player.spm[int(event.second/60)] += 1
else:
event.player.last_event = event
event.player.eps[event.second] += 1
event.player.epm[int(event.second/60)] += 1
def handleAbilityEvent(self, event, replay):
event.player.aps[event.second] += 1
event.player.apm[int(event.second/60)] += 1
if event.player.last_event == event:
event.player.sps[event.second] += 1
event.player.spm[int(event.second/60)] += 1
else:
event.player.last_event = event
event.player.eps[event.second] += 1
event.player.epm[int(event.second/60)] += 1
def handlePlayerLeaveEvent(self, event, replay):
event.player.seconds_played = event.second
def handleEndGame(self, event, replay):
for human in replay.humans:
if len(human.apm.keys()) > 0:
human.avg_apm = sum(human.aps.values())/float(human.seconds_played)*60
else:
human.avg_apm = 0
if len(human.epm.keys()) > 0:
human.avg_epm = sum(human.eps.values())/float(human.seconds_played)*60
else:
human.avg_epm = 0
if len(human.spm.keys()) > 0:
human.avg_spm = sum(human.sps.values())/float(human.seconds_played)*60
else:
human.avg_spm = 0
if len(human.ipm.keys()) > 0:
human.avg_ipm = sum(human.ips.values())/float(human.seconds_played)*60
else:
human.avg_ipm = 0