-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_prechecks.py
714 lines (569 loc) · 22.2 KB
/
event_prechecks.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 4 21:58:47 2018
Event prescout with emphasis on past performance and interesting judging
things.
TODO: Move master keys and sorted award list to an external file and import
TODO: Replace diagnostic print statements with ic
TODO: Refactor everything
"""
import tbaUtils
import pandas as pd
from pprint import pprint
from icecream import ic
from datetime import date
import urllib
from time import sleep
YEAR = str(date.today().year)
MASTERKEYS = {0: 'RCA/CCA',
1: 'Winner',
2: 'Finalist',
3: 'WFFA/WFA',
4: 'DLFA',
5: 'Volunteer of the Year',
6: 'Founders Award',
9: 'REI/EI',
10: 'Rookie All-Star',
11: 'Gracious Professionalism',
12: 'Coopertition',
13: 'Judges',
14: 'Highest Rookie Seed',
15: 'Rookie Inspiration',
16: 'GM Industrial Design',
17: 'Quality',
18: 'Safety',
19: 'Sportsmanship',
20: 'Creativity',
21: 'Excellence in Engineering',
22: 'Entrepreneurship',
23: 'Autodesk Excellence in Design',
24: 'Excellence in Design Award sponsored by Autodesk (3D CAD)',
25: 'Championship - Excellence in Design Award sponsored by Autodesk (Animation)',
26: 'Delphi Driving Tomorrows Technology',
27: 'Imagery',
28: 'Media and Technology Award sponsored by Comcast',
29: 'Innovation in Control',
30: 'Team Spirit',
31: 'Website',
32: 'Autodesk Visualization',
33: 'Autodesk Inventor Award',
34: 'FIRST Future Innovator',
38: 'Leadership in Controls',
39: '#1 Seed',
40: 'Incredible Play Award',
41: "People's Choice Animation Award",
42: 'Autodesk Rising Star Visualization Award',
43: 'Best Offensive Round',
44: 'Best Play of the Day Award',
45: 'Featherweight in the Finals',
46: 'Most Photogenic',
47: 'Outstanding Defense',
48: 'Delphi "Power to Simplify" Award',
49: 'Against All Odds Award',
51: 'Chairmans Award Finalist',
52: 'Honorable Mention-Content Communication',
53: 'Honorable Mention-Technical Execution',
54: 'Autodesk Award for Realization',
56: 'Autodesk Design your Future Award',
57: 'Autodesk Design your Future Award Honorable Mentions:',
58: 'Autodesk Special Recognition for Distinctive Work in the Area of Character Animation:',
59: 'High Score',
60: 'Teacher Pioneer Award',
61: 'Best Craftsmanship/Ultimate Keeper Award',
62: 'Best Defensive Match',
63: 'Play of the Day',
64: 'Programming',
65: 'Professionalism Award',
66: 'The Golden Corndog Award',
67: 'Most Improved Team',
68: 'Wildcard',
69: "Chairman's Award Finalist",
70: 'Most Improved Robot',
71: 'Autonomous Award sponsored by Ford',
72: 'FIRST Innovation Challenge Semi-Finalist Award',
73: 'Rookie Game Changer',
74: 'Skills Competition Winner',
75: 'Skills Competition Finalist',
76: 'Rookie Design Award',
77: 'Engineering Design Award',
78: "Designer's Award",
79: 'Concept Award'}
AWDSEQ = ['Chairman\'s Award Finalist', 'RCA/CCA', 'REI/EI', 'Winner', 'Finalist',
'Wildcard', 'Excellence in Engineering', 'GM Industrial Design',
'Innovation in Control', 'Quality', 'Creativity',
'Autonomous Award sponsored by Ford', 'Entrepreneurship',
'Gracious Professionalism', 'Team Spirit', 'Imagery', 'Judges', 'Safety',
'Rookie All-Star', 'Rookie Inspiration', 'Highest Rookie Seed',
'WFFA/WFA', 'DLFA', 'Volunteer of the Year', 'FIRST Future Innovator',
'Coopertition', 'Sportsmanship', 'Professionalism Award',
'Delphi Driving Tomorrows Technology',
'Website', 'Leadership in Controls', '#1 Seed', 'High Score',
'Incredible Play Award', 'Against All Odds Award',
'Best Play of the Day Award', 'Best Offensive Round',
'Best Defensive Match', 'Best Craftsmanship/Ultimate Keeper Award',
'Outstanding Defense', 'Featherweight in the Finals',
'Most Improved Team', 'Most Photogenic',
'Programming', 'Most Improved Robot',
'Media and Technology Award sponsored by Comcast',
'Teacher Pioneer Award',
'Delphi "Power to Simplify" Award',
'Autodesk Excellence in Design',
'Excellence in Design Award sponsored by Autodesk (3D CAD)',
'Autodesk Rising Star Visualization Award',
'Autodesk Visualization', 'Autodesk Inventor Award',
'Autodesk Award for Realization',
'Autodesk Design your Future Award',
'Autodesk Design your Future Award Honorable Mentions:']
def maketeamlist(event):
'''
Pull big list, strip out the interesting parts, and return as a dict.
'''
raw = tbaUtils.get_event_teams(event)
result = {}
for entry in raw:
teamnum = entry['team_number']
name = entry['nickname']
if entry['country'] == 'USA':
state = entry['state_prov']
else:
state = entry['country']
school = entry['name'].split('&')[-1]
# print(teamnum, name, state, school)
result[teamnum] = {'name': name, 'state': state, 'school': school}
return result
def locstats(teamdict):
'''
Where are the teams from, generally speaking.
'''
locgrid = {}
for team in teamdict:
state = teamdict[team]['state']
if state not in locgrid:
locgrid[state] = 0
locgrid[state] += 1
return locgrid
def eventmtx(teamlist):
'''
Take each team, get their event history (which includes this years).
Make two dicts, one with everything, one with just this year.
'''
allevents = {}
currentevents = {}
for team in teamlist:
allevents[team] = tbaUtils.get_team_history(team)
currentevents[team] = []
for event in allevents[team]:
if YEAR in event:
currentevents[team].append(event)
return currentevents, allevents
def awdmtx(teamlist):
'''
Take each team, get their award history.
'''
allawds = {}
awdkeys = {}
awdmtx = {}
for team in teamlist:
allawds[team] = tbaUtils.get_award_history(team)
for awddict in allawds[team]:
atype = awddict['award_type']
aname = awddict['name']
aevent = awddict['event_key']
# Make a matrix of all the type number to award name mappings
if atype not in awdkeys:
awdkeys[atype] = []
if aname not in awdkeys[atype]:
awdkeys[atype].append(aname)
# Make a matrix of award key to team to event mappings
if atype not in awdmtx:
awdmtx[atype] = {}
if team not in awdmtx[atype]:
awdmtx[atype][team] = []
awdmtx[atype][team].append(aevent)
return allawds, awdkeys, awdmtx
def teamweekmtx(teamdict):
'''(dict) -> dict
Take entries like 935: ['2018mokc2', '2018mokc'] and convert to
935: {2: '2018mokc2', 3: '2018mokc'}
'''
junk, weeklist = tbaUtils.make_eventweekmtx()
result = {}
for team in teamdict:
result[team] = {}
for week in weeklist:
for event in teamdict[team]:
if event[4:] in weeklist[week]:
result[team][week] = event
# print('\nTeam Week Matrix?')
return pd.DataFrame(result).transpose().fillna(value='')
def wrestleawds(awdmatrix, awdkeys):
masterkeys = MASTERKEYS
# pprint(masterkeys)
print()
for i in awdkeys:
if i not in masterkeys:
print('Missing Award:', i, awdkeys[i])
masterkeys[i] = awdkeys[i][0]
# print('\nMaster Keys')
# pprint(masterkeys)
currentyear = {}
allyears = {}
for key in awdmatrix:
aname = masterkeys[key]
currentyear[aname] = {}
allyears[aname] = {}
for team in awdmatrix[key]:
currentyear[aname][team] = []
allyears[aname][team] = []
for award in awdmatrix[key][team]:
if award[0:4] == YEAR:
currentyear[aname][team].append(award)
allyears[aname][team].append(award)
if len(currentyear[aname][team]) == 0:
del currentyear[aname][team]
if len(currentyear[aname]) == 0:
del currentyear[aname]
if len(allyears[aname]) == 0:
del allyears[aname]
print()
# print('All')
# pprint(allyears)
currentyeardf = pd.DataFrame(currentyear)
allyearsdf = pd.DataFrame(allyears)
# resequence this mess
actuals = currentyeardf.columns.tolist()
possibles = AWDSEQ.copy()
for item in AWDSEQ:
if item not in actuals:
possibles.remove(item)
currentyeardf = currentyeardf[possibles]
actuals2 = allyearsdf.columns.tolist()
possibles2 = AWDSEQ.copy()
for item in AWDSEQ:
if item not in actuals2:
possibles2.remove(item)
allyearsdf = allyearsdf[possibles2]
return currentyeardf, allyearsdf
def awdcounter(awdmtxdf):
'''
Take the award matrix and do a count by team by award.
Also do a count by team by award for the most recent 4 years (i.e. the
window in which the same student might have been on the team Freshman to
Senior)
'''
tgtyears = [YEAR, str(int(YEAR) - 1), str(int(YEAR) - 2), str(int(YEAR) - 3)]
awdmtxdf.fillna(value='0', inplace=True)
mtx = awdmtxdf.to_dict()
allcnt = {}
past4 = {}
for awd in mtx:
allcnt[awd] = {}
past4[awd] = {}
for team in mtx[awd]:
if mtx[awd][team] == '0':
allcnt[awd][team] = 0
past4[awd][team] = 0
else:
for item in mtx[awd][team]:
if team not in past4[awd]:
allcnt[awd][team] = 0
past4[awd][team] = 0
year = item[0:4]
if year in tgtyears:
past4[awd][team] += 1
allcnt[awd][team] += 1
past4df = pd.DataFrame(past4)
allcntdf = pd.DataFrame(allcnt)
# TODO resequence this mess
actuals = past4df.columns.tolist()
possibles = AWDSEQ.copy()
for item in AWDSEQ:
if item not in actuals:
possibles.remove(item)
past4df = past4df[possibles]
actuals = allcntdf.columns.tolist()
possibles = AWDSEQ.copy()
for item in AWDSEQ:
if item not in actuals:
possibles.remove(item)
allcntdf = allcntdf[possibles]
return past4df, allcntdf
def wffanator(allawds):
'''
Take the all awards list, find the WFFA entries, and print/return a list
of the recipients
'''
wffas = []
for team in allawds:
for award in allawds[team]:
if award['award_type'] == 3:
# print(award['event_key'], award['recipient_list'][0]['awardee'], team)
if award['event_key'] == '2009co':
wffas.append([award['event_key'], 'Kevin Schimpf', team])
else:
wffas.append([award['event_key'], award['recipient_list'][0]['awardee'], team])
wffas.sort()
print('\nWFFA count is:', len(wffas))
pprint(wffas)
return wffas
def prescout_event(event):
'''
Combine commands together, write to a file.
'''
xlfile = 'Prescout-' + YEAR + '-' + event + '.xlsx'
scratchfile = 'Prescout-' + YEAR + '-' + event + '-notes.txt'
teamlist = maketeamlist(event)
#ic(teamlist)
locations = locstats(teamlist)
current, fullhist = eventmtx(teamlist)
allawds, awdkeys, awdmx = awdmtx(teamlist)
wffas = wffanator(allawds)
'''
with open(scratchfile, 'w') as file:
file.write('Team List\n')
print(teamlist)
file.write(str(teamlist))
file.write('\n\nLocation Stats\n')
file.write(str(locations))
file.write('\n\nCurrent Events\n')
file.write(str(current))
file.write('\n\nAward List\n')
file.write(str(allawds))
file.write('\n\nAward Keys\n')
file.write(str(awdkeys))
'''
# print('\nKeys')
# pprint(awdkeys)
print('Team locations:')
pprint(locations)
curmtx = teamweekmtx(current)
teamdf = pd.DataFrame(teamlist).transpose()
#covidRkdf = covidrookie(teamdf)
#ic(covidRkdf)
eventteamdf = pd.merge(teamdf, curmtx, left_index=True, right_index=True)
# pprint(awdmx)
curawddf, awdmtxdf = wrestleawds(awdmx, awdkeys)
past4cntdf, allawdcntdf = awdcounter(awdmtxdf)
# print(awdmtxdf.head())
with pd.ExcelWriter(xlfile) as writer:
eventteamdf.to_excel(writer, 'Team Events')
curawddf.to_excel(writer, 'Current Awards')
awdmtxdf.to_excel(writer, 'Full Award Matrix')
past4cntdf.to_excel(writer, 'Awd Count Current Team')
allawdcntdf.to_excel(writer, 'All Award Count')
def makeEventList(year=YEAR):
'''
List event code, event name, competition level
'''
eventlist = tbaUtils.get_event_list(year)
result = []
for event in eventlist:
key = event['key']
name = event['name']
level = event['event_type_string']
result.append([key, level])
return result
'''
def covidrookie(teamdf):
Parameters:
teamdf: pdDataframe containing Team, Nickname, State
Returns:
coviddf: pd.Dataframe containing Team, 2020Events
2020Events is a boolean indicating whether the team attended a 2020 event that was not cancelled.
TODO:This thing doesn't work at all yet
good2020 = ['2020arli', '2020award', '2020bcvi', '2020cadm', '2020cala', '2020caln', '2020cass', '2020cmpmi',
'2020cmptx', '2020ctnct', '2020ctwat', '2020facc', '2020gadal', '2020gagai', '2020gzrs', '2020ilch',
'2020inblo', '2020isde1', '2020isde2', '2020mabri', '2020mdbet', '2020mijac', '2020mike2', '2020miket',
'2020mikng', '2020mimcc', '2020mimil', '2020misjo', '2020misou', '2020mitvc', '2020mndu', '2020mndu2',
'2020mnwcw', '2020mokc', '2020mxmo', '2020ncpem', '2020ncwak', '2020ndgf', '2020nhgrs', '2020nyrra',
'2020ohmv', '2020onbar', '2020onosh', '2020onto3', '2020orore', '2020pahat', '2020qcsh', '2020scmb',
'2020srrc', '2020taiw', '2020taiw2', '2020tuis', '2020tuis2', '2020txcha', '2020txdel', '2020txdri',
'2020txgre', '2020txpla', '2020utwv', '2020vagle', '2020vahay', '2020wasno', '2020waspo', '2020week0',
'2020wiss']
ic(teamdf.head())
ic(tbaUtils.get_team_history('1706'))
teamdf[events] = tbaUtils.get_team_history(teamdf[team_num])
ic(teamdf.head())
'''
def eventLeveler(eventlist):
'''
Take a list of eventcodes and return them by level [CMP, REG, DCMP, DIS]
'''
result = [[], [], [], []]
cmpdivs = ['carv', 'gal', 'hop', 'new', 'roe', 'tur',
'arc', 'cars', 'cur', 'dal', 'dar', 'tes',
'cmp', 'cmptx', 'cmpmo', 'cmpmi']
mi = ['dt', 'dt1', 'gg', 'grl', 'gt', 'mi', 'oc', 'oc1', 'swm', 'wc', 'ww']
for event in eventlist:
shortclli = event[4:]
el = len(shortclli)
year = int(event[:4])
print(event, shortclli, el)
if shortclli in cmpdivs:
result[0].append(event)
elif year > 2012: # Naming convention standardized
if el == 5:
if shortclli[2:] == 'cmp':
result[2].append(event)
elif shortclli[-1].isdigit():
result[1].append(event)
else:
result[3].append(event)
elif el == 4:
result[1].append(event)
elif year > 2008: # Michigan has districts, still on oldformat names
if shortclli == 'gl': # micmp
result[2].append(event)
elif shortclli in mi:
result[3].append(event)
else:
result[1].append(event)
else: # No districts exist, and we've already ruled out CMP divisions
result[1].append(event)
return result
def cmpscout(cmp):
if cmp == 'hou':
divisions = ['carv', 'gal', 'hop', 'new', 'roe', 'tur']
else:
divisions = ['arc', 'cars', 'cur', 'dal', 'dar', 'tes']
for event in divisions:
print(event)
prescout_event(event)
sleep(10)
def matchlistformo(event, year=YEAR):
matchdictlist = tbaUtils.get_event_matches(event, year)
qualteams = []
for match in matchdictlist:
if match['comp_level'] == 'qm':
matchnum = match['match_number']
blue = match['alliances']['blue']['team_keys']
red = match['alliances']['red']['team_keys']
for i in [0, 1, 2]:
j = str(i + 1)
qualteams.append([matchnum, 'Red' + j, red[i]])
qualteams.append([matchnum, 'Blue' + j, blue[i]])
qualdf = pd.DataFrame(qualteams, columns=['Match', 'Position', 'Team'])
qualdf.to_excel('MO Matchlist - ' + event + '.xlsx', index=False)
def crmnlevel(event):
year = int(event[0:4])
length = len(event)
if 'cmp' in event:
if length == 7:
return 'HOF'
else:
return 'DCMP'
else:
if year == 2021:
return 'R21'
else:
if length <= 7:
return 'R'
elif year > 2012 and length == 8:
return 'R'
else:
state = event[4:6]
if state in ['mo', 'mn', 'ny', 'tu']:
return 'R'
else:
return 'D'
def getcrmn(year=YEAR):
keylist = tbaUtils.get_event_year_keys()
#temp for testing
#keylist = ['2022mokc', '2022mokc3', '2022ksla', '2022cave', '2022wayak']
pprint(keylist)
longlist = []
for event in keylist:
eventawds = tbaUtils.get_event_awards(event[4:])
if len(eventawds) > 0 and eventawds[0]['award_type'] == 0:
longlist.append(eventawds[0]['recipient_list'][0]['team_key'][3:])
pprint(longlist)
print()
teamlist = {}
teamnames = {}
teamstate = {}
for team in longlist:
teamawds = tbaUtils.get_award_history(team)
templist = []
print('\n',team,'\n')
for awd in teamawds:
if awd['award_type'] == 0:
if crmnlevel(awd['event_key']) != 'D':# or awd['event_key'][:4] == '2022':
templist.append(awd['event_key'])
#print(templist)
teamlist[int(team)] = templist
teamdata = tbaUtils.get_team(team)
teamnames[int(team)] = teamdata['nickname']
if teamdata['country'] in ['USA','Canada']:
teamstate[int(team)] = teamdata['state_prov']
else:
teamstate[int(team)] = teamdata['country']
pprint(teamlist)
teamwins = {}
print()
for team in teamlist.keys():
teamwins[team]=len(set([event[:4] for event in teamlist[team]]))
pprint(teamwins)
teamwincountdf = pd.DataFrame({'Team':teamwins.keys(),'WinCount':teamwins.values(),'nickname':teamnames.values(),'State':teamstate.values()})
windf = pd.DataFrame({'Team':teamlist.keys(),'Awards':teamlist.values()})
with pd.ExcelWriter('crmn-'+year+'.xlsx') as writer:
teamwincountdf.to_excel(writer, 'Win Counts', index=False)
windf.to_excel(writer, 'Win List', index=False)
def findawd(awdlist,awdkey):
for awd in awdlist:
#pprint(awd)
if awd['award_type'] == awdkey:
#print('Gotcha',awdkey)
return awd
def getwffavoy():
'''
Looking for people are both WFFAs and VOYs (and maybe DLFAs later), by team
'''
wffas = {}
voys = {}
dlfas = {}
for year in range(1992,2023):
# Get event list for year
keylist = tbaUtils.get_event_year_keys(year)
# Pull award list for each event
for event in keylist:
try:
tempevent = tbaUtils.get_event_awards(event[4:],year)
voy = findawd(tempevent,5)
wffa = findawd(tempevent,3)
dlfa = findawd(tempevent,4)
#pprint(voy)
#pprint(wffa)
if voy is not None:
voys[voy['event_key']] = voy['recipient_list']
if wffa is not None:
wffas[wffa['event_key']] = wffa['recipient_list']
if dlfa is not None:
dlfas[dlfa['event_key']] = dlfa['recipient_list']
except urllib.error.HTTPError:
continue
sleep(3)
print('\nVOY List')
pprint(voys)
print('\nWFFA List')
pprint(wffas)
#Invert awardee and event
voynames = []
for event in voys.keys():
for awardee in voys[event]:
voynames.append({'name': awardee['awardee'], 'event': event, 'team_key': awardee['team_key']})
print('\nVOYs by Name')
pprint(voynames)
wffanames = []
for event in wffas.keys():
for awardee in wffas[event]:
wffanames.append({'name': awardee['awardee'], 'event': event, 'team_key': awardee['team_key']})
voydf = pd.DataFrame(voynames)
wffadf = pd.DataFrame(wffanames)
wffavoy = wffadf.merge(voydf,how='inner',on=['name','team_key'],suffixes=['_wffa','_voy'])
with pd.ExcelWriter('wffavoy.xlsx') as writer:
wffadf.to_excel(writer, 'WFFAs', index=False)
voydf.to_excel(writer, 'VOYs', index=False)
wffavoy.to_excel(writer, 'Double winners',index=False)
#thisevent = input('Enter event to check: ')
#assert thisevent.isalnum()
#prescout_event('wimi')