-
Notifications
You must be signed in to change notification settings - Fork 5
/
readcsv.py
69 lines (58 loc) · 2.21 KB
/
readcsv.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
import csv
import numpy as np
import pylab
f = open("CADRE.csv", "rb")
reader = csv.DictReader(f, skipinitialspace=True)
X, Y, Z = [], [], []
pcom = []
for row in reader:
data = [row["pt" + str(i) + ".Data[0][1499]"] for i in xrange(6)]
sumdata = sum([float(i) for i in data if i])
c1 = [row["Constraint ( pt" + str(i) + ".ConCh<=0 )[0]"] for i in xrange(6)]
c2 = [row["Constraint ( pt" + str(i) + ".ConDs<=0 )[0]"] for i in xrange(6)]
c3 = [row["Constraint ( pt" + str(i) + ".ConS0<=0 )[0]"] for i in xrange(6)]
c4 = [row["Constraint ( pt" + str(i) + ".ConS1<=0 )[0]"] for i in xrange(6)]
c5 = [row["Constraint ( pt" + str(i) + ".SOC[0][0]=pt" + str(i) + ".SOC[0][-1] )[0]"]
for i in xrange(6)]
# c1_f = np.all([float(i) < 0 for i in c1 if i])
# c2_f = np.all([float(i) < 0 for i in c2 if i])
# c3_f = np.all([float(i) < 0 for i in c3 if i])
# c4_f = np.all([float(i) < 0 for i in c4 if i])
# c5_f = np.all([float(i) < 0 for i in c4 if i])
c1_f = sum([float(i) for i in c1 if i])
c2_f = sum([float(i) for i in c2 if i])
c3_f = sum([float(i) for i in c3 if i])
c4_f = sum([float(i) for i in c4 if i])
c5_f = sum([float(i) for i in c5 if i])
feasible = [c1_f, c2_f, c3_f, c4_f, c5_f]
X.append(sumdata), Y.append(sum(feasible)), Z.append(feasible)
pcom.append([float(row["pt5.CP_gamma[%s]" % str(i)])
for i in xrange(300)])
# print sumdata, sum(feasible), max(feasible) #,[ '%.1f' % i for i in
# feasible]
print sumdata
pylab.figure()
pylab.plot(pcom[-1])
Z = np.array(Z)
if not len(Z):
print "no data yet..."
quit()
pylab.figure()
pylab.subplot(311)
pylab.title("total data")
pylab.plot(X, 'b')
pylab.plot([0, len(X)], [3e4, 3e4], 'k--', marker="o")
pylab.subplot(312)
pylab.title("Sum of Constraints")
pylab.plot([0, len(Y)], [0, 0], 'k--', marker="o")
pylab.plot(Y, 'k')
pylab.subplot(313)
pylab.title("Max of Constraints")
pylab.plot([0, len(Z)], [0, 0], 'k--')
pylab.plot(Z[:, 0], marker="o", label="c1")
pylab.plot(Z[:, 1], marker="o", label="c2")
pylab.plot(Z[:, 2], marker="o", label="c3")
pylab.plot(Z[:, 3], marker="o", label="c4")
pylab.plot(Z[:, 4], marker="o", label="c5")
pylab.legend(loc="best")
pylab.show()