-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataHandler.py
More file actions
60 lines (51 loc) · 2.42 KB
/
DataHandler.py
File metadata and controls
60 lines (51 loc) · 2.42 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
import os
import yaml
import time
from pathlib import Path
class DataHandler:
def __init__(self, data_directory="data"):
self.data_directory = data_directory
if not os.path.exists(self.data_directory):
os.mkdir(self.data_directory)
def readData(self, data: list):
# TODO I'm assuming the data is in a certain order, is there a better way or do I just need to make this assumption?
# TODO Bruh moment, refactor this please
# TODO Check data most likely in (an)other function(s)
# TODO Possibly look into re-ordering data into a more logical fashion, right now important field (ie. team number)
# are in random locations
# TODO HARDCODING LMAOOOOO HAHAHAHAH
data_dict = {
"Scouter Name": data[0],
"Match Number": int(data[1]),
"Match Type": data[2],
"Team Number": int(data[3]),
"Alliance": data[4],
"Preload": int(data[5]),
"High Port Auto": int(data[6]),
"Low Port Auto": int(data[7]),
"Missed Auto": int(data[8]),
"High Port Teleop": int(data[9]),
"Low Port Teleop": int(data[10]),
"Missed Teleop": int(data[11]),
"Robot Attitude": data[12],
"Colour Wheel Done": bool(data[13]),
"Colour Wheel Landed": bool(data[14]),
"Colour Wheel Was Rotated": bool(data[15]),
"Climb": data[16], # TODO possibly a boolean, look into this
"Balanced": data[17],
"Number of Climbs": int(data[18]),
"Notes": data[19]
}
return yaml.dump(data_dict)
# TODO Figure out YAML type hinting
def writeData(self, yaml_data):
# TODO Refactor, this is going to be a real stinker
# TODO Generate some test data to test this out
data = yaml.load(yaml_data, Loader=yaml.FullLoader)
# splitting this to make it cleaner
# filename format: teamnumber_matchtype_matchnumber_scouter_date_time.yaml
# date/time are when the data is entered, so don't use it to determine a match number
filename = f"{data['Team Number']}_{data['Match Type']}_{data['Match Number']}_{data['Scouter Name']}_{time.strftime('%Y-%m-%d')}_{time.strftime('%H-%M-%S')}.yaml"
f = open(Path(f"{os.path.dirname(__file__)}/{self.data_directory}/{filename}"), "w+")
f.write(yaml_data)
f.close()