-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfgplot.py
More file actions
61 lines (52 loc) · 1.7 KB
/
fgplot.py
File metadata and controls
61 lines (52 loc) · 1.7 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
import csv
import sys
import os
import matplotlib.pyplot as plt
def import_log(file_name):
print('Opening {}'.format(file_name))
data_dict = {}
with open(file_name) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
line_count += 1
if not row[1] in data_dict.keys():
data_dict[row[1]] = ([], [])
value = None
stamp = None
try:
value = float(row[2])
stamp = float(row[0])
except ValueError:
pass
if stamp:
data_dict[row[1]][0].append(stamp)
data_dict[row[1]][1].append(value)
print('Processed {} lines.'.format(line_count))
return(data_dict)
def plot_log(file_name):
data_dict = import_log(file_name)
plot_keys = [k for k in data_dict if len(data_dict[k][0]) > 1]
print(plot_keys)
for i, key in enumerate(plot_keys):
if i == 0:
this_ax = plt.subplot(len(plot_keys), 1, i+1)
top_ax = this_ax
else:
this_ax = plt.subplot(len(plot_keys), 1, i+1, sharex=top_ax)
plt.plot(data_dict[key][0], data_dict[key][1])
plt.title(key)
plt.show()
def last_log_filename():
file_list = [fn for fn in os.listdir('logs') if fn.endswith('.csv')]
file_list.sort()
if len(file_list) == 0:
raise FileNotFoundError('Unable to find last log file')
file_name = 'logs/'+file_list[-1]
return file_name
if __name__ == '__main__':
if len(sys.argv) == 2:
file_name = sys.argv[1]
else:
file_name = last_log_filename()
plot_log(file_name)