-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation_processing.py
253 lines (198 loc) · 9.08 KB
/
evaluation_processing.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
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
#
# This source file is part of the JASS open source project
#
# SPDX-FileCopyrightText: 2019-2021 Paul Schmiedmayer and the JASS project authors (see CONTRIBUTORS.md) <[email protected]>
#
# SPDX-License-Identifier: MIT
#
import os
import sys
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
def timestampFor(line):
try:
return datetime.strptime(line.split()[0], '%Y-%m-%dT%H:%M:%S+0000')
except:
return datetime.strptime(line.split()[0], '%Y-%m-%dT%H:%M:%S+0100')
def duration(d1, d2):
return (d1 - d2).seconds
def main():
initalDeploymentPath = sys.argv[1]
repeatedDeploymentPath = sys.argv[2]
initalDeploymentValues = processDir(initalDeploymentPath)
repeatedDeploymentValues = processDir(repeatedDeploymentPath)
drawDefaultPlots(initalDeploymentValues, repeatedDeploymentValues)
drawRatioPlots(initalDeploymentValues, repeatedDeploymentValues)
def processDir(path):
files = os.listdir(path)
searchTimes=[]
actionsTimes=[]
structureRetrievalTimes=[]
startupTimes=[]
for file in files:
if os.path.isfile(os.path.join(path, file)):
f = open(os.path.join(path, file),'r')
foundLines=[]
for line in f:
for keyword in keywords:
if keyword in line:
foundLines.append(line)
values = processFoundLines(foundLines)
searchTimes.append(values[0])
actionsTimes.append(values[1])
f.close()
f = open(os.path.join(path, file),'r')
specialValues = processSpecialCases(f)
structureRetrievalTimes.append(specialValues[0])
startupTimes.append(specialValues[1])
f.close()
return [np.mean(searchTimes), np.mean(actionsTimes), np.mean(structureRetrievalTimes), np.mean(startupTimes)]
# We have some operations (structure retrieval, startup) that are done together.
# We want to evaluate the total of each process, so we have to split it
def processSpecialCases(file):
keywords = [
'Cleaning up any leftover actions data',
'System structure written to',
'Finished deployment for',
]
tuples=[]
tuple = []
foundCleaning = False
foundStructure = False
for line in file:
if keywords[0] in line and not foundCleaning:
tuple.append(line)
foundCleaning = True
if keywords[1] in line and foundCleaning:
tuple.append(line)
foundStructure = True
if keywords[2] in line and foundStructure:
tuple.append(line)
tuples.append(tuple)
foundCleaning = False
foundStructure = False
tuple = []
structureRetrievalTime = 0
startupTime = 0
for tuple in tuples:
structureTime = duration(timestampFor(tuple[1]), timestampFor(tuple[0]))
startTime = duration(timestampFor(tuple[2]), timestampFor(tuple[1]))
structureRetrievalTime += structureTime
startupTime += startTime
return [structureRetrievalTime, startupTime]
def processFoundLines(lines):
searchTime = duration(timestampFor(lines[1]), timestampFor(lines[0]))
actionsTime = duration(timestampFor(lines[2]), timestampFor(lines[1]))
return (searchTime, actionsTime)
def drawDefaultPlots(data1, data2):
tags = [['Initial Deployment'], ['Recurring Deployment']]
transformedData1 = np.array(data1).astype(int)
transformedData2 = np.array(data2).astype(int)
transformedData = [transformedData1, transformedData2]
print(transformedData)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 10))
for index, ax in enumerate([ax1, ax2]):
currentData = transformedData[index]
search = currentData[0]
action = currentData[1]
structure = currentData[2]
startup = currentData[3]
ind = [x for x, _ in enumerate(tags[index])]
ax.bar(ind, startup, width=0.5, label='Startup', color='yellow', bottom=search+action+structure, align='center')
ax.bar(ind, structure, width=0.5, label='Structure Retrieval', color='green', bottom=action+search, align='center')
ax.bar(ind, action, width=0.5, label='Post Discovery Action', color='blue', bottom=search, align='center')
ax.bar(ind, search, width=0.5, label='Device Search', color='cyan', align='center')
ax.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False # labels along the bottom edge are off
)
if index == 0:
ax1.annotate(str(search)+" sec.",
xy=(0.25, search),
xycoords='data',
va='center',
xytext=(0.65, search+10),
arrowprops=dict(arrowstyle='-', color='black', linestyle='dotted')
)
ax1.annotate(str(startup)+" sec.",
xy=(0.25, (action+search+structure+startup)),
xycoords='data',
va='center',
xytext=(0.65, (action+search+structure+startup+15)),
arrowprops=dict(arrowstyle='-', color='black', linestyle='dotted')
)
else:
ax2.annotate(str(search)+" sec.",
xy=(0.25, search),
xycoords='data',
xytext=(0.65, search),
va='center',
arrowprops=dict(arrowstyle='-', color='black', linestyle='dotted')
)
ax2.annotate(str(startup)+" sec.",
xy=(0.25, (action+search+structure+startup)),
xycoords='data',
xytext=(0.65, (action+search+structure+startup)),
va='center',
arrowprops=dict(arrowstyle='-', color='black', linestyle='dotted')
)
ax.annotate(str(action)+" sec.",
xy=(0.25, (action+search)),
xycoords='data',
xytext=(0.65, (action+search)),
fontsize=12,
va='center',
arrowprops=dict(arrowstyle='-', color='black', linestyle='dotted')
)
ax.annotate(str(structure)+" sec.",
xy=(0.25, (action+search+structure)),
xycoords='data',
xytext=(0.65, (action+search+structure)),
va='center',
arrowprops=dict(arrowstyle='-', color='black', linestyle='dotted')
)
ax.set_xlim(-1,1)
ax1.set_ylabel("Elapsed Time in Seconds", fontsize=14)
ax1.set_xlabel("Initial Deployment", fontsize=14)
ax2.set_xlabel("Recurring Deployment", fontsize=14)
plt.subplots_adjust(right=0.8)
plt.legend(loc=(1.01,0.5))
plt.savefig('/Users/felice/Documents/master-thesis/evaluation/'+ figureName + '.pdf', transparent=True, bbox_inches='tight')
plt.show()
def drawRatioPlots(data1, data2):
countries = ['Initial Deployment', 'Recurring Deployment']
transformedData = np.column_stack((data1, data2)).astype(int)
fig, ax = plt.subplots(figsize=(16, 10))
search = np.array(transformedData[0])
action = np.array(transformedData[1])
structure = np.array(transformedData[2])
startup = np.array(transformedData[3])
ind = [x for x, _ in enumerate(countries)]
total = search + action + structure + startup
proportion_search = np.true_divide(search, total)
proportion_action = np.true_divide(action, total)
proportion_structure = np.true_divide(structure, total)
proportion_startup = np.true_divide(startup, total)
plt.bar(ind, proportion_startup, width=0.25, label='Startup', color='yellow', bottom=proportion_search+proportion_action+proportion_structure, align='center')
plt.bar(ind, proportion_structure, width=0.25, label='Structure Retrieval', color='green', bottom=proportion_action+proportion_search, align='center')
plt.bar(ind, proportion_action, width=0.25, label='Post Discovery Action', color='blue', bottom=proportion_search, align='center')
plt.bar(ind, proportion_search, width=0.25, label='Device Search', color='cyan', align='center')
plt.subplots_adjust(right=0.75)
plt.xticks(ind, countries, fontsize=14)
plt.ylabel("Ratio", fontsize=14)
plt.xlabel("Scenarios", fontsize=14)
plt.legend(loc=(1.01,0.5))
plt.ylim=1.0
plt.savefig('/Users/felice/Documents/master-thesis/evaluation/'+ figureName+'_ratio.pdf', transparent=True, bbox_inches='tight')
plt.show()
keywords = [
'Searching for devices in the network', # Start Device Search
'Finished device search', # Finished Device Search/Start post discovery actions
'Finished post discovery actions', # Finished Post Discovery Actions/ start deployment
]
figureName = sys.argv[3]
main()