-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_logs.py
94 lines (78 loc) · 3.02 KB
/
parse_logs.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
# Open the parm filename. Read each line of the file, splitting each line into a list of strings delimited by space.
# The function output is a list of list of stings.
#
# Eg. input file,
# ---------------
# This is a
# test.
# ---------------
def filename_to_list_of_strings(filename):
output = []
with open(filename) as fileobj:
for line in fileobj:
output.append((line.replace('\n', '')).split(' '))
return output
# For example,
# input_list = [['foo', 'bar', 'harry'], ['foo', 'miss', 'david']]
# target = 'bar'
# output = [['foo', 'bar', 'harry']]
def filter_by_2nd_item(input_list, target):
output = []
for item in input_list:
if item[1] == target:
output.append(item)
return output
# Make a list of waypoints out of filtered list of waypoint strings.
def make_list_of_waypoints(input_list):
output = []
pos = -1
for item in input_list[0]: # Every item in the list is same, so arbitrarily pick 1st one.
pos += 1
if pos >= 2: # Ignore the first two items in the list,
tuple_pos = (pos - 2) % 3
if tuple_pos == 0:
i1 = item
elif tuple_pos == 1:
i2 = item
else:
waypoint = {}
waypoint['waypoint'] = int(i1)
waypoint['x'] = float(i2)
waypoint['y'] = float(item)
output.append(waypoint) # Append the tuple.
return output
# 'true' -> True, 'false' -> False
def string_to_bool(s):
return s == 'true'
def make_list_of_statuses(input_list):
output = []
for s in input_list:
status = {}
status['timestamp'] = float(s[2])
status['all_wheels_on_track'] = string_to_bool(s[3])
status['x'] = float(s[4])
status['y'] = float(s[5])
status['distance_from_center'] = float(s[6])
status['is_left_of_center'] = string_to_bool(s[7])
status['heading'] = float(s[8])
status['progress'] = float(s[9])
status['steps'] = int(s[10])
status['speed'] = float(s[11])
status['steering_angle'] = float(s[12])
status['track_width'] = float(s[13])
status['max_speed'] = float(s[14])
status['max_steer'] = float(s[15])
status['near_centre_of_track'] = string_to_bool(s[16])
status['quite_near_centre_of_track'] = string_to_bool(s[17])
status['heading_in_right_direction'] = string_to_bool(s[18])
status['turning_hard'] = string_to_bool(s[19])
status['going_straight'] = string_to_bool(s[20])
status['going_fast'] = string_to_bool(s[21])
status['going_slowly'] = string_to_bool(s[22])
status['correcting_course'] = string_to_bool(s[23])
status['rule_number'] = int(s[24])
status['rule_description'] = s[25].replace('_', ' ')
status['reward_level'] = s[26].replace('_', ' ')
status['score'] = float(s[27])
output.append(status)
return output