-
Notifications
You must be signed in to change notification settings - Fork 1
/
cvt_test_mod.py
67 lines (55 loc) · 1.71 KB
/
cvt_test_mod.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
import csv
import datetime
import itertools
import sys
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# from scipy.interpolate import spline
class testData (object):
def __init__(self, dateTime, speedo, tach, timeStamp):
self.dateTime = dateTime
self.speedo = speedo
self.tach = tach
self.timeStamp = timeStamp
def __str__(self):
return 'Date: ' + str(self.dateTime) + '\nSpeedo: ' + len(self.speedo) + '\nTach: ' + len(self.tach)
class cvtData (object):
def __init__(self):
self.tests = {}
def addTestData(self, tests):
for test in tests:
dateList = test[0][0].split()
date = dateList[-2].split('/')
time = dateList[-1].split(':')
DT = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(time[0]), int(time[1]), int(float(time[2])))
del test[0]
data = zip(*test)
self.tests[DT] = testData(DT, np.array(map(float, data[0])), np.array(map(float, data[1])), np.array(map(float, data[2])))
def get_tests_csv(filename):
test = []
c = csv.reader(open(filename))
groups = itertools.groupby(c, lambda line: line==[])
for is_seperator, rawdata in groups:
if not is_seperator:
test.append(list(rawdata))
return test
def plotCVTData(cvt):
t = cvt.tests.values()[0]
# tnew = np.linspace(t.speedo.min(), t.speedo.max(), len(t.speedo))
# smooth = spline(t.speedo, t.tacho, tnew)
plt.plot(t.speedo, t.tach, 'ro-')
plt.ylabel('RPM')
plt.xlabel('Speed')
plt.title(str(t.dateTime))
plt.xlim(xmin=0)
plt.ylim(ymin=0)
plt.savefig(str(t.dateTime)+'.png', bbox_inches=0)
return str(t.dateTime)+'.png'
def save_plot(results_file):
tests = get_tests_csv(results_file)
cvt = cvtData()
cvt.addTestData(tests)
fig = plotCVTData(cvt)
return fig