-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogTool.py
More file actions
71 lines (52 loc) · 1.39 KB
/
LogTool.py
File metadata and controls
71 lines (52 loc) · 1.39 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
62
63
64
65
66
67
68
69
70
71
import matplotlib.pyplot as plt
class Math(object):
"""Basic statistical math functions"""
def sum(self, array):
total = 0
for i in array:
total += i
return total
def avg(self, array):
return sum(array) / len(array)
def std(self, array):
avg = self.avg(array)
sum = 0
for i in array:
sum += (i - avg) ** 2
return (sum / (len(array) - 1)) ** (1.0/2.0)
def numOf(self, num, array):
count = 0
for x in array:
if(x == num):
count += 1
return count
class FileLoader(object):
"""Load log file data into program"""
def __init__(self, fileName):
self.fileName = fileName
self.loadFile();
def loadFile(self):
self.logs = {}
file = open(self.fileName, 'r')
for line in file:
if not line.strip():
continue
else:
key = line[line.index(':') + 2 : line.index('=') - 1]
self.logs.setdefault(key, []).append(float(line[line.index("=") + 2:].rstrip()))
print key + "\t" + line[line.index("=") + 1 :]
def getValues(self, val):
return self.logs[val]
# math = Math()
# array = [1, 2, 3, 4, 5]
# print "Sum", math.sum(array)
# print "Avg", math.avg(array)
# print "Std", math.std(array)
# print "Num Of", math.numOf(3, array)
loader = FileLoader("log.txt")
math = Math()
print math.sum(loader.getValues("Right Encoder"))
print loader.getValues("Right Velocity")
plt.plot([10, 20, 30, 20, 15, 13, 14, 12])
plt.ylabel('Battery Voltage')
plt.show()