Statistics
| Branch: | Revision:

nepatest_popbabel / scripts / popNoPopCompar.py @ 60ba786f

History | View | Annotate | Download (3.97 KB)

1
import sys
2
import csv
3
from pprint import pprint
4
from matplotlib import pyplot as plt
5
import code
6

    
7
f1=sys.argv[1] #pop
8
f2=sys.argv[2] #noPop
9
print f1,f2
10

    
11

    
12
#Header format is like this
13
#Time,loops,blackholes,total
14

    
15
#time example: 8:22:38-high
16

    
17

    
18

    
19
#Dealing with pop csv
20
f1res={} #timeToTuple
21
elaps1=[]
22
min1=0.0
23
with open(f1, 'r') as csvfile:
24
        reader = csv.reader(csvfile, delimiter=',')
25
        next(reader, None)
26
        for row in reader:
27
                time=row[0]
28
                loops=int(row[1])
29
                bh=int(row[2])
30
                total=int(row[3])
31
                
32
                #converting time string to comparable number
33
                splt=time.split('-')
34
                c=0.0
35
                if (splt[-1]=='high'):
36
                        c=5
37
                splt=splt[0].split(':')
38
                hh=int(splt[0])
39
                mm=int(splt[1])
40
                ss=int(splt[2])
41
                numtime=hh*60*60 + mm*60 + ss + c*(10**-1)
42
                el=0.0
43
                if (not elaps1):
44
                        min1=numtime
45
                else:
46
                        el=numtime-min1
47
                elaps1.append(el)
48
                f1res[el]=(loops,bh,total)
49

    
50
pprint(f1res)
51

    
52

    
53
#Dealing with pop csv
54
f2res={} #timeToTuple
55
elaps2=[]
56
min2=0.0
57
with open(f2, 'rb') as csvfile:
58
        reader = csv.reader(csvfile, delimiter=',')
59
        next(reader, None)
60
        for row in reader:
61
                time=row[0]
62
                loops=int(row[1])
63
                bh=int(row[2])
64
                total=int(row[3])
65
                
66
                #converting time string to comparable number
67
                splt=time.split('-')
68
                c=0.0
69
                if (splt[-1]=='high'):
70
                        c=5
71
                splt=splt[0].split(':')
72
                hh=int(splt[0])
73
                mm=int(splt[1])
74
                ss=int(splt[2])
75
                numtime=hh*60*60 + mm*60 + ss + c*(10**-1)
76
                el=0.0
77
                if (not elaps2):
78
                        min2=numtime
79
                else:
80
                        el=numtime-min2
81
                elaps2.append(el)
82
                f2res[el]=(loops,bh,total)
83

    
84
pprint(f2res)
85

    
86
#code.interact(local=dict(globals(), **locals()))
87

    
88
lps1=[]
89
bhs1=[]
90
tot1=[]
91

    
92

    
93
lps2=[]
94
bhs2=[]
95
tot2=[]
96

    
97

    
98
elaps=""
99
srtkeys=""
100
if (len(f1res)>len(f2res)):
101
        elaps=elaps1
102
        srtkeys=sorted(f1res.keys())
103
        missing=list(set(f1res.keys()) - set(f2res.keys()))
104
        for k in missing:
105
                f2res[k]=(0,0,0,)
106
else:
107
        elaps=elaps2
108
        srtkeys=sorted(f2res.keys())
109
        missing=list(set(f2res.keys()) - set(f1res.keys()))
110
        for k in missing:
111
                f1res[k]=(0,0,0,)
112
pprint(srtkeys)
113

    
114

    
115
for k in srtkeys:
116
        print f1res[k][1],f2res[k][1]
117
        bhs1.append(f1res[k][1])
118
        bhs2.append(f2res[k][1])
119

    
120
        lps1.append(f1res[k][0])
121
        lps2.append(f2res[k][0])
122

    
123
        tot1.append(f1res[k][-1])
124
        tot2.append(f2res[k][-1])
125

    
126
area1=0.0
127
for i in range(0,len(bhs1)):
128
        area1+=tot1[i]*0.5
129

    
130
area2=0.0
131
for i in range(0,len(bhs2)):
132
        area2+=tot2[i]*0.5
133

    
134
print "Disruption gain: "+str(area2-area1)
135

    
136

    
137
#print "we: "+str( sum(bhs2) - sum(bhs1)      )
138
print area2, " - ", area1
139

    
140

    
141

    
142

    
143
#plotting bhs
144
f = plt.figure(1)
145
plt.plot(elaps, bhs1, 'r', label="pop")
146
plt.plot(elaps, bhs2, 'b', label="NOpop")
147
plt.legend(loc='upper right', fontsize=10, numpoints=1)
148
plt.grid(True)
149

    
150
plt.xlabel('Elapsed time from node\'s failure (sec)')
151
plt.ylabel('#Blackholes')
152
plt.legend(loc='upper right', fontsize=10, numpoints=1)
153
'''ymin, ymax = plt.ylim()
154
ml=ymax+1
155
plt.ylim(ymin,ml)'''
156
#fig = plt.gcf()
157
#f.show()
158
plt.savefig("blh-plot.pdf",bbox_inches='tight')
159

    
160

    
161
#plotting loops
162
f = plt.figure(2)
163
plt.plot(elaps, lps1, 'r', label="pop")
164
plt.plot(elaps, lps2, 'b', label="NOpop")
165
plt.legend(loc='upper right', fontsize=10, numpoints=1)
166
plt.grid(True)
167

    
168
plt.xlabel('Elapsed time from node\'s failure (sec)')
169
plt.ylabel('#Loops')
170
plt.legend(loc='upper right', fontsize=10, numpoints=1)
171
'''ymin, ymax = plt.ylim()
172
ml=ymax+1
173
plt.ylim(ymin,ml)'''
174
#fig = plt.gcf()
175
#f.show()
176
plt.savefig("loop-plot.pdf",bbox_inches='tight')
177

    
178

    
179
#plotting totals
180
#pprint(elaps1)
181
#pprint(tot1)
182
elaps = [x+4.0 for x in elaps]
183
elaps=[0.0, 0.5, 1.0, 1.5, 2.0,2.5, 3.0, 3.5]+elaps
184
tot1=[0,0,0,0,0,0,0,0]+tot1
185
tot2=[0,0,0,0,0,0,0,0]+tot2
186
f = plt.figure(3)
187
plt.plot(elaps, tot1, 'r', label="pop",linewidth=2.0)
188
plt.plot(elaps, tot2, 'b', label="NOpop",linewidth=2.0)
189
plt.grid(True)
190

    
191
code.interact(local=dict(globals(), **locals()))
192

    
193
plt.xlabel('Elapsed time from node\'s failure [sec]',fontsize=22)
194
plt.ylabel('#Broken paths',fontsize=22)
195
plt.legend(loc='upper right', fontsize=22, numpoints=1)
196
'''ymin, ymax = plt.ylim()
197
ml=ymax+1
198
plt.ylim(ymin,ml)'''
199
#fig = plt.gcf()
200
#f.show()
201
plt.savefig("tot-plot.pdf",bbox_inches='tight')
202

    
203
#print "Plots have been saved in working dir\n\nPress ENTER to quit"
204
#raw_input()