-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresults_export.py
157 lines (131 loc) · 8.3 KB
/
results_export.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
import csv
import os
import sqlite3
import bootstrapped.bootstrap as bs
import bootstrapped.stats_functions as bs_stats
import numpy
from sim_for_fixed_joining_node import Scenario
from ieee802154.tsch.joining_phase_simulator import EBSchedulingMethod
simulations_with_fixed_nodes = [
(EBSchedulingMethod.CFASV, Scenario.ANY, False), (EBSchedulingMethod.CFASV, Scenario.ANY, True),
(EBSchedulingMethod.CFASH, Scenario.ANY, False), (EBSchedulingMethod.CFASH, Scenario.ANY, True),
(EBSchedulingMethod.ECFASV, Scenario.ONE_HOP, False), (EBSchedulingMethod.ECFASV, Scenario.ONE_HOP, True),
(EBSchedulingMethod.ECFASV, Scenario.TWO_HOPS, False), (EBSchedulingMethod.ECFASV, Scenario.TWO_HOPS, True),
(EBSchedulingMethod.ECFASH, Scenario.ONE_HOP, False), (EBSchedulingMethod.ECFASH, Scenario.ONE_HOP, True),
(EBSchedulingMethod.ECFASH, Scenario.TWO_HOPS, False), (EBSchedulingMethod.ECFASH, Scenario.TWO_HOPS, True),
(EBSchedulingMethod.ECV, Scenario.ONE_HOP), (EBSchedulingMethod.ECV, Scenario.TWO_HOPS),
(EBSchedulingMethod.ECH, Scenario.ONE_HOP),
(EBSchedulingMethod.ECH, Scenario.TWO_HOPS),
(EBSchedulingMethod.Minimal6TiSCH, Scenario.ANY),
(EBSchedulingMethod.Minimal6TiSCH, Scenario.ANY),
(EBSchedulingMethod.MAC_BASED_AS, Scenario.ANY),
(EBSchedulingMethod.EMAC_BASED_AS, Scenario.ONE_HOP),
(EBSchedulingMethod.EMAC_BASED_AS, Scenario.TWO_HOPS)
]
simulations_with_mobile_node = [
(EBSchedulingMethod.ECV,), (EBSchedulingMethod.ECH,),
(EBSchedulingMethod.Minimal6TiSCH,), (EBSchedulingMethod.ECFASV, False), (EBSchedulingMethod.ECFASV, True),
(EBSchedulingMethod.CFASV, False), (EBSchedulingMethod.CFASV, True),
(EBSchedulingMethod.CFASH, False), (EBSchedulingMethod.CFASH, True),
(EBSchedulingMethod.ECFASH, False), (EBSchedulingMethod.ECFASH, True),
(EBSchedulingMethod.MAC_BASED_AS,),
(EBSchedulingMethod.EMAC_BASED_AS,)
]
simulations_for_energy = [
(EBSchedulingMethod.ECV,), (EBSchedulingMethod.ECH,),
(EBSchedulingMethod.Minimal6TiSCH,), (EBSchedulingMethod.ECFASV, False), (EBSchedulingMethod.ECFASV, True),
(EBSchedulingMethod.CFASV, False), (EBSchedulingMethod.CFASV, True),
(EBSchedulingMethod.CFASH, False), (EBSchedulingMethod.CFASH, True),
(EBSchedulingMethod.ECFASH, False), (EBSchedulingMethod.ECFASH, True),
(EBSchedulingMethod.MAC_BASED_AS,),
(EBSchedulingMethod.EMAC_BASED_AS,)
]
os.makedirs(os.path.join("filtered_statistics", "fixed_joining_node"), exist_ok=True)
os.makedirs(os.path.join("filtered_statistics", "mobile_joining_node"), exist_ok=True)
os.makedirs(os.path.join("filtered_statistics", "energy_consumption"), exist_ok=True)
for sim in simulations_with_fixed_nodes:
scheduling_method = sim[0]
selected_scenario = sim[1]
atp_enabled = sim[2] if len(sim) == 3 else False
db_name = "{}{}{}".format(scheduling_method.name, ("_with_ATP" if atp_enabled else ""),
("_{}".format(selected_scenario.name) if selected_scenario is not Scenario.ANY else ""))
db_conn = sqlite3.connect(os.path.join("statistics", "fixed_joining_node", "{}.db".format(db_name)))
db_conn.row_factory = sqlite3.Row
c = db_conn.cursor()
export_file = os.path.join("filtered_statistics", "fixed_joining_node", "{}.csv".format(db_name))
with open(export_file, 'w', newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
if scheduling_method not in {EBSchedulingMethod.ECV, EBSchedulingMethod.ECH}:
csv_writer.writerow(["Neighboring Advertisers", "Joining Time (s)"])
csv_writer.writerow([""] + ["AVG", "CI_LL", "CI_UL"])
else:
csv_writer.writerow(["Neighboring Advertisers", "Joining Time (s)", "", "", "Sensed Slots", "", "",
"EB Scheduling Delay"])
csv_writer.writerow([""] + ["AVG", "CI_LL", "CI_UL"] * 3)
for advertisers in range(1, 11):
record = [advertisers]
if scheduling_method not in {EBSchedulingMethod.ECV, EBSchedulingMethod.ECH}:
joining_time_samples = [row[0] for row in c.execute(
'''SELECT time FROM joining_time_samples WHERE neighboring_advertisers=?''',
(advertisers,))]
res = bs.bootstrap(numpy.asarray(joining_time_samples), stat_func=bs_stats.mean, num_iterations=1000)
record += [res.value, res.lower_bound, res.upper_bound]
else:
joining_time_samples = []
sensed_slots_samples = []
eb_scheduling_delay_samples = []
for row in c.execute('''SELECT * FROM joining_time_samples WHERE neighboring_advertisers=?''',
(advertisers,)):
joining_time_samples.append(row["time"])
sensed_slots_samples.append(row["num_adv_slots_sensed"])
eb_scheduling_delay_samples.append(row["eb_scheduling_delay"])
res = bs.bootstrap(numpy.asarray(joining_time_samples), stat_func=bs_stats.mean, num_iterations=1000)
record += [res.value, res.lower_bound, res.upper_bound]
res = bs.bootstrap(numpy.asarray(sensed_slots_samples), stat_func=bs_stats.mean, num_iterations=1000)
record += [res.value, res.lower_bound, res.upper_bound]
res = bs.bootstrap(numpy.asarray(eb_scheduling_delay_samples), stat_func=bs_stats.mean,
num_iterations=1000)
record += [res.value, res.lower_bound, res.upper_bound]
csv_writer.writerow(record)
for sim in simulations_with_mobile_node:
scheduling_method = sim[0]
atp_enabled = sim[1] if len(sim) == 2 else False
db_name = "{}{}".format(scheduling_method.name, ("_with_ATP" if atp_enabled else ""))
db_conn = sqlite3.connect(os.path.join("statistics", "mobile_joining_node", "{}.db".format(db_name)))
db_conn.row_factory = sqlite3.Row
c = db_conn.cursor()
export_file = os.path.join("filtered_statistics", "mobile_joining_node", "{}.csv".format(db_name))
with open(export_file, 'w', newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(["Advertisers", "Joining Time (s)", "", ""])
csv_writer.writerow([""] + ["AVG", "CI_LL", "CI_UL"])
for num_advertisers in range(10, 151, 10): # excluding PAN coordinator
record = [num_advertisers]
mobile_node_joining_time_samples = []
for row in c.execute('''SELECT * FROM mobile_node_joining_time_samples WHERE advertisers=?''',
(num_advertisers,)):
mobile_node_joining_time_samples.append(row["time"])
res = bs.bootstrap(numpy.asarray(mobile_node_joining_time_samples), stat_func=bs_stats.mean,
num_iterations=1000)
record += [res.value, res.lower_bound, res.upper_bound]
csv_writer.writerow(record)
for sim in simulations_for_energy:
scheduling_method = sim[0]
atp_enabled = sim[1] if len(sim) == 2 else False
db_name = "{}{}".format(scheduling_method.name, ("_with_ATP" if atp_enabled else ""))
db_conn = sqlite3.connect(os.path.join("statistics", "energy_consumption", "{}.db".format(db_name)))
db_conn.row_factory = sqlite3.Row
c = db_conn.cursor()
export_file = os.path.join("filtered_statistics", "energy_consumption", "{}.csv".format(db_name))
with open(export_file, 'w', newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow(["Nodes", "Energy Consumption (J)", "", ""])
csv_writer.writerow([""] + ["AVG", "CI_LL", "CI_UL"])
for num_nodes in range(10, 151, 10): # excluding PAN coordinator
record = [num_nodes]
energy_consumption_samples = []
for row in c.execute('''SELECT * FROM energy_consumption_samples WHERE num_nodes=?''', (num_nodes,)):
energy_consumption_samples.append(row["energy_consumption"])
res = bs.bootstrap(numpy.asarray(energy_consumption_samples), stat_func=bs_stats.mean, num_iterations=1000)
record += [res.value, res.lower_bound, res.upper_bound]
csv_writer.writerow(record)