-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
83 lines (65 loc) · 1.99 KB
/
util.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
import os
import json
from typing import List
from subprocess import run
import csv
from datetime import datetime
def path_to_this_files_directory():
dir_path = os.path.dirname(os.path.realpath(__file__))
return dir_path + '/'
def loads(x: str):
try:
return json.loads(x)
except:
return {}
def dumps(x: dict):
try:
return json.dumps(x)
except:
return "{}"
def get_team_number(teamid):
return teamid.replace('frc', '')
def save_as_csv(data: List[List], name='unnamed', append_timestamp=False):
run(['mkdir', '-p', 'exports'])
filename = f'exports/{name}{f"-{datetime.utcnow()}" if append_timestamp else ""}.csv'
run(['touch', filename])
with open(filename, "w") as f:
writer = csv.writer(f)
writer.writerows(data)
def tie_breaker_steam_works(red_foul_points: int, blue_foul_points: int,
red_auto_points: int, blue_auto_points: int,
red_total_rotor_points: int, blue_total_rotor_points: int,
red_touchpad_points: int, blue_touchpad_points: int,
red_total_pressure: int, blue_total_pressure: int) -> str:
"""
Taken from the Game Manual
Table 10-2: Quarterfinal, Semifinal, and Overtime Tiebreaker Criteria
Order Sort Criteria
1st Fewer FOUL points
2nd Cumulative sum of AUTO points
3rd Cumulative ROTOR engagement score (AUTO and TELEOP)
4th Cumulative TOUCHPAD score
5th Total accumulated pressure
6th MATCH is replayed
"""
if red_foul_points > blue_foul_points:
return 'red'
elif blue_foul_points > red_foul_points:
return 'blue'
if red_auto_points > blue_auto_points:
return 'red'
elif blue_auto_points > red_auto_points:
return 'blue'
if red_total_rotor_points > blue_total_rotor_points:
return 'red'
elif blue_total_rotor_points > red_total_rotor_points:
return 'blue'
if red_touchpad_points > blue_touchpad_points:
return 'red'
elif blue_touchpad_points > red_touchpad_points:
return 'blue'
if red_total_pressure > blue_total_pressure:
return 'red'
elif blue_total_pressure > red_total_pressure:
return 'blue'
return 'replay'