-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotting_module.py
240 lines (195 loc) · 7.18 KB
/
plotting_module.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
"""
Functions for plotting measurement results of Digital Twin Web.
"""
import os
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Set style for figures
try:
from distutils.spawn import find_executable
if find_executable('latex'):
# print("Latex installed")
plt.style.use(['science','ieee'])
print('Using SciencePlots IEEE style for figures: https://github.com/garrettj403/SciencePlots#faq')
# print('If you get weird errors, you may have to install LaTeX: https://github.com/garrettj403/SciencePlots#faq')
else:
print('Did not find LaTeX, using manually defined styles for figures')
print('More info: https://github.com/garrettj403/SciencePlots#faq')
raise Exception
except:
plt.rcParams.update({'font.size': 8})
def plot_network_fetch_times(filepath: str, folderpath: str, registry_domain: str):
"""
Plots network measurement
Args:
filepath: Path to measurement log file
folderpath: Path to folder where all measurement result files will be written.
registry_domain: internet domain address of the DTID registry for figure title
"""
width = 2.3 # inches
height = 3.5 # inches
df = pd.read_csv(filepath)
print(filepath)
# Check max depth
df = df[df['Event'] == 'DT doc received']
max_depth = int(df["Depth"].max())
print('Max depth: ' + str(max_depth))
fig, axes = plt.subplots(figsize=(width,height))
# Prepare data
violindata = []
quantiles = []
labels = []
for depth in range(max_depth+1):
violindata.append(df[df.Depth == str(depth)]["Time"].values.astype('float'))
quantiles.append([0,0.5,0.99])
labels.append(str(depth))
# Plot
plot = axes.violinplot(dataset = violindata,
points=100,
widths=0.9,
showmeans=False, showextrema=False, showmedians=False,
quantiles=quantiles,
# bw_method=0.1
)
plot['cquantiles'].set_linewidth(0.5)
# axes.violinplot(dataset = violindata,
# points=100,
# widths=0.9,
# showmeans=False, showextrema=False, showmedians=False,
# # quantiles=quantiles,
# bw_method=0.05)
# Set texts to figure
axes.set_title('DTID registry: ' + registry_domain)
axes.yaxis.grid(True)
axes.set_xlabel('Depth in the network (steps from origin)')
axes.set_ylabel('Fetch time (s)')
axes.set_ylim(bottom=0)
axes.set_xticks(range(1,max_depth+2))
axes.set_xticklabels(labels)
# plt.xticks(rotation=90)
plt.tight_layout()
figurename = 'fetch_times_network_' + registry_domain + '.pdf'
fig.savefig(os.path.join(folderpath, figurename))
return True
def plot_registry_fetch_times(filepath, folderpath, dtids):
"""
Plots registry comparison measurement
Args:
filepath: Path to measurement log file
folderpath: Path to folder where all measurement result files will be written.
dtids: List of DTIDs to be plotted
"""
df = pd.read_csv(filepath)
#### VIOLIN simple ####
# https://stackoverflow.com/questions/43345599/process-pandas-dataframe-into-violinplot
fig, axes = plt.subplots(figsize=(3.5,3.5))
# Prepare data
df = df[df['Event'] == 'DT doc received']
violindata = []
quantiles = []
labels = []
stddev = {}
anomalies = {}
for dtid in dtids:
reg = dtid.split('/')[2]
violindata.append(df[df.Base == dtid]["Time"].values.astype('float'))
anomalies[reg] = 0
for idx, val in enumerate(violindata[-1]):
if val > 2:
anomalies[reg] += 1
violindata[-1] = np.delete(violindata[-1], idx)
stddev[reg] = np.std(violindata[-1])
quantiles.append([0,0.5,0.99])
labels.append(reg)
print('Standard deviations:')
print(stddev)
# Plot
plot = axes.violinplot(dataset = violindata,
points=100,
widths=0.9,
showmeans=False, showextrema=False, showmedians=False, \
quantiles=quantiles,
bw_method=0.1)
plot['cquantiles'].set_linewidth(0.5)
# Set texts to figure
# axes.set_title('Fetch time')
axes.yaxis.grid(True)
axes.set_xlabel('Domain name of registry')
axes.set_ylabel('Fetch time (s)')
axes.set_ylim([0, 2])
axes.set_xticks(range(1,len(dtids)+1))
axes.set_xticklabels(labels)
plt.xticks(rotation=90)
plt.tight_layout()
# Add numbers of anomalies
anomalies_text = 'Anomalies:'
for key in anomalies:
if anomalies[key] > 0:
anomalies_text += '\n' + key + ': ' + str(anomalies[key])
axes.text(0.95, 0.95, anomalies_text,
transform=axes.transAxes,
verticalalignment='top',
horizontalalignment = 'right',
bbox=dict(facecolor='white', linewidth=0.5))
fig.savefig(os.path.join(folderpath, "base_fetch_times_violin.png"))
fig.savefig(os.path.join(folderpath, "base_fetch_times_violin.pdf"))
# VIOLIN with divided base & registry ####
# https://stackoverflow.com/questions/43345599/process-pandas-dataframe-into-violinplot
df = pd.read_csv(filepath)
fig, axes = plt.subplots(figsize=(3.5,3.5))
# Prepare data
df_dh = df[df['Event'] == 'DTID > hosturl fetch time']
violindata_dh = []
quantiles = []
labels = []
for dtid in dtids:
violindata_dh.append(df_dh[df_dh.Base == dtid]["Time"].values.astype('float'))
quantiles.append([0,0.5,0.99,1])
labels.append(dtid.split('/')[2])
# Plot
plot_dh = axes.violinplot(dataset = violindata_dh,
points=100,
widths=0.9,
showmeans=False, showextrema=False, showmedians=False, \
quantiles=quantiles,
# bw_method=0.1
)
plot_dh['cquantiles'].set_linewidth(0.5)
plot_dh = axes.violinplot(dataset = violindata_dh,
points=100,
widths=0.9,
showmeans=False, showextrema=False, showmedians=False, \
quantiles=quantiles,
bw_method=0.1
)
plot_dh['cquantiles'].set_linewidth(0.5)
# Prepare data
df_hosdoc = df[df['Event'] == 'Hosturl > DT doc fetch time']
violindata_hosdoc = []
quantiles = []
labels = []
for dtid in dtids:
violindata_hosdoc.append(df_hosdoc[df_hosdoc.Base == dtid]["Time"].values.astype('float'))
quantiles.append([0,0.5,0.99,1])
labels.append(dtid.split('/')[2])
# Plot
plot_hosdoc = axes.violinplot(dataset = violindata_hosdoc, points=100, widths=0.9, showmeans=False, showextrema=False, showmedians=False, \
quantiles=quantiles,
bw_method=0.1)
# Set texts to figure
# axes.set_title('Fetch time')
axes.yaxis.grid(True)
# axes.set_xlabel('Base number')
axes.set_ylabel('Time (s)')
axes.set_ylim([0, 2])
axes.set_xticks(range(1,len(dtids)+1))
axes.set_xticklabels(labels)
plt.xticks(rotation=90)
plt.tight_layout()
plot_hosdoc['cquantiles'].set_linewidth(0.5)
fig.savefig(os.path.join(folderpath, "base_fetch_times_violin_divided.png"))
fig.savefig(os.path.join(folderpath, "base_fetch_times_violin_divided.pdf"))
return True
if __name__ == '__main__':
print('Use the "run_measurements.py file to run and plot measurements')