-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_handler.py
83 lines (66 loc) · 2.03 KB
/
data_handler.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 configparser
DATA_FILE = "data.ini"
def get_available_courses():
config = open_config()
return config.sections()
def get_course_data(course_name):
"""
:param course_name:
:type course_name: str
:return:
"""
config = open_config()
course = config[course_name]
resulting_course = {}
for key, value in course.items():
if "description" in key:
resulting_course[key] = value
else:
resulting_course[key] = int(value)
return resulting_course
def get_compass_pos():
config = open_config()
compass_pos = [int(config["DEFAULT"]["compass_x"]), int(config["DEFAULT"]["compass_y"])]
return compass_pos
def set_compass_pos(x, y):
"""
:param x:
:type x: int
:param y:
:type y: int
:return:
"""
config = open_config()
config.set("DEFAULT", "compass_x", str(x))
config.set("DEFAULT", "compass_y", str(y))
with open(DATA_FILE, "w") as configfile:
config.write(configfile)
def update_course_obstacle(course_name, x, y, obstacle_number, obstacle_sub_step):
"""
:param course_name:
:type course_name: str
:param x:
:type x: int
:param y:
:type y: int
:param obstacle_number:
:type obstacle_number: int
:param obstacle_sub_step:
:type obstacle_sub_step: int
:return:
"""
config = open_config()
if obstacle_sub_step != -1:
x_option = str(obstacle_number) + "_sub_step_" + str(obstacle_sub_step) + "_x"
y_option = str(obstacle_number) + "_sub_step_" + str(obstacle_sub_step) + "_y"
else:
x_option = str(obstacle_number) + "_x"
y_option = str(obstacle_number) + "_y"
config.set(course_name, str(x_option), str(x))
config.set(course_name, str(y_option), str(y))
with open(DATA_FILE, "w") as configfile:
config.write(configfile)
def open_config():
config = configparser.ConfigParser()
config.read(DATA_FILE)
return config