This repository has been archived by the owner on Apr 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation
executable file
·185 lines (144 loc) · 5.98 KB
/
evaluation
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
#!/usr/bin/env python2.7
import os
import sys
import numpy as np
#import table
from math import sqrt
import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import pylab
from scalarfileparser import ScalarFileParser
import json
import pprint
def main():
# invocation of the script is always ./evaluation example.json
if len(sys.argv) != 2:
sys.exit(1)
with open(sys.argv[1]) as configuration_file:
configuration = json.load(configuration_file)
results = {}
# get the directory to parse from the json file
directory = configuration["directory"]
if not directory.endswith("/"):
directory = directory + "/"
# same goes for the title, xlabel, and ylabel of the plot
title = configuration["plot"]["title"]
xlabel = configuration["plot"]["xlabel"]
ylabel = configuration["plot"]["ylabel"]
# set the filename of the plot
current_filename = configuration["plot"]["file"]
# get the data
for result_file in os.listdir(directory):
if result_file.endswith(".sca"):
parser = ScalarFileParser(directory + result_file)
data = parser.read()
offset = float(data.parameters['offset'])
# let's write the offset in ms not in percent
offset = offset * 983.04
if "0.75" in result_file:
offset = -1 * (983.04 - offset)
#else:
# offset = 983.04 - offset
if offset not in results:
results[offset] = {}
for node in data.nodes.keys():
if node not in results[offset]:
results[offset][node] = []
# compute the packet reception rate = received packets/sent packets
sent_packets = float(data.nodes['2']['sent:count'])
arrived_packets = float(data.nodes['0']['arrival:count'])
packet_reception_rate = float(arrived_packets/sent_packets)
results[offset]['0'].append(packet_reception_rate)
sent_packets = float(data.nodes['3']['sent:count'])
arrived_packets = float(data.nodes['1']['arrival:count'])
packet_reception_rate = float(arrived_packets/sent_packets)
results[offset]['1'].append(packet_reception_rate)
# sort the offsets
offsets = sorted(results.keys(), key=float)
# define our coordinators
nodes = ['0','1']
print(offsets)
# we are going to have a plot with broken axes
figure, axis = plt.subplots(1)
plt.subplots_adjust(bottom=0.2, top=0.8)
# in milimeters
textwidth = 183.0
# convert textwdith to inches
inches_per_mm = 0.039370
# get aesthetic ratio
golden_mean = (sqrt(5)-1.0)/2.0
# width in inches
fig_width = textwidth * inches_per_mm
# height in inches
fig_height = fig_width * golden_mean
fig_size = [fig_width,fig_height]
figure.set_size_inches(fig_width,fig_height)
#plt.set_cmap('cubehelix')
colors = ["#FF9900", "#0A50A7", "#00A3A7"]
# update the parameters
params = {'backend': 'ps',
'axes.labelsize': 12,
'font.size': 14,
'legend.fontsize': 14,
'xtick.labelsize': 12,
'ytick.labelsize': 12,
'text.usetex': True,
'figure.figsize': fig_size}
pylab.rcParams.update(params)
#colors = [(255/255, 153/255, 0), (10/255, 80/255, 167/255), (0, 153/255, 167/255)]
# plot the data
for node in nodes:
average = []
minimum = []
maximum = []
standev = []
for offset in offsets:
#average_per_offset = np.average(results[offset][node])
average_per_offset = np.mean(results[offset][node])
average.append(average_per_offset)
minimum_per_offset = np.amin(results[offset][node])
minimum.append(minimum_per_offset)
maximum_per_offset = np.amax(results[offset][node])
maximum.append(maximum_per_offset)
std_per_offset = np.std(results[offset][node])
standev.append(std_per_offset)
# let's set the network type for the labels
network_type = configuration["network-properties"][node]
# should we print the coordinators of the network
if configuration["network-properties"]["index"]:
network_type = network_type + "$_{" + node + "}$"
# test
average = np.array(average)
standev = np.array(standev)
# xlim
plt.xlim(min(offsets)-0.05, max(offsets)+0.05)
plt.ylim(min(minimum)-0.05, max(minimum)+0.05)
round10 = lambda x: 10 * int(x / 10.)
# plt.xticks(np.arange(round10(min(offsets)), round10(max(offsets)) + 1, 60))
plt.xticks(np.arange(round10(min(offsets)), round10(max(offsets)) + 1, 20))
plt.yticks(np.arange(min(minimum), max(maximum)+0.10, 0.20))
# let's see if we want to plot mean +/- std or mean + max and mean - min
base_line, = axis.plot(offsets, average, color=colors[int(node)], lw=2, label=network_type)
if configuration["plot"]["std"]:
axis.fill_between(offsets, average+standev, average-standev,
color=colors[int(node)], alpha=0.2)
else:
axis.fill_between(offsets, maximum, minimum,
color=colors[int(node)], alpha=0.2)
# enable grid
axis.grid()
# title: plt.title(title)
# labels
figure.text(0.5, 0.04, xlabel, ha='center', va='center')
figure.text(0.04, 0.5, ylabel, ha='center', va='center', rotation='vertical')
# put the legend inside the figure
# plt.legend(loc=0)
# plt.legend(bbox_to_anchor=(1.13, 1), loc=2, borderaxespad=0.)
# put the legend above the figure (currently only above one axis)
#plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)
plt.legend(bbox_to_anchor=(0., 1.00, 1., .102), loc=3, ncol=2, borderaxespad=0., frameon=False)
figure.savefig(current_filename)
plt.close()
if __name__ == "__main__":
main()