def main(): files = my.get_grouped_files(source_path=source_path, delay=delay, index_delay=index_delay) i = 1 my_list_ble = dict() my_list_wifi = dict() my_list_total = dict() my_list_times = dict() # cambio delay_wifi_send my_list_times_1 = dict() # cambio delay_wifi_send for item in files: print("\x1b[1;30;43m " + str(i) + " \x1b[1;34;40m " + item[28:] + " \x1b[0m ") data = my.open_file_and_return_data(path=item) if i == 1: my_dictionary['_command'] = data['_command'] l_ble, l_wifi, latency = statistics(data=data, run=i) t, t1 = get_times_change_delay(data['_time'], data['_command']['delay'], data['_info']) my_list_ble[i] = l_ble my_list_wifi[i] = l_wifi my_list_total[i] = latency my_list_times[i] = t my_list_times_1[i] = t1 i += 1 # Summary summary_statistics() save_statistics_data() # PLOT plot_1(my_list_ble, my_list_wifi, my_list_total, my_list_times, my_list_times_1)
def main(): my_list_ble = dict() my_list_wifi = dict() for index_delay in range(len(delay)): source_path = my.path_media + "json_file/relay_" + str(relay[index_relay]) + "/delay_" + str( delay[index_delay]) + "/*_analysis.json" cuts_path = my.path_media + "json_file/relay_" + str(relay[index_relay]) + "/outcomes/cuts/delay_x_" + str( delay[index_delay]) + ".json" files = my.get_grouped_files(source_path=source_path, delay=delay, index_delay=index_delay) cuts = my.open_file_and_return_data(path=cuts_path) i = 1 my_list_ble[delay[index_delay]] = dict() my_list_wifi[delay[index_delay]] = dict() for item in files: data = my.open_file_and_return_data(path=item)['_mex'] l_ble, l_wifi = get_all_value_cuts(dataset=data, run=i, cut=cuts) my_list_ble[delay[index_delay]][i] = l_ble my_list_wifi[delay[index_delay]][i] = l_wifi i += 1 df = get_list_and_return_df(my_list_ble, 'ble', 'latency') define_base_plot() # plot(df, "BLE", 'latency') smooth_interpolation(df, 'ble', 'latency')
def main(): files = my.get_grouped_files(source_path=source_path, delay=delay, index_delay=index_delay) path = delay_path + "delay_" + str(delay[index_delay]) + ".json" data_delay = my.open_file_and_return_data(path=path) i = 1 err = list() dictionaries = dict() data = dict() for item in files: data = my.open_file_and_return_data(path=item) print("\x1b[1;30;43m " + item[28:] + " \x1b[0m ") start = dt.datetime.strptime(data_delay[str(i)]['_info']['start'], '%Y-%m-%d %H:%M:%S.%f') end = dt.datetime.strptime(data_delay[str(i)]['_info']['end_sent'], '%Y-%m-%d %H:%M:%S.%f') # TODO shift focus about data --- duration 4 minute new_start = start + dt.timedelta(0, 30) # right shift --> default 40 s new_end = new_start + dt.timedelta(0, 240) # 4m <- (60s*4) # end = end - dt.timedelta(0, 15) new_diff = new_end - new_start h, m, s = my.convert_timedelta(new_diff) fault, outcome = analysis(data, new_start, new_end, i) print("start: {} -- end: {} --- {}:{}.{} -- min: {} -- max: {}".format( new_start, new_end, h, m, s, outcome['smaller'], outcome['bigger'])) time = str(h) + ":" + str(m) + "." + str(s) + " [h:m.s]" outcome['time'] = { 'old_start': start, 'old_end': end, 'new_start': new_start, 'new_end': new_end, 'new_time': time } err.append(fault) dictionaries[i] = outcome i += 1 mex_removed = (60 * 1000) / delay[index_delay] total = data['_command']['n_mex'] - mex_removed print("\x1b[1;34;40m [{}] Mex_removed: {} --> total: {} \x1b[0m ".format( delay[index_delay], mex_removed, total)) print("err: --> ", err) dictionaries['error'] = err dictionaries['info'] = {'mex_removed': mex_removed, 'n_mex': total} save_data(dictionaries)
def main(): files = my.get_grouped_files(source_path=source_path, delay=delay, index_delay=index_delay) cuts = my.open_file_and_return_data(path=cuts_path) i = 1 my_list_ble = dict() for item in files: print("\x1b[1;30;43m " + str(i) + " \x1b[1;34;40m " + item[28:] + " \x1b[0m ") data = my.open_file_and_return_data(path=item) if i == 1: my_dictionary['_command'] = data['_command'] l_ble = statistics(data=data, run=i, x=cuts) my_list_ble[i] = l_ble i += 1 # Summary summary_statistics() # PLOT plot_1(my_list_ble)
def main_cut(): my_list_ble = dict() if directory == 'ble_wifi_output': my_list_wifi = dict() my_list_total = dict() for index_delay in range(len(delay)): source_path = my.path_media + "json_file/" + directory + "/relay_" + str( relay[index_relay]) + "/" + str( delay[index_delay]) + "/*_analysis.json" cuts_path = my.path_media + "json_file/" + directory + "/relay_" + str( relay[index_relay]) + "/x/delay_x_" + str( delay[index_delay]) + ".json" files = my.get_grouped_files(source_path=source_path, delay=delay, index_delay=index_delay) cuts = my.open_file_and_return_data(path=cuts_path) i = 1 my_list_ble[delay[index_delay]] = dict() if directory == 'ble_wifi_output': my_list_wifi[delay[index_delay]] = dict() my_list_total[delay[index_delay]] = dict() for item in files: data = my.open_file_and_return_data(path=item)['_mex'] if directory == 'ble_wifi_output': l_ble, l_wifi, l_total = get_all_value_cuts(dataset=data, run=i, cut=cuts) my_list_ble[delay[index_delay]][i] = l_ble my_list_wifi[delay[index_delay]][i] = l_wifi my_list_total[delay[index_delay]][i] = l_total else: l_ble = get_all_value_cuts_ble(dataset=data, run=i, cut=cuts) my_list_ble[delay[index_delay]][i] = l_ble i += 1 plot(my_list_ble, "BLE") plot(my_list_wifi, "WiFi") plot(my_list_total, "BLE - WiFi")
def main_2(): my_list = {'delay': list(), 'latency': list(), 'type': list()} for index_delay in range(len(delay)): source_path = my.path_media + "json_file/ble_wifi_output/relay_" + str( relay[index_relay]) + "/" + str( delay[index_delay]) + "/*_analysis.json" cuts_path = my.path_media + "json_file/ble_wifi_output/relay_" + str( relay[index_relay]) + "/x/delay_x_" + str( delay[index_delay]) + ".json" files = my.get_grouped_files(source_path=source_path, delay=delay, index_delay=index_delay) cuts = my.open_file_and_return_data(path=cuts_path) i = 1 for item in files: data = my.open_file_and_return_data(path=item) pxs, pys, pzs = get_all_value_2(dataset=data, run=i, cut=cuts) my_list['delay'].append(pxs) my_list['latency'].append(pys) my_list['type'].append(pzs) i += 1 pxs = list() pys = list() pzs = list() runs = len(my_list['delay']) for r in range(runs): item = len(my_list['delay'][r]) for i in range(item): pxs.append(my_list['delay'][r][i]) pys.append(my_list['latency'][r][i]) pzs.append(my_list['type'][r][i]) dataframe = {'delay': pxs, 'y_data': pys, 'type': pzs} df = pd.DataFrame(dataframe) print(df.head()) plot_2(df)
def main_3(): x = list() y = list() z = list() dictionary = dict() if directory == 'ble_output': tech = " - [BLE]" else: tech = " - [BLE - WiFi]" if type_graph == 'latency': y_label = 'Latency (s)' title = 'Latency' + tech name = directory[:-6] + 'latency.png' elif type_graph == 'pdr': y_label = 'Packet Delivery Ratio' title = y_label + tech name = directory[:-6] + 'pdr.png' else: y_label = 'Goodput (byte/s)' title = 'Goodput' + tech name = directory[:-6] + 'goodput.png' for r in range(len(relay)): dictionary[r] = {'x': list(), 'y': list()} for d in range(len(delay)): path = my.path_media + "json_file/" + directory + "/relay_" + str( relay[r]) + "/x/delay_XXX_" + str(delay[d]) + ".json" files = my.get_grouped_files(source_path=path, delay=delay, index_delay=d) i = 1 for item in files: data = my.open_file_and_return_data(path=item) t = 'config_' + str(int(r + 1)) z.append(t) time_ = convert_time_in_num(data['_command']['delay']) x.append(time_) dictionary[r]['x'].append(time_) if directory == 'ble_wifi_output': if type_graph == 'latency': value = data['summary']['statistic_']['total'][ type_graph]['mean'] else: value = data['summary']['statistic_']['total'][ type_graph] else: if type_graph == 'latency': value = data['summary']['statistic_'][type_graph][ 'mean'] else: value = data['summary']['statistic_'][type_graph] y.append(value) dictionary[r]['y'].append(value) i += 1 dataframe = {'delay': x, 'y_data': y, 'type': z} df = pd.DataFrame(dataframe) print(df.head()) print("path: " + my.path_media + "json_file/" + directory + "/last_plot/") print("name: " + name) plot_3(df, dictionary, y_label, title) plot_x(df, dictionary, y_label, title)
def main_4(): x = list() y = list() z = list() dir = ['ble_wifi_output', 'ble_output'] dictionary = dict() if type_graph == 'latency': y_label = 'Latency (s)' title = 'Latency' name = 'mixed_latency.png' elif type_graph == 'pdr': y_label = 'Packet Delivery Ratio' title = y_label name = 'mixed_pdr.png' else: y_label = 'Goodput (byte/s)' title = 'Goodput' name = 'mixed_goodput.png' for d1 in dir: if d1 == 'ble_wifi_output': hue = 'ble_wifi' else: hue = 'ble' dictionary[hue] = dict() for r in range(len(relay)): dictionary[hue][r] = {'x': list(), 'y': list()} for d in range(len(delay)): path = my.path_media + "json_file/" + d1 + "/relay_" + str( relay[r]) + "/x/delay_XXX_" + str(delay[d]) + ".json" files = my.get_grouped_files(source_path=path, delay=delay, index_delay=d) i = 1 for item in files: data = my.open_file_and_return_data(path=item) t = hue + ' config_' + str(r) if hue == 'ble_wifi': if type_graph == 'latency': value = data['summary']['statistic_']['total'][ type_graph]['mean'] else: value = data['summary']['statistic_']['total'][ type_graph] else: if type_graph == 'latency': value = data['summary']['statistic_'][type_graph][ 'mean'] else: value = data['summary']['statistic_'][type_graph] time_ = convert_time_in_num(data['_command']['delay']) x.append(time_) y.append(value) z.append(t) dictionary[hue][r]['x'].append(time_) dictionary[hue][r]['y'].append(value) i += 1 dataframe = {'delay': x, 'latency': y, 'type': z} df = pd.DataFrame(dataframe) # print(df) print("path: " + my.path_media + "json_file/" + directory + "/last_plot/") print("name: " + name) # colors = ['#4878D0', '#EE854A', '#6ACC64', '#D65F5F', '#82C6E2', '#D5BB67'] # sns.set_palette(sns.color_palette(colors)) xs_b_0 = np.linspace(min(dictionary['ble'][0]['x']), max(dictionary['ble'][0]['x']), 100) xs_b_1 = np.linspace(min(dictionary['ble'][1]['x']), max(dictionary['ble'][1]['x']), 100) xs_b_2 = np.linspace(min(dictionary['ble'][2]['x']), max(dictionary['ble'][2]['x']), 100) xs_bw_0 = np.linspace(min(dictionary['ble_wifi'][0]['x']), max(dictionary['ble_wifi'][0]['x']), 100) xs_bw_1 = np.linspace(min(dictionary['ble_wifi'][1]['x']), max(dictionary['ble_wifi'][1]['x']), 100) xs_bw_2 = np.linspace(min(dictionary['ble_wifi'][2]['x']), max(dictionary['ble_wifi'][2]['x']), 100) f_b_0 = sc.interpolate.interp1d(dictionary['ble'][0]['x'], dictionary['ble'][0]['y'], kind='linear') f_b_1 = sc.interpolate.interp1d(dictionary['ble'][1]['x'], dictionary['ble'][1]['y'], kind='linear') f_b_2 = sc.interpolate.interp1d(dictionary['ble'][2]['x'], dictionary['ble'][2]['y'], kind='linear') f_bw_0 = sc.interpolate.interp1d(dictionary['ble_wifi'][0]['x'], dictionary['ble_wifi'][0]['y'], kind='linear') f_bw_1 = sc.interpolate.interp1d(dictionary['ble_wifi'][1]['x'], dictionary['ble_wifi'][1]['y'], kind='linear') f_bw_2 = sc.interpolate.interp1d(dictionary['ble_wifi'][2]['x'], dictionary['ble_wifi'][2]['y'], kind='linear') sns.set_context('notebook') sns.lmplot( x='delay', y='latency', data=df, palette='muted', fit_reg=False, ci=None, legend_out=False, # hue='type', height=4, aspect=2, markers=".", scatter_kws={"s": 30}) # plot line plt.plot(xs_b_0, f_b_0(xs_b_0), '-.', color='#D65F5F') # red plt.plot(xs_b_1, f_b_1(xs_b_1), '-.', color='#956CB4') # purple plt.plot(xs_b_2, f_b_2(xs_b_2), '-.', color='#8C613C') # brown plt.plot(xs_bw_0, f_bw_0(xs_bw_0), '--', color='#4878D0') # blue plt.plot(xs_bw_1, f_bw_1(xs_bw_1), '--', color='#EE854A') # orange plt.plot(xs_bw_2, f_bw_2(xs_bw_2), '--', color='#6ACC64') # green # plot point plt.plot(dictionary['ble'][0]['x'], dictionary['ble'][0]['y'], 'o', markersize=6, color='#D65F5F', label="ble config_0") # red plt.plot(dictionary['ble'][1]['x'], dictionary['ble'][1]['y'], 'o', markersize=6, color='#956CB4', label="ble config_1") # purple plt.plot(dictionary['ble'][2]['x'], dictionary['ble'][2]['y'], 'o', markersize=6, color='#8C613C', label="ble confgi_2") # brown plt.plot(dictionary['ble_wifi'][0]['x'], dictionary['ble_wifi'][0]['y'], 'D', markersize=6, color='#4878D0', label="ble_wifi config_0") # blue plt.plot(dictionary['ble_wifi'][1]['x'], dictionary['ble_wifi'][1]['y'], 'D', markersize=6, color='#EE854A', label="ble_wifi config_1") # orange plt.plot(dictionary['ble_wifi'][2]['x'], dictionary['ble_wifi'][2]['y'], 'D', markersize=6, color='#6ACC64', label="ble_wifi config_2") # green plt.legend(loc='best') my_point = list() my_label = list() delay.reverse() for i in range(len(delay)): my_point.append(i + 1) frequency = 1 / (delay[i] / 1000) my_label.append(round(frequency, 2)) plt.xticks(my_point, my_label, rotation=30) plt.xlabel("Frequency (Hz)", fontsize=16) plt.ylabel(y_label, fontsize=16) # plt.title(title) sns.despine( ) # is a function that removes the spines from the right and upper portion of the plot by default. plt.show()
def main_5(): x = dict() y = list() z = list() l_1 = list() l_2 = list() if directory == 'ble_output': raise Exception('wrong - directory- ') r = 0 for d in range(len(delay)): path = my.path_media + "json_file/" + directory + "/relay_" + str( relay[r]) + "/x/delay_XXX_" + str(delay[d]) + ".json" files = my.get_grouped_files(source_path=path, delay=delay, index_delay=d) for item in files: data = my.open_file_and_return_data(path=item) time_ = (data['_command']['delay']) ble = data['summary']['mex_']['ble']['R'] wifi = data['summary']['mex_']['wifi']['R'] total = data['summary']['mex_']['total']['R'] p_ble = ble * 100 / total p_wifi = wifi * 100 / total x[time_] = list() x[time_].append(p_ble) z.append('ble') x[time_].append(p_wifi) z.append('wifi') l_1.append(time_) y.append(p_ble) l_2.append(100) dataframe = {'total': l_2, 'ble': y, 'delay': l_1} df = pd.DataFrame(dataframe) print(df) fig_dims = (10, 4) fig, ax = plt.subplots(figsize=fig_dims) sns.set_context('notebook') sns.set_color_codes("muted") sns.barplot(x='delay', y='total', data=df, label="total", color='b', ax=ax) sns.set_color_codes("muted") sns.barplot(x='delay', y='ble', data=df, label="ble", color='y', ax=ax) sns.despine() plt.show() print("--") dataframe = { 'type': ['ble', 'wifi'], '50': x[50], '100': x[100], '150': x[150], '200': x[200], '250': x[250], '500': x[500], '1000': x[1000] } df = pd.DataFrame(dataframe) print(df.head()) sns.set_context('notebook') df.set_index('type').T.plot(kind='bar', stacked=True) plt.legend(loc='best') my_point = list() my_label = list() delay.reverse() for i in range(len(delay)): my_point.append(i + 1) frequency = 1 / (delay[i] / 1000) my_label.append(round(frequency, 2)) plt.xticks(my_point, my_label, rotation=30) plt.xlabel("Frequency (Hz)", fontsize=16) plt.ylabel("Percentage", fontsize=16) # plt.title(title) sns.despine( ) # is a function that removes the spines from the right and upper portion of the plot by default. plt.show()