-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverageDelayPlot.py
More file actions
256 lines (186 loc) · 10.3 KB
/
AverageDelayPlot.py
File metadata and controls
256 lines (186 loc) · 10.3 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
from include.Database import *
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
def getData(sensorid, fileName):
db = Database(fileName)
combinedDelayParam = {
'select' : 'PayloadTransfer.combinedDelay',
'where' : {'sensorId': sensorid}
}
offsetParam = {
'select' : 'TransferJump.RTO, TransferJump.GT',
'where' : {'nodeid' : sensorid}
}
combinedDelay = db.fetch('PayloadTransfer', combinedDelayParam)
offset = db.fetch('TransferJump', offsetParam)
return combinedDelay, offset
def divideIntoList(sqlfetch: dict):
rto = []
gt = []
for i in range(len(sqlfetch)):
rto.append(sqlfetch[i].get("RTO"))
gt.append(sqlfetch[i].get("GT"))
return rto, gt
def dict_to_list(sqlfetch: dict):
combinedDelay = []
for i in range(len(sqlfetch)):
combinedDelay.append(sqlfetch[i].get("combinedDelay"))
return combinedDelay
def accuracy_adjust(combinedDelay: list, rto: list, gt: list):
combinedDelay_RTO = []
combinedDelay_GT = []
for i in range(len(combinedDelay)):
combinedDelay_RTO.append(combinedDelay[i] - rto[i])
combinedDelay_GT.append(combinedDelay[i] - gt[i])
print("gt", combinedDelay[i], "-", gt[i])
print("RTO",combinedDelay[i], "-", rto[i])
return combinedDelay_RTO, combinedDelay_GT
def averageDelay(combinedDelay: list):
sum: float
for i in range (len(combinedDelay)):
sum =+ combinedDelay[i]
average = sum / len(combinedDelay)
return average
def readping_syncInterval_3():
with open("include/test/syncInterval_3/up0_ping.log", "r") as log:
times1 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
with open("include/test/syncInterval_3/up1_ping.log", "r") as log:
times2 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
with open("include/test/syncInterval_3/up3_ping.log", "r") as log:
times3 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
return times1, times2, times3
def readping_syncInterval_15():
with open("include/test/syncInterval_15/up0_ping.log", "r") as log:
times1 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
with open("include/test/syncInterval_15/up1_ping.log", "r") as log:
times2 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
with open("include/test/syncInterval_15/up3_ping.log", "r") as log:
times3 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
return times1, times2, times3
def readping_syncInterval_30():
with open("include/test/syncInterval_30/up0_ping.log", "r") as log:
times1 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
with open("include/test/syncInterval_30/up1_ping.log", "r") as log:
times2 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
with open("include/test/syncInterval_30/up3_ping.log", "r") as log:
times3 = [float(line.split("time=")[1].split(" ms")[0]) for line in log]
return times1, times2, times3
def addlist(list1: list, list2: list):
list3 = []
for i in range(len(list1)):
list3.append(list1[i] + list2[i])
for i in range(len(list3)):
list3[i] = int(list3[i])/2
return list3
def synchplot():
up0_ping, up1_ping, up3_ping = readping_syncInterval_3()
up0_ping_15, up1_ping_15, up3_ping_15 = readping_syncInterval_15()
up0_ping_30, up1_ping_30, up3_ping_30 = readping_syncInterval_30()
up1_up2_delay_ping = addlist(up1_ping, up0_ping)
average_up1_up2_delay_ping = averageDelay(up1_up2_delay_ping)
up3_up2_delay_ping = []
for i in range(len(up3_ping)):
up3_up2_delay_ping.append(up3_ping[i]/2)
average_up3_up2_delay_ping = averageDelay(up3_up2_delay_ping)
####
up1_up2_delay_ping_15 = addlist(up1_ping_15, up0_ping_15)
average_up1_up2_delay_ping_15 = averageDelay(up1_up2_delay_ping_15)
up3_up2_delay_ping_15 = []
for i in range(len(up3_ping_15)):
up3_up2_delay_ping_15.append(up3_ping_15[i]/2)
average_up3_up2_delay_ping_15 = averageDelay(up3_up2_delay_ping_15)
####
up1_up2_delay_ping_30 = addlist(up1_ping_30, up0_ping_30)
average_up1_up2_delay_ping_30 = averageDelay(up1_up2_delay_ping_30)
up3_up2_delay_ping_30 = []
for i in range(len(up3_ping_30)):
up3_up2_delay_ping_30.append(up3_ping_30[i]/2)
average_up3_up2_delay_ping_30 = averageDelay(up3_up2_delay_ping_30)
# 30, 15, 3
################### Synch interval 3
fileName_3 = "include/test/syncInterval_3/db.db3"
sensor_up1_Delay_3, sensor_up1_offset_3 = getData(2, fileName_3)
rto_3, gt_3 = divideIntoList(sensor_up1_offset_3)
combinedDelay_3 = dict_to_list(sensor_up1_Delay_3)
combinedDelay_RTO_3, combinedDelay_GT_3 = accuracy_adjust(combinedDelay_3, rto_3, gt_3)
averageDelay_RTO_3 = averageDelay(combinedDelay_RTO_3)
averageDelay_GT_3 = averageDelay(combinedDelay_GT_3)
sensor_up2_Delay_3, sensor_up2_offset_3 = getData(4, fileName_3)
sensor2_rto_3, sensor2_gt_3 = divideIntoList(sensor_up2_offset_3)
sensor2_combinedDelay_3 = dict_to_list(sensor_up2_Delay_3)
sensor2_combinedDelay_RTO_3, sensor2_combinedDelay_GT_3 = accuracy_adjust(sensor2_combinedDelay_3, sensor2_rto_3, sensor2_gt_3)
sensor2_averageDelay_RTO_3 = averageDelay(sensor2_combinedDelay_RTO_3)
sensor2_averageDelay_GT_3 = averageDelay(sensor2_combinedDelay_GT_3)
#################3# Synch interval 15
fileName_15 = "include/test/syncInterval_15/db.db3"
Delay_15, offset_15 = getData(2, fileName_15)
rto_15, gt_15 = divideIntoList(offset_15)
combinedDelay_15 = dict_to_list(Delay_15)
combinedDelay_RTO_15, combinedDelay_GT_15 = accuracy_adjust(combinedDelay_15, rto_15, gt_15)
# print(combinedDelay_RTO_15)
print(combinedDelay_GT_15)
averageDelay_RTO_15 = averageDelay(combinedDelay_RTO_15)
averageDelay_GT_15 = averageDelay(combinedDelay_GT_15)
print("Average Delay GT", averageDelay_GT_15)
print("Average Delay RTO",averageDelay_RTO_15)
sensor_up2_Delay_15, sensor_up2_offset_15 = getData(4, fileName_15)
sensor2_rto_15, sensor2_gt_15 = divideIntoList(sensor_up2_offset_15)
sensor2_combinedDelay_15 = dict_to_list(sensor_up2_Delay_15)
sensor2_combinedDelay_RTO_15, sensor2_combinedDelay_GT_15 = accuracy_adjust(sensor2_combinedDelay_15, sensor2_rto_15, sensor2_gt_15)
sensor2_averageDelay_RTO_15 = averageDelay(sensor2_combinedDelay_RTO_15)
sensor2_averageDelay_GT_15 = averageDelay(sensor2_combinedDelay_GT_15)
print(sensor2_combinedDelay_RTO_15)
print(sensor2_averageDelay_RTO_15)
###################### Synch interval 30
fileName_30 = "include/test/syncInterval_30/db.db3"
Delay_30, offset_30= getData(2, fileName_30)
rto_30, gt_30 = divideIntoList(offset_30)
combinedDelay_30 = dict_to_list(Delay_30)
combinedDelay_RTO_30, combinedDelay_GT_30 = accuracy_adjust(combinedDelay_30, rto_30, gt_30)
averageDelay_RTO_30= averageDelay(combinedDelay_RTO_30)
averageDelay_GT_30 = averageDelay(combinedDelay_GT_30)
sensor_up2_Delay_30, sensor_up2_offset_30 = getData(4, fileName_30)
sensor2_rto_30, sensor2_gt_30 = divideIntoList(sensor_up2_offset_30)
sensor2_combinedDelay_30 = dict_to_list(sensor_up2_Delay_30)
sensor2_combinedDelay_RTO_30, sensor2_combinedDelay_GT_30 = accuracy_adjust(sensor2_combinedDelay_30, sensor2_rto_30, sensor2_gt_30)
sensor2_averageDelay_RTO_30 = averageDelay(sensor2_combinedDelay_RTO_30)
sensor2_averageDelay_GT_30 = averageDelay(sensor2_combinedDelay_GT_30)
averageDelay_RTO = [averageDelay_RTO_3, averageDelay_RTO_15, averageDelay_RTO_30]
averageDelay_GT = [averageDelay_GT_3, averageDelay_GT_15, averageDelay_GT_30]
averageDelay_ping_up0_up2 = [average_up1_up2_delay_ping, average_up1_up2_delay_ping_15, average_up1_up2_delay_ping_30]
sensor2_averageDelay_RTO = [sensor2_averageDelay_RTO_3, sensor2_averageDelay_RTO_15, sensor2_averageDelay_RTO_30]
sensor2_averageDelay_GT = [sensor2_averageDelay_GT_3, sensor2_averageDelay_GT_15, sensor2_averageDelay_GT_30]
averageDelay_ping_up3_up2 = [average_up3_up2_delay_ping, average_up3_up2_delay_ping_15, average_up3_up2_delay_ping_30]
for i in range(len(averageDelay_GT)):
averageDelay_RTO[i] = averageDelay_RTO[i]*1000
averageDelay_GT[i] = averageDelay_GT[i]*1000
sensor2_averageDelay_RTO[i] = sensor2_averageDelay_RTO[i] * 1000
sensor2_averageDelay_GT[i] = sensor2_averageDelay_GT[i] * 1000
print("Sensor2 - Average Delay Ping",averageDelay_ping_up3_up2)
print("Sensor1 - Average Delay Ping",averageDelay_ping_up0_up2)
print("Sensor2 - Average Delay GT",sensor2_averageDelay_GT)
print("Sensor2 - Average Delay RTO",sensor2_averageDelay_RTO)
x = [3, 15, 30]
fig, sync = plt.subplots()
fig.suptitle("Sensor:1Average delay for different synch intervals")
sync.plot(x, averageDelay_GT, "r", label="Sensor1: AverageDelay of GT", marker="o" , linestyle=':')
sync.plot(x, averageDelay_RTO, "b", label="sensor1: AverageDelay of RTO",marker="o", linestyle='dotted')
sync.plot(x, averageDelay_ping_up0_up2, "g", label="sensor1: AverageDelay of Ping", marker="o",linestyle=':')
sync.set_xlabel("synchronization interval")
sync.set_ylabel("Average Delay")
# sync.plot(x,sensor2_averageDelay_GT, "g", label="sensor2: AverageDelay of GT")
# sync.plot(x,sensor2_averageDelay_RTO, "y", label="sensor2: AverageDelay of RTO")
sync.legend(loc="best")
fig.savefig("include/test/syncInterval_3/AverageDelay_syncInterval_sensor1")
fig2, sync2 = plt.subplots()
fig2.suptitle("Sensor2: Average delay for different synch intervals")
sync2.plot(x,sensor2_averageDelay_GT, "g", label="sensor2: AverageDelay of GT", marker="o",linestyle=':')
sync2.plot(x,sensor2_averageDelay_RTO, "y", label="sensor2: AverageDelay of RTO", marker="o",linestyle=':')
sync2.plot(x, averageDelay_ping_up3_up2, "b", label="sensor2: AverageDelay of Ping", marker="o",linestyle=':')
sync2.legend(loc="best")
sync2.set_xlabel("synchronization interval")
sync2.set_ylabel("Average Delay")
fig2.savefig("include/test/syncInterval_3/AverageDelay_syncInterval_sensor2")
plt.show()
synchplot()