-
Notifications
You must be signed in to change notification settings - Fork 0
/
12V_parse.py
82 lines (79 loc) · 2.98 KB
/
12V_parse.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
import re, csv
DELIMITER = ','
input_filename = "4.7.5 8031595.csv"
output_filename = "4.7.5 8031595 analysis.csv"
index_GPIO1 = 52
index_GPIO2 = 60
index_GPIO3 = 68
index_GPIO4 = 76
index_GPIO5 = 84
reg_GPIO = r"A: ([\d\.]+)V / B: ([\d\.]+)V / C: ([\d\.]+)V / D: ([\d\.]+)V"
index_panic = 108
reg_panic = r"Panic 1 Low: (PASS|FAIL) \(([\d\.]+)\) / High: (PASS|FAIL) \(([\d\.]+)\) Panic 2 Low: (PASS|FAIL) \(([\d\.]+)\) / High: (PASS|FAIL) \(([\d\.]+)\)"
index_12V = 124
reg_12V = r"Int(ernal)?: ([\d\.]+)V / V(B|b)att A: ([\d\.]+)V"
index_5V = 116
reg_5V = r"([\d\.]+)"
with open(input_filename) as f:
with open(output_filename, 'w') as out_file:
reader = csv.reader(f)
headers = reader.next()
for items in reader:
out_array = []
# GPIO1
m = re.search(reg_GPIO, items[index_GPIO1])
if not m:
print "No match for GPIO1"
out_array += ['']*4
else:
out_array += [m.group(1), m.group(2), m.group(3), m.group(4)]
# GPIO2
m = re.search(reg_GPIO, items[index_GPIO2])
if not m:
print "No match for GPIO2"
out_array += ['']*4
else:
out_array += [m.group(1), m.group(2), m.group(3), m.group(4)]
# GPIO3
m = re.search(reg_GPIO, items[index_GPIO3])
if not m:
print "No match for GPIO3"
out_array += ['']*4
else:
out_array += [m.group(1), m.group(2), m.group(3), m.group(4)]
# GPIO4
m = re.search(reg_GPIO, items[index_GPIO4])
if not m:
print "No match for GPIO4"
out_array += ['']*4
else:
out_array += [m.group(1), m.group(2), m.group(3), m.group(4)]
# GPIO5
m = re.search(reg_GPIO, items[index_GPIO5])
if not m:
print "No match for GPIO5"
out_array += ['']*4
else:
out_array += [m.group(1), m.group(2), m.group(3), m.group(4)]
# Panic Lines
m = re.search(reg_panic, items[index_panic])
if not m:
print "No match for Panic Lines: {}".format(items[index_panic])
out_array += ['']*4
else:
out_array += [m.group(2), m.group(4), m.group(6), m.group(8)]
# 5V
m = re.search(reg_5V, items[index_5V])
if not m:
print "No match for 5V: {}".format(items[index_5V])
out_array += ['']
else:
out_array += [m.group(1)]
# 12V
m = re.search(reg_12V, items[index_12V])
if not m:
print "No match for 12V: {}".format(items[index_12V])
out_array += ['', '']
else:
out_array += [m.group(2), m.group(4)]
out_file.write(DELIMITER.join(out_array) + '\n')