-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgames.py
More file actions
2412 lines (2227 loc) · 97.8 KB
/
games.py
File metadata and controls
2412 lines (2227 loc) · 97.8 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
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from typing import List
from constants import *
from constants import Station, getMeanOfScoringCategory
from database import *
from pymongo.collection import Collection
import time
import ast
from database import Station, getMeanOfScoringCategory
class Game:
"""
Game Superclass
This shouldn't be used; all functions should be replaced.
"""
def __init__(self, matches: Collection, teams: Collection):
self.keyDisplayNames = {}
self.matches = matches
self.teams = teams
self.teamRankOptions = {}
self.teamTableDisplayNames = {}
self.matchTableDisplayNames = {}
self.cannedComments = []
self.pitScoutAutoCapabilities = tuple()
self.pitScoutTeleCapabilities = tuple()
raise NotImplementedError("Game Superclass __init__ used")
def calculateScore(self) -> int:
"""
Calculate the total score from scouted values.
This shouldn't be used; replace this with a game specific function.
Inputs:
- Depends
Outputs:
- int: total score, minus points from fouls
"""
raise NotImplementedError("Game Superclass calculateScore used")
# return 0
def scoreRobotInMatch(self) -> bool:
"""
Scores one robot in a match.
This shouldn't be used; replace this with a game specific function.
Inputs:
- self explanitory
Returns:
- Boolean: if the robot was successfully scored
"""
raise NotImplementedError("Game Superclass scoreRobotInMatch used")
# return False
def calculateScoreFromData(
self, matchData: dict, team: Station, edit: int = -1
) -> int:
"""
Gets a robot's result from the database and scores it.
This shouldn't be used; replace this with a game specific function.
Inputs:
- matchData (dict): a match dict
- team (Station): the station to score
- edit (int): which revision to score, defaults to the latest
Returns:
- int: calculated score
"""
raise NotImplementedError("Game Superclass calculateScoreFromData used")
# return 0
def calculateAverageAllianceScore(
self, team1: int, team2: int, team3: int, calc=getMeanOfScoringCategory
) -> dict | None:
"""
Calculates a hypothetical alliance score of three teams using their average results in each category.
This shouldn't be used; replace this with a game specific function.
Inputs:
- team1 (int): team number 1
- team2 (int): team number 2
- team3 (int): team number 3
- calc (function): the static function to use, defaults to mean
Returns:
- dict or none: dict of predicted results, or None if any teams are not found.
"""
raise NotImplementedError("Game Superclass calculateAverageAllianceScore used")
# return None
def calculateMinMaxAllianceScore(
self, team1: int, team2: int, team3: int, maximum: bool = True
) -> dict | None:
"""
Calculates a hypothetical alliance score of three teams using their minimum or maximum results in each category.
This shouldn't be used; replace this with a game specific function.
Inputs:
- team1 (int): team number 1
- team2 (int): team number 2
- team3 (int): team number 3
- maximum (bool): True uses maximum, False uses minimum, defaults to True
Returns:
- dict or none: dict of predicted results, or None if any teams are not found.
"""
raise NotImplementedError("Game Superclass calcualteMinMaxAllianceScore used")
# return None
def getAllStats(self, team: int) -> dict:
"""
Calculates all stats for every single scoring category.
This shouldn't be used; replace this with a game specific function.
Inputs:
- team (int): Team number
Returns:
- dict: dict of every scoring category with every stat
"""
raise NotImplementedError("Game Superclass getAllStats used")
# return {}
def calculateAllianceFromMatches(
self,
team1: int,
match1: list,
team2: int,
match2: list,
team3: int,
match3: list,
) -> dict:
"""
Adds together results for three teams from given match data to predict their performance as an alliance.
This shouldn't be used; replace this with a game specific function.
Inputs:
- team1 (int): team 1 number
- match1 (list): match data for team 1
- team2 (int): team 2 number
- match2 (list): match data for team 2
- team3 (int): team 3 number
- match3 (list): match data for team 3
Returns:
- dict: predicted results dict
"""
raise NotImplementedError("Game Superclass calculateAllianceFromMatches used")
# return {}
def calculateStatMatrix(self,team:int) -> dict:
"""
Calculates a team's stat matrix, with each field from a range from 0 to 1.
1 represents the highest value for that field.
This shouldn't be used; replace this with a game specific function.
Inputs:
- team (int): team number
Returns:
- dict: stat dict
"""
raise NotImplementedError("Game Superclass calculateStatMatrix used")
class Reefscape(Game):
def __init__(self, matches: Collection, teams: Collection):
self.keyDisplayNames = {
"matchNumber": "Match Number",
"setNumber": "Set Number",
"compLevel": "Competition Level",
"matchKey": "Match Key",
"displayName": "Display Name",
"teams": "Teams",
"red1": "Red 1",
"red2": "Red 2",
"red3": "Red 3",
"blue1": "Blue 1",
"blue2": "Blue 2",
"blue3": "Blue 3",
"results": "Results",
"scored": "Scored",
"startPos": "Starting Position",
"autoLeave": "Auto Leave",
"autoReef": "Reef Auto",
"autoReefL1": "Reef Auto L1",
"autoReefL2": "Reef Auto L2",
"autoReefL3": "Reef Auto L3",
"autoReefL4": "Reef Auto L4",
"autoReefMiss": "Reef Auto Missed",
"teleReef": "Reef Tele-Op",
"teleReefL1": "Reef Tele-Op L1",
"teleReefL2": "Reef Tele-Op L2",
"teleReefL3": "Reef Tele-Op L3",
"teleReefL4": "Reef Tele-Op L4",
"teleReefMiss": "Reef Tele-Op Missed",
"autoProcessor": "Processor Auto",
"autoProcessorMiss": "Processor Auto Missed",
"teleProcessor": "Processor Tele-Op",
"teleProcessorMiss": "Processor Tele-Op Missed",
"autoNet": "Net Auto",
"autoNetMiss": "Net Auto Missed",
"teleNet": "Net Tele-Op",
"teleNetMiss": "Net Tele-Op Missed",
"endPos": "Ending Position",
"attemptedEndPos": "Attempted Ending Position",
"endPosSuccess": "Succeeded End Position",
"minorFouls": "Minor Fouls",
"majorFouls": "Major Fouls",
"score": "Score Impact",
"comment": "Comment",
"scout": "Scout",
}
self.matches = matches
self.teams = teams
self.teamRankOptions = {
"Score Impact": "score,0",
"Starting Position": "startPos,0",
"Auto Leave": "autoLeave,0",
"Reef Auto": "autoReef,0",
"Reef Auto L1": "autoReef,0",
"Reef Auto L2": "autoReef,1",
"Reef Auto L3": "autoReef,2",
"Reef Auto L4": "autoReef,3",
"Reef Auto Missed": "autoReefMiss,0",
"Reef Tele-Op": "teleReef,0",
"Reef Tele-Op L1": "teleReef,0",
"Reef Tele-Op L2": "teleReef,1",
"Reef Tele-Op L3": "teleReef,2",
"Reef Tele-Op L4": "teleReef,3",
"Reef Tele-Op Missed": "teleReefMiss,0",
"Processor Auto": "autoProcessor,0",
"Processor Auto Missed": "autoProcessorMiss,0",
"Processor Tele-Op": "teleProcessor,0",
"Processor Tele-Op Missed": "teleProcessorMiss,0",
"Net Auto": "autoNet,0",
"Net Auto Missed": "autoNetMiss,0",
"Net Tele-Op": "teleNet,0",
"Net Tele-Op Missed": "teleNetMiss,0",
"Ending Position": "endPos,0",
"Attempted Ending Position": "attemptedEndPos,0",
"Minor Fouls": "minorFouls,0",
"Major Fouls": "majorFouls,0",
}
self.teamTableDisplayNames = {
"score": "Score Impact",
"autoLeave": "Auto Leave",
"autoReefL1": "Reef Auto L1",
"autoReefL2": "Reef Auto L2",
"autoReefL3": "Reef Auto L3",
"autoReefL4": "Reef Auto L4",
"autoReefMiss": "Reef Auto Missed",
"autoReefTotal": "Reef Auto Total",
"teleReefL1": "Reef Tele-Op L1",
"teleReefL2": "Reef Tele-Op L2",
"teleReefL3": "Reef Tele-Op L3",
"teleReefL4": "Reef Tele-Op L4",
"teleReefMiss": "Reef Tele-Op Missed",
"teleReefTotal": "Reef Tele-Op Total",
"autoProcessor": "Processor Auto",
"autoProcessorMiss": "Processor Auto Missed",
"teleProcessor": "Processor Tele-Op",
"teleProcessorMiss": "Processor Tele-Op Missed",
"autoNet": "Net Auto",
"autoNetMiss": "Net Auto Missed",
"teleNet": "Net Tele-Op",
"teleNetMiss": "Net Tele-Op Missed",
"minorFouls": "Minor Fouls",
"majorFouls": "Major Fouls",
}
self.matchTableDisplayNames = {
"team": "Team",
"displayName": "Display Name",
"score": "Score Impact",
"matchNumber": "Match Number",
"setNumber": "Set Number",
"compLevel": "Competition Level",
"startPos": "Starting Position",
"autoLeave": "Auto Leave",
"autoReefL1": "Reef Auto L1",
"autoReefL2": "Reef Auto L2",
"autoReefL3": "Reef Auto L3",
"autoReefL4": "Reef Auto L4",
"autoReefMiss": "Reef Auto Missed",
"teleReefL1": "Reef Tele-Op L1",
"teleReefL2": "Reef Tele-Op L2",
"teleReefL3": "Reef Tele-Op L3",
"teleReefL4": "Reef Tele-Op L4",
"teleReefMiss": "Reef Tele-Op Missed",
"autoProcessor": "Processor Auto",
"autoProcessorMiss": "Processor Auto Missed",
"teleProcessor": "Processor Tele-Op",
"teleProcessorMiss": "Processor Tele-Op Missed",
"autoNet": "Net Auto",
"autoNetMiss": "Net Auto Missed",
"teleNet": "Net Tele-Op",
"teleNetMiss": "Net Tele-Op Missed",
"attemptedEndPos": "Attempted Ending Position",
"endPosSuccess": "Ending Position Sucecss",
"minorFouls": "Minor Fouls",
"majorFouls": "Major Fouls",
"comment": "Comment",
}
self.cannedComments = [
"Good Driving",
"Bad Driving",
"Fast Driving",
"Slow Driving",
"Removed Algae",
"Coral Station During Auto",
"Played Defense",
"Good Defense",
"Bad Defense",
"Was Defended",
"Multiple Fouls",
"Multiple Jams",
"Bumpers Off",
"Tipped/Stuck",
"Died",
"No Show",
"Bad Descision Making",
]
self.pitScoutAutoCapabilities = tuple()
self.pitScoutTeleCapabilities = tuple()
def calculateScore(
self,
autoLeave: bool,
autoReef: List[int],
teleReef: List[int],
autoProcessor: int,
teleProcessor: int,
autoNet: int,
teleNet: int,
endPos: int,
minorFouls: int,
majorFouls: int,
) -> int:
"""
Calculate the total score from scouted values.
Inputs:
- Self explanatory
Outputs:
- int: total score, minus points from fouls
"""
score = 0
score += 3 if autoLeave else 0
score += 3 * autoReef[0]
score += 4 * autoReef[1]
score += 6 * autoReef[2]
score += 7 * autoReef[3]
score += 2 * teleReef[0]
score += 3 * teleReef[1]
score += 4 * teleReef[2]
score += 5 * teleReef[3]
score += 2 * autoProcessor
score += 2 * teleProcessor
score += 4 * autoNet
score += 4 * teleNet
score += (
2
if endPos == EndPositionReefscape.PARK.value
else (
6
if endPos == EndPositionReefscape.SHALLOW.value
else 12 if endPos == EndPositionReefscape.DEEP.value else 0
)
)
score -= 2 * minorFouls
score -= 6 * majorFouls
return score
def scoreRobotInMatch(
self,
matchNumber: int,
setNumber: int,
compLevel: CompLevel,
station: Station,
startPos: StartingPosition,
autoLeave: bool,
autoReef: List[int],
autoReefMiss: int,
teleReef: List[int],
teleReefMiss: int,
autoProcessor: int,
autoProcessorMiss: int,
teleProcessor: int,
teleProcessorMiss: int,
autoNet: int,
autoNetMiss: int,
teleNet: int,
teleNetMiss: int,
endPosSuccess: bool,
attemptedEndPos: EndPositionReefscape,
minorFouls: int,
majorFouls: int,
comment: str,
cannedComments: List[str],
scout: str,
) -> bool:
"""
Scores one robot in a match.
Should change every year.
Inputs:
- self explanitory
Returns:
- Boolean: if the robot was successfully scored
"""
result = matches.update_many(
{
"matchNumber": matchNumber,
"setNumber": setNumber,
"compLevel": compLevel.value,
},
{
"$push": {
"results."
+ station.value: {
"startPos": startPos.value,
"autoLeave": autoLeave,
"autoReef": autoReef,
"autoReefMiss": autoReefMiss,
"autoReefTotal": autoReef[0]
+ autoReef[1]
+ autoReef[2]
+ autoReef[3],
"teleReef": teleReef,
"teleReefMiss": teleReefMiss,
"teleReefTotal": teleReef[0]
+ teleReef[1]
+ teleReef[2]
+ teleReef[3],
"autoProcessor": autoProcessor,
"autoProcessorMiss": autoProcessorMiss,
"teleProcessor": teleProcessor,
"teleProcessorMiss": teleProcessorMiss,
"autoNet": autoNet,
"autoNetMiss": autoNetMiss,
"teleNet": teleNet,
"teleNetMiss": teleNetMiss,
"endPosSuccess": endPosSuccess,
"attemptedEndPos": attemptedEndPos.value,
"minorFouls": minorFouls,
"majorFouls": majorFouls,
"score": self.calculateScore(
autoLeave,
autoReef,
teleReef,
autoProcessor,
teleProcessor,
autoNet,
teleNet,
(
attemptedEndPos.value
if endPosSuccess
else EndPositionReefscape.NONE.value
),
minorFouls,
majorFouls,
),
"comment": comment,
"cannedComments": cannedComments,
"scout": scout,
}
}
},
)
if result.matched_count == 0:
app.logger.info( # type: ignore
f"Failed to score robot {station.value} for match {matchNumber} by {scout}: Match does not exist."
)
return False
writeToCacheFile("","statMatrixCache")
app.logger.info(f"Robot {station.value} scored for match {matchNumber} by {scout}.") # type: ignore
return True
def calculateScoreFromData(
self, matchData: dict, team: Station, edit: int = -1
) -> int:
"""
Gets a robot's result from the database and scores it.
Inputs:
- matchData (dict): a match dict
- team (Station): the station to score
- edit (int): which revision to score, defaults to the latest
Returns:
- int: calculated score
"""
results = matchData["results"][team.value][edit]
score = self.calculateScore(
results["autoLeave"],
results["autoReef"],
results["teleReef"],
results["autoProcessor"],
results["teleProcessor"],
results["autoNet"],
results["teleNet"],
results["endPos"],
results["minorFouls"],
results["majorFouls"],
)
return score
def calculateAverageAllianceScore(
self, team1: int, team2: int, team3: int, calc=getMeanOfScoringCategory
):
"""
Calculates a hypothetical alliance score of three teams using their average results in each category.
Should be edited every year.
Inputs:
- team1 (int): team number 1
- team2 (int): team number 2
- team3 (int): team number 3
- calc (function): the static function to use, defaults to mean
Returns:
- dict or none: dict of predicted results, or None if any teams are not found.
"""
team1Listing = getTeam(team1)
if not team1Listing:
return None
team2Listing = getTeam(team2)
if not team2Listing:
return None
team3Listing = getTeam(team3)
if not team3Listing:
return None
team1Data = getTeamResults(team1)
team2Data = getTeamResults(team2)
team3Data = getTeamResults(team3)
team1Leave = int(calc(team1Data, "autoLeave") >= 0.5)
team2Leave = int(calc(team2Data, "autoLeave") >= 0.5)
team3Leave = int(calc(team3Data, "autoLeave") >= 0.5)
leaveTotal = team1Leave + team2Leave + team3Leave
team1End = round(calc(team1Data, "endPos"))
team2End = round(calc(team2Data, "endPos"))
team3End = round(calc(team3Data, "endPos"))
team1Minors = calc(team1Data, "minorFouls")
team2Minors = calc(team2Data, "minorFouls")
team3Minors = calc(team3Data, "minorFouls")
team1Majors = calc(team1Data, "majorFouls")
team2Majors = calc(team2Data, "majorFouls")
team3Majors = calc(team3Data, "majorFouls")
autoReef = [
round(calc(team1Data, "autoReef", 0))
+ round(calc(team2Data, "autoReef", 0))
+ round(calc(team3Data, "autoReef", 0)),
round(calc(team1Data, "autoReef", 1))
+ round(calc(team2Data, "autoReef", 1))
+ round(calc(team3Data, "autoReef", 1)),
round(calc(team1Data, "autoReef", 2))
+ round(calc(team2Data, "autoReef", 2))
+ round(calc(team3Data, "autoReef", 2)),
round(calc(team1Data, "autoReef", 3))
+ round(calc(team2Data, "autoReef", 3))
+ round(calc(team3Data, "autoReef", 3)),
]
autoReef[0] += (
(max(autoReef[1], 12) - 12)
+ (max(autoReef[2], 12) - 12)
+ (max(autoReef[3], 12) - 12)
)
autoReef = [
autoReef[0],
min(autoReef[1], 12),
min(autoReef[2], 12),
min(autoReef[3], 12),
]
teleReefValues = [
round(calc(team1Data, "teleReef", 0))
+ round(calc(team2Data, "teleReef", 0))
+ round(calc(team3Data, "teleReef", 0)),
round(calc(team1Data, "teleReef", 1))
+ round(calc(team2Data, "teleReef", 1))
+ round(calc(team3Data, "teleReef", 1)),
round(calc(team1Data, "teleReef", 2))
+ round(calc(team2Data, "teleReef", 2))
+ round(calc(team3Data, "teleReef", 2)),
round(calc(team1Data, "teleReef", 3))
+ round(calc(team2Data, "teleReef", 3))
+ round(calc(team3Data, "teleReef", 3)),
]
teleReef = [
teleReefValues[0],
min(teleReefValues[1], 12 - autoReef[1]),
min(teleReefValues[1], 12 - autoReef[1]),
min(teleReefValues[1], 12 - autoReef[1]),
]
teleReef[0] += (
max(0, teleReefValues[1] - teleReef[1])
+ max(0, teleReefValues[2] - teleReef[2])
+ max(0, teleReefValues[3] - teleReef[3])
)
autoProcessor = (
round(calc(team1Data, "autoProcessor"))
+ round(calc(team2Data, "autoProcessor"))
+ round(calc(team3Data, "autoProcessor"))
)
teleProcessor = (
round(calc(team1Data, "teleProcessor"))
+ round(calc(team2Data, "teleProcessor"))
+ round(calc(team3Data, "teleProcessor"))
)
autoNet = (
round(calc(team1Data, "autoNet"))
+ round(calc(team2Data, "autoNet"))
+ round(calc(team3Data, "autoNet"))
)
teleNet = (
round(calc(team1Data, "teleNet"))
+ round(calc(team2Data, "teleNet"))
+ round(calc(team3Data, "teleNet"))
)
score = self.calculateScore(
False,
autoReef,
teleReef,
autoProcessor,
teleProcessor,
autoNet,
teleNet,
0,
0,
0,
)
score += 3 * leaveTotal
score += (
2
if team1End == EndPositionReefscape.PARK.value
else (
6
if team1End == EndPositionReefscape.SHALLOW.value
else 12 if team1End == EndPositionReefscape.DEEP.value else 0
)
)
score += (
2
if team2End == EndPositionReefscape.PARK.value
else (
6
if team2End == EndPositionReefscape.SHALLOW.value
else 12 if team2End == EndPositionReefscape.DEEP.value else 0
)
)
score += (
2
if team3End == EndPositionReefscape.PARK.value
else (
6
if team3End == EndPositionReefscape.SHALLOW.value
else 12 if team3End == EndPositionReefscape.DEEP.value else 0
)
)
return {
"score": score,
"autoLeave": leaveTotal,
"autoReef": autoReef,
"teleReef": teleReef,
"autoProcessor": autoProcessor,
"teleProcessor": teleProcessor,
"autoNet": autoNet,
"teleNet": teleNet,
"endPos1": team1End,
"endPos2": team2End,
"endPos3": team3End,
"minorFouls": team1Minors + team2Minors + team3Minors,
"majorFouls": team1Majors + team2Majors + team3Majors,
}
def calculateMinMaxAllianceScore(
self, team1: int, team2: int, team3: int, maximum: bool = True
):
"""
Calculates a hypothetical alliance score of three teams using their minimum or maximum results in each category.
Inputs:
- team1 (int): team number 1
- team2 (int): team number 2
- team3 (int): team number 3
- maximum (bool): True uses maximum, False uses minimum, defaults to True
Returns:
- dict or none: dict of predicted results, or None if any teams are not found.
"""
statistic = getMatchWithHighestValue if maximum else getMatchWithLowestValue
oppositeStatistic = (
getMatchWithLowestValue if maximum else getMatchWithHighestValue
)
team1Listing = getTeam(team1)
if not team1Listing:
return None
team2Listing = getTeam(team2)
if not team2Listing:
return None
team3Listing = getTeam(team3)
if not team3Listing:
return None
team1Data = getTeamResults(team1)
team2Data = getTeamResults(team2)
team3Data = getTeamResults(team3)
team1Leave = statistic(team1Data, "autoLeave")["value"]
team2Leave = statistic(team2Data, "autoLeave")["value"]
team3Leave = statistic(team3Data, "autoLeave")["value"]
leaveTotal = team1Leave + team2Leave + team3Leave
team1End = statistic(team1Data, "endPos")["value"]
team2End = statistic(team2Data, "endPos")["value"]
team3End = statistic(team3Data, "endPos")["value"]
team1Minors = statistic(team1Data, "minorFouls")["value"]
team2Minors = statistic(team2Data, "minorFouls")["value"]
team3Minors = statistic(team3Data, "minorFouls")["value"]
team1Majors = statistic(team1Data, "majorFouls")["value"]
team2Majors = statistic(team2Data, "majorFouls")["value"]
team3Majors = statistic(team3Data, "majorFouls")["value"]
autoReef = [
round(statistic(team1Data, "autoReef", 0)["value"])
+ round(statistic(team2Data, "autoReef", 0)["value"])
+ round(statistic(team3Data, "autoReef", 0)["value"]),
round(statistic(team1Data, "autoReef", 1)["value"])
+ round(statistic(team2Data, "autoReef", 1)["value"])
+ round(statistic(team3Data, "autoReef", 1)["value"]),
round(statistic(team1Data, "autoReef", 2)["value"])
+ round(statistic(team2Data, "autoReef", 2)["value"])
+ round(statistic(team3Data, "autoReef", 2)["value"]),
round(statistic(team1Data, "autoReef", 3)["value"])
+ round(statistic(team2Data, "autoReef", 3)["value"])
+ round(statistic(team3Data, "autoReef", 3)["value"]),
]
autoReef[0] += (
(max(autoReef[1], 12) - 12)
+ (max(autoReef[2], 12) - 12)
+ (max(autoReef[3], 12) - 12)
)
autoReef = [
autoReef[0],
min(autoReef[1], 12),
min(autoReef[2], 12),
min(autoReef[3], 12),
]
teleReefValues = [
round(statistic(team1Data, "teleReef", 0)["value"])
+ round(statistic(team2Data, "teleReef", 0)["value"])
+ round(statistic(team3Data, "teleReef", 0)["value"]),
round(statistic(team1Data, "teleReef", 1)["value"])
+ round(statistic(team2Data, "teleReef", 1)["value"])
+ round(statistic(team3Data, "teleReef", 1)["value"]),
round(statistic(team1Data, "teleReef", 2)["value"])
+ round(statistic(team2Data, "teleReef", 2)["value"])
+ round(statistic(team3Data, "teleReef", 2)["value"]),
round(statistic(team1Data, "teleReef", 3)["value"])
+ round(statistic(team2Data, "teleReef", 3)["value"])
+ round(statistic(team3Data, "teleReef", 3)["value"]),
]
teleReef = [
teleReefValues[0],
min(teleReefValues[1], 12 - autoReef[1]),
min(teleReefValues[1], 12 - autoReef[1]),
min(teleReefValues[1], 12 - autoReef[1]),
]
teleReef[0] += (
max(0, teleReefValues[1] - teleReef[1])
+ max(0, teleReefValues[2] - teleReef[2])
+ max(0, teleReefValues[3] - teleReef[3])
)
autoProcessor = (
statistic(team1Data, "autoProcessor")["value"]
+ statistic(team2Data, "autoProcessor")["value"]
+ statistic(team3Data, "autoProcessor")["value"]
)
teleProcessor = (
statistic(team1Data, "teleProcessor")["value"]
+ statistic(team2Data, "teleProcessor")["value"]
+ statistic(team3Data, "teleProcessor")["value"]
)
autoNet = (
statistic(team1Data, "autoNet")["value"]
+ statistic(team2Data, "autoNet")["value"]
+ statistic(team3Data, "autoNet")["value"]
)
teleNet = (
statistic(team1Data, "teleNet")["value"]
+ statistic(team2Data, "teleNet")["value"]
+ statistic(team3Data, "teleNet")["value"]
)
score = self.calculateScore(
False,
autoReef,
teleReef,
autoProcessor,
teleProcessor,
autoNet,
teleNet,
0,
0,
0,
)
score += 3 * leaveTotal
score += (
2
if team1End == EndPositionReefscape.PARK.value
else (
6
if team1End == EndPositionReefscape.SHALLOW.value
else 12 if team1End == EndPositionReefscape.DEEP.value else 0
)
)
score += (
2
if team2End == EndPositionReefscape.PARK.value
else (
6
if team2End == EndPositionReefscape.SHALLOW.value
else 12 if team2End == EndPositionReefscape.DEEP.value else 0
)
)
score += (
2
if team3End == EndPositionReefscape.PARK.value
else (
6
if team3End == EndPositionReefscape.SHALLOW.value
else 12 if team3End == EndPositionReefscape.DEEP.value else 0
)
)
return {
"score": score,
"autoLeave": leaveTotal,
"autoReef": autoReef,
"teleReef": teleReef,
"autoProcessor": autoProcessor,
"teleProcessor": teleProcessor,
"autoNet": autoNet,
"teleNet": teleNet,
"endPos1": team1End,
"endPos2": team2End,
"endPos3": team3End,
"minorFouls": team1Minors + team2Minors + team3Minors,
"majorFouls": team1Majors + team2Majors + team3Majors,
}
def getAllStats(self, team: int) -> dict:
"""
Calculates all stats for every single scoring category.
Inputs:
- team (int): Team number
Returns:
- dict: dict of every scoring category with every stat
"""
teamResults = getTeamResults(team)
return {
"startPos": getAllStatsForCategory(teamResults, "startPos"),
"autoLeave": getAllStatsForCategory(teamResults, "autoLeave"),
"autoReefL1": getAllStatsForCategory(teamResults, "autoReef", 0),
"autoReefL2": getAllStatsForCategory(teamResults, "autoReef", 1),
"autoReefL3": getAllStatsForCategory(teamResults, "autoReef", 2),
"autoReefL4": getAllStatsForCategory(teamResults, "autoReef", 3),
"autoReefMiss": getAllStatsForCategory(teamResults, "autoReefMiss"),
"teleReefL1": getAllStatsForCategory(teamResults, "teleReef", 0),
"teleReefL2": getAllStatsForCategory(teamResults, "teleReef", 1),
"teleReefL3": getAllStatsForCategory(teamResults, "teleReef", 2),
"teleReefL4": getAllStatsForCategory(teamResults, "teleReef", 3),
"teleReefMiss": getAllStatsForCategory(teamResults, "teleReefMiss"),
"autoProcessor": getAllStatsForCategory(teamResults, "autoProcessor"),
"autoProcessorMiss": getAllStatsForCategory(
teamResults, "autoProcessorMiss"
),
"teleProcessor": getAllStatsForCategory(teamResults, "teleProcessor"),
"teleProcessorMiss": getAllStatsForCategory(
teamResults, "teleProcessorMiss"
),
"autoNet": getAllStatsForCategory(teamResults, "autoNet"),
"autoNetMiss": getAllStatsForCategory(teamResults, "autoNetMiss"),
"teleNet": getAllStatsForCategory(teamResults, "teleNet"),
"teleNetMiss": getAllStatsForCategory(teamResults, "teleNetMiss"),
"endPosSuccess": getAllStatsForCategory(teamResults, "endPosSuccess"),
"attemptedEndPos": getAllStatsForCategory(teamResults, "attemptedEndPos"),
"minorFouls": getAllStatsForCategory(teamResults, "minorFouls"),
"majorFouls": getAllStatsForCategory(teamResults, "majorFouls"),
"score": getAllStatsForCategory(teamResults, "score"),
}
class Rebuilt(Game):
def __init__(self, matches: Collection, teams: Collection):
self.keyDisplayNames = {
"matchNumber": "Match Number",
"setNumber": "Set Number",
"compLevel": "Competition Level",
"preloadFuel": "Preloaded Fuel",
# "autoFuel": "Auto Fuel",
"autoFuelTotal": "Total Auto Fuel",
# "autoFuelTotalMissed": "Total Auto Fuel Missed",
"autoDepot": "Intaked from Depot During Auto",
"autoBump": "Went over the Bump in Auto",
"autoTrench": "Went under the Trench in Auto",
"autoNeutralIntake": "Intaked from the Neutral Zone during Auto",
"autoAttemptedSecondScore": "Attempted to score past preloads during Auto",
"autoSucceededSecondScore": "Succeeded to score past preloads during Auto",
"autoClimbAttempted": "Auto L1 Climb Attempted",
"autoClimbSuccess": "Auto L1 Climb Succeeded",
"autoOutpostFeed": "Fed from the Outpost during Auto",
"autoFedToOutpost": "Fed to the Outpost during Auto",
"firstShift": "Active in first and third shifts",
# "transitionFuel": "Transition Shift Fuel",
"transitionFuelTotal": "Total Transition Shift Fuel",
# "transitionFuelTotalMissed": "Total Transition Shift Fuel Missed",
"transitionFed": "Fed Fuel Into Alliance Zone During Transition Period",
"transitionDefense": "Defended During Transition Period",
"transitionStole": "Stole During Transition Period",
# "firstActiveShiftFuel": "First Active Shift Fuel",
"firstActiveShiftFuelTotal": "Total First Active Shift Fuel",
# "firstActiveShiftFuelTotalMissed": "Total First Active Shift Fuel Missed",
"firstActiveShiftFed": "Fed Fuel Into Alliance Zone During the First Active Shift",
"firstActiveShiftDefense": "Defended During the First Active Shift",
"firstActiveShiftStole": "Stole During the First Active Shift",
# "secondActiveShiftFuel": "Second Active Shift Fuel",
"secondActiveShiftFuelTotal": "Total Second Active Shift Fuel",
# "secondActiveShiftFuelTotalMissed": "Total Second Active Shift Fuel Missed",
"secondActiveShiftFed": "Fed Fuel Into Alliance Zone During the Second Active Shift",
"secondActiveShiftDefense": "Defended During the Second Active Shift",
"secondActiveShiftStole": "Stole During the Second Active Shift",
"firstInactiveShiftScored": "Scored During First Inactive Shift",
"scoredDuringFirstInactiveShift": "Scored During First Inacgive Shift",
"firstInactiveShiftFed": "Fed Fuel Into Alliance Zone During First Inactive Shift",
"firstInactiveShiftDefense": "Defended During First Inactive Shift",
"firstInactiveShiftStole": "Stole During the First Inactive Shift",
"firstInactiveShiftIntaked": "Intaked During First Inactive Shift",
"secondInactiveShiftScored": "Scored During Second Inactive Shift",
"scoredDuringSecondInactiveShift": "Scored During Second Inactive Shift",
"secondInactiveShiftFed": "Fed Fuel Into Alliance Zone During Second Inactive Shift",
"secondInactiveShiftIntaked": "Intaked During Second Inactive Shift",
"secondInactiveShiftDefense": "Defended During First Inactive Shift",
"secondInactiveShiftStole": "Stole During the Second Inactive Shift",
# "endgameFuel": "Endgame Fuel",
"endgameFuelTotal": "Total Endgame Fuel",
# "endgameFuelTotalMissed": "Total Endgame Fuel Missed",