-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.py
148 lines (118 loc) · 6.29 KB
/
team.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from enum import Enum
import dataconstants
# Stores and calculates data about a team, and outputs it in the format of the match strategy sheets
class Team:
partner = True
strat_header = 'team: cross | srt lvl | auto(h:c) | pre(h:c) |#| l h | l c | l r | h h | h c | defense |#| ' \
' attempt | success | time '
strat_form = '{team:4s}: {cross:3d}% | {start1:3d}:{start2:3d} | {autoh:4d}:{autoc:4d} | {preloadh:3d}:{' \
'preloadc:3d} |#| {lowh:3.1f} | {lowc:3.1f} | {lowr:1s} | {highh:3.1f} | {highc:3.1f} | {' \
'defensep:3d}:{defenses:1.1f} |#| {attempt1:3d}:{attempt2:3d}:{attempt3:3d} | {success2:3d}:{' \
'success3:3d} | {time2:2d}:{time3:2d} '
opp_header = 'team: l h | l c | h h | h c | drop(h:c) | climb | defense'
opp_form = '{team:4s}: {lowh:3.1f} | {lowc:3.1f} | {highh:3.1f} | {highc:3.1f} | ' \
'{droph:3.1f}:{dropc:3.1f} | {climb2:3d}:{climb3:3d} | {defensep:3d}:{defenses:1.1f}'
quick_form = '\033[7m\033[95m{team:4s}\033[0m SS:{autoh:3d}:{autoc:3d} H:{allhatch:2.1f} C:{allcargo:2.1f} ' \
'HI:{height:2s} EG:{success2:3d}:{success3:3d}'
detail_form = '\033[7m\033[95m{team:4s}\033[0m\n'
# noinspection PyArgumentList
Forms = Enum('Forms', 'strat quick detail')
total, lowh, lowc, highc, highh = 0, 0, 0, 0, 0
autocross, start1, start2, prec, preh, autoc, autoh = 0, 0, 0, 0, 0, 0, 0
droph, dropc = 0, 0
lowr = False
comments = ''
def __init__(self, team, partner=True):
self.team = team
self.defense = []
self.habattempt, self.habsuccess, self.climbtime = [0, 0, 0, 0], [0, 0, 0, 0], [[], []]
self.climb = [0, 0]
if not partner:
self.partner = False
self.strat_header, self.strat_form = self.opp_header, self.opp_form
def getteam(self):
return self.team
def getheader(self):
return self.strat_header
def getcomments(self):
return self.comments
def addline(self, line):
self.total += 1
self.autocross += int(line[dataconstants.MOVED_FORWARD])
self.start1 += line[dataconstants.STARTING_LEVEL] == '1'
self.start2 += line[dataconstants.STARTING_LEVEL] == '2'
if line[dataconstants.PRELOAD] == '1':
self.preh += 1
self.autoh += line[dataconstants.AUTO_PLACE] == '1'
elif line[dataconstants.PRELOAD] == '2':
self.prec += 1
self.autoc += line[dataconstants.AUTO_PLACE] == '1'
self.lowc += int(line[dataconstants.CSC]) + int(line[dataconstants.L1RC])
self.lowh += int(line[dataconstants.CSH]) + int(line[dataconstants.L1RH])
self.highc += int(line[dataconstants.L2RC]) + int(line[dataconstants.L3RC])
self.highh += int(line[dataconstants.L2RH]) + int(line[dataconstants.L3RH])
self.droph += int(line[dataconstants.DROP_HATCH])
self.dropc += int(line[dataconstants.DROP_CARGO])
if int(line[dataconstants.L1RH]) + int(line[dataconstants.L3RH]) + int(line[dataconstants.L1RH]):
self.lowr = True
attempt = int(line[dataconstants.HAB_ATTEMPT])
self.habattempt[attempt] += 1
self.habsuccess[attempt] += attempt == int(line[dataconstants.HAB_REACHED])
if int(line[dataconstants.HAB_SUCCESS]) > 1:
self.climbtime[int(line[dataconstants.HAB_REACHED]) - 2].append(int(line[dataconstants.CLIMB_TIME]))
self.climb[int(line[dataconstants.HAB_REACHED]) - 2] += 1
d = int(line[dataconstants.DEFENSE])
if d:
self.defense.append(d)
comment = line[dataconstants.COMMENTS]
if comment:
self.comments += comment + '\n\t'
def calcvalues(self):
return {'team': self.team,
'lowc': self.avg(self.lowc),
'lowh': self.avg(self.lowh),
'highc': self.avg(self.highc),
'highh': self.avg(self.highh),
'defensep': self.avg(len(self.defense), perc=True),
'defenses': self.avg(self.defense, itint=False),
'cross': self.avg(self.autocross, perc=True),
'start1': self.avg(self.start1, perc=True),
'start2': self.avg(self.start2, perc=True),
'preloadc': self.avg(self.prec, perc=True),
'preloadh': self.avg(self.preh, perc=True),
'autoc': self.percent(0 if not self.prec else self.autoc / self.prec),
'autoh': self.percent(0 if not self.preh else self.autoh / self.preh),
'lowr': 'y' if self.lowr else 'n',
'attempt1': self.avg(self.habattempt[1], perc=True),
'attempt2': self.avg(self.habattempt[2], perc=True),
'attempt3': self.avg(self.habattempt[3], perc=True),
'success2': self.percent(0 if not self.habattempt[2] else self.habsuccess[2] / self.habattempt[2]),
'success3': self.percent(0 if not self.habattempt[3] else self.habsuccess[3] / self.habattempt[3]),
'time2': self.avg(self.climbtime[0]),
'time3': self.avg(self.climbtime[1]),
'droph': self.avg(self.droph),
'dropc': self.avg(self.dropc),
'climb2': self.avg(self.climb[0], perc=True),
'climb3': self.avg(self.climb[1], perc=True),
'allhatch': self.avg(self.lowh + self.highh),
'allcargo': self.avg(self.lowc + self.highc),
'height': ('h' if self.highh > 2 else 'x') + ('c' if self.highc > 2 else 'x'), }
def summary(self, form=Forms.strat):
forms = {self.Forms.strat: self.strat_form, self.Forms.quick: self.quick_form,
self.Forms.detail: self.detail_form}
if self.total:
return forms[form].format(**self.calcvalues())
return '{0:4s}: '.format(self.team) + dataconstants.NO_DATA
def avg(self, x, perc=False, itint=True):
if type(x) in (int, float):
# Sum average
r = 0 if not self.total else x / self.total
else:
# Iterable average
r = sum(x) / (1 if len(x) == 0 else len(x))
if itint:
r = int(r)
return r if not perc else self.percent(r)
@staticmethod
def percent(n):
return int(n * 100)