-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
280 lines (227 loc) · 9.16 KB
/
main.py
File metadata and controls
280 lines (227 loc) · 9.16 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
from perf import Perf
from duration import Duration
import numpy as np
import matplotlib.pyplot as plt
import sys
defaultPath = "./data/mockgen.graphdata"
dataPerf = []
dataSample = []
def readFile(path):
file = open(path, "r");
return file.readlines()
def buildObjects(lines):
for line in lines:
dataPerf.append(Perf(line.rstrip()))
def getTimePerActivity():
durations = []
for perf in dataPerf:
exists = False
for duration in durations:
if duration.exists(perf):
duration.addValue(perf)
exists = True
if exists:
pass
else:
duration = Duration(perf)
durations.append(duration)
return durations
def getMirrorMesure(toCompare):
if len(dataSample) <= 0:
return
for sample in dataSample:
if sample.pref.isMirrorOf(toCompare):
return sample
return None;
def getIndividualMirrorMesure(toCompare):
if len(dataPerf) <= 0:
return
for sample in dataPerf:
if sample.isMirrorOf(toCompare):
return sample
return None;
def appendTotalValue(vals, toAppends):
last = vals[len(vals) - 1]
for toAppend in toAppends :
vals.append(last + toAppend);
last += toAppend;
return vals;
def SortChronologicaly():
graphqlDurationEvolution =[0]
restDurationEvolution = [0]
graphqlSizeEvolution =[0]
restSizeEvolution = [0]
graphqlRequestSizeEvolution =[0]
restRequestSizeEvolution = [0]
graphqlRoundTripEvolution = [0]
restRoundTripEvolution = [0]
annotation = [""]
for sample in dataPerf:
if sample.requestType == 2:
continue
restDurationEvolution = appendEvolutionValue(restDurationEvolution, sample.getDuration())
restSizeEvolution = appendEvolutionValue(restSizeEvolution, sample.responseSize)
restRequestSizeEvolution = appendEvolutionValue(restRequestSizeEvolution, sample.requestSize)
restRoundTripEvolution = appendEvolutionValue(restRoundTripEvolution, sample.roundTrips)
toCompare = getIndividualMirrorMesure(sample);
if toCompare == None:
graphqlDurationEvolution = appendEvolutionValue(graphqlDurationEvolution, 0)
graphqlSizeEvolution = appendEvolutionValue(graphqlSizeEvolution, 0)
graphqlRequestEvolution = appendEvolutionValue(graphqlRequestSizeEvolution, 0)
graphqlRoundTripEvolution = appendEvolutionValue(graphqlRoundTripEvolution, 0)
else:
graphqlDurationEvolution = appendEvolutionValue(graphqlDurationEvolution, toCompare.getDuration())
graphqlSizeEvolution = appendEvolutionValue(graphqlSizeEvolution, toCompare.responseSize)
graphqlRequestSizeEvolution = appendEvolutionValue(graphqlRequestSizeEvolution, toCompare.requestSize)
graphqlRoundTripEvolution = appendEvolutionValue(graphqlRoundTripEvolution, toCompare.roundTrips)
annotation.append(sample.endpoint)
showDurationEvolution(graphqlDurationEvolution, restDurationEvolution, annotation)
showCumulatedSizeEvolution(graphqlSizeEvolution, restSizeEvolution, annotation)
showRequestSizeEvolution(graphqlRequestSizeEvolution, restRequestSizeEvolution, annotation)
showRoundTripEvolution(graphqlRoundTripEvolution, restRoundTripEvolution, annotation)
def appendEvolutionValue(lastValue, toAdd):
total = lastValue[len(lastValue) - 1];
lastValue.append(toAdd + total)
return lastValue;
def showDurationEvolution(graphqlDurationEvolution, restDurationEvolution, annotation):
fig = plt.figure()
fig.suptitle('Cumulated transmission time for app navigation', fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
print(restDurationEvolution)
ax.plot(graphqlDurationEvolution, marker="o", label="GraphQL")
ax.plot(restDurationEvolution, marker="o", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Screen navigation")
ax.set_ylabel("Cumulated request duration (ms)")
plt.xticks(range(1, len(restDurationEvolution)))
for i in xrange(1,len(graphqlDurationEvolution)):
print graphqlDurationEvolution[i], i, annotation[i]
offset = -1 if i % 2 == 0 else 1
ax.annotate(annotation[i], xy=(i - 0.5, graphqlDurationEvolution[i]+100 * offset))
ax.annotate(annotation[i], xy=(i - 0.5, restDurationEvolution[i]+100 * offset))
plt.show()
def showCumulatedSizeEvolution(graphqlSizeEvolution, restSizeEvolution, annotation):
fig = plt.figure()
fig.suptitle('Cumulated response size for app navigation', fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
ax.plot(graphqlSizeEvolution, marker="o", label="GraphQL")
ax.plot(restSizeEvolution, marker="o", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Screen navigation")
ax.set_ylabel("Cumulated response size (b)")
plt.xticks(range(1, len(restSizeEvolution)))
for i in xrange(1,len(graphqlSizeEvolution)):
print graphqlSizeEvolution[i], i, annotation[i]
offset = -1 if i % 2 == 0 else 1
ax.annotate(annotation[i], xy=(i - 0.5, graphqlSizeEvolution[i]+2000 * offset))
ax.annotate(annotation[i], xy=(i - 0.5, restSizeEvolution[i]+2000 * offset))
plt.show()
def showRequestSizeEvolution(graphqlSizeEvolution, restSizeEvolution, annotation):
fig = plt.figure()
fig.suptitle('Cumulated request size for app navigation', fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
ax.plot(graphqlSizeEvolution, marker="o", label="GraphQL")
ax.plot(restSizeEvolution, marker="o", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Screen navigation")
ax.set_ylabel("Cumulated request size (b)")
plt.xticks(range(1, len(restSizeEvolution)))
for i in xrange(1,len(graphqlSizeEvolution)):
print graphqlSizeEvolution[i], i, annotation[i]
offset = -1 if i % 2 == 0 else 1
ax.annotate(annotation[i], xy=(i - 0.5, graphqlSizeEvolution[i]+100 * offset))
ax.annotate(annotation[i], xy=(i - 0.5, restSizeEvolution[i]+100 * offset))
plt.show()
def showRoundTripEvolution(graphqlRoundTripEvolution, restRoundTripEvolution, annotation):
fig = plt.figure()
fig.suptitle('Cumulated roundtrips for app navigation', fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
print(restRoundTripEvolution)
ax.plot(graphqlRoundTripEvolution, marker="o", label="GraphQL")
ax.plot(restRoundTripEvolution, marker="o", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Screen navigation")
ax.set_ylabel("Cumulated RoundTrip")
plt.xticks(range(1, len(restRoundTripEvolution)))
for i in xrange(1,len(graphqlRoundTripEvolution)):
print graphqlRoundTripEvolution[i], i, annotation[i]
offset = -1 if i % 2 == 0 else 1
ax.annotate(annotation[i], xy=(i - 0.5, graphqlRoundTripEvolution[i]+2 * offset))
ax.annotate(annotation[i], xy=(i - 0.5, restRoundTripEvolution[i]+2 * offset))
plt.show()
def sortResultAndDisplay():
graphqlTimeByActivity = []
restTimeByActivity = []
xLabel = []
for sample in dataSample:
if sample.pref.requestType == 2:
continue;
restTimeByActivity.append(sample.stat.calculateDurationMean())
graphqlTimeByActivity.append(getMirrorMesure(sample.pref).stat.calculateDurationMean())
xLabel.append(sample.pref.className)
showDurationByActivity(graphqlTimeByActivity, restTimeByActivity, xLabel)
def showDurationByActivity(graphqlTimeByActivity, restTimeByActivity, xLabel):
n_groups = len(graphqlTimeByActivity)
index = np.arange(n_groups)
bar_width = 0.25
fig = plt.figure()
fig.suptitle('Mean response duration per activity', fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
ax.bar(index, graphqlTimeByActivity, bar_width, color="b", label="GraphQL")
ax.bar(index + bar_width, restTimeByActivity, bar_width, color="r", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Activity Name")
ax.set_ylabel("Mean waiting time")
plt.xticks(index + bar_width, xLabel)
plt.show()
def showEvolution(graphqlDurationEvolution, restDurationEvolution, graphqlSizeEvolution, restSizeEvolution) :
fig = plt.figure()
ax = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
print(restDurationEvolution)
ax.plot(graphqlDurationEvolution, marker="o", label="GraphQL")
ax.plot(restDurationEvolution, marker="o", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Screen navigation")
ax.set_ylabel("Cumulated query duration")
ax.set_xticks(range(1, len(restDurationEvolution)))
ax2.plot(graphqlSizeEvolution, marker="o", label="GraphQL")
ax2.plot(restSizeEvolution, marker="o", label="Rest")
ax2.legend(loc="upper left")
ax2.set_xlabel("Screen navigation")
ax2.set_ylabel("Cumulated response size")
ax2.set_xticks(range(1, len(restSizeEvolution)))
plt.show()
def getSizeReceivedEvolution():
graphql =[0]
rest = [0]
for sample in dataSample:
if sample.pref.requestType == 2:
continue;
rest = appendTotalValue(rest, sample.stat.getTotalResponseSize())
graphql = appendTotalValue(graphql, getMirrorMesure(sample.pref).stat.getTotalResponseSize())
print graphql
print rest
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(graphql, marker="o", label="GraphQL")
ax.plot(rest, marker="o", label="Rest")
ax.legend(loc="upper left")
ax.set_xlabel("Screen navigation")
ax.set_ylabel("Cumulated response size")
plt.xticks(range(1, len(rest)))
plt.show()
def meanByActivity():
print "wip"
graphql = []
rest = []
#Take a duration calculate mean and plot array of means
if len(sys.argv) > 1:
defaultPath = sys.argv[1]
buildObjects(readFile(defaultPath))
dataSample = getTimePerActivity()
#plt.plot(dataSample[0].stat.getTotalValues())
#plt.plot(getMirrorMesure(dataSample[0].pref).stat.getTotalValues())
#plt.show()
SortChronologicaly();
sortResultAndDisplay();