def usdn_energy_v_hops(df_dict): """Plot usdn energy vs hops.""" try: if 'app' in df_dict and 'pow' in df_dict: pow_df = df_dict['pow'] app_df = df_dict['app'] else: raise Exception('ERROR: Correct df(s) not in dict!') except Exception: traceback.print_exc() sys.exit(0) # Add hops to node_df. N.B. cols with NaN are always converted to float hops = app_df[['src', 'hops']].groupby('src').agg(lambda x: mode(x)[0]) pow_df = pow_df.join(hops['hops'].astype(int)) df = pow_df.groupby('hops')['all_rdc'] \ .apply(lambda x: x.mean()) \ .reset_index() \ .set_index('hops') x = df.index.tolist() y = df['all_rdc'].tolist() cpplot.plot_bar(df, 'usdn_energy_v_hops', sim_dir, x, y, xlabel='Hops', ylabel='Radio duty cycle (%)')
def usdn_pdr_v_hops(df_dict): """Plot usdn energy vs hops.""" try: if 'app' in df_dict: app_df = df_dict['app'] else: raise Exception('ERROR: Correct df(s) not in dict!') except Exception: traceback.print_exc() sys.exit(0) # Get hops for each node. N.B. cols with NaN are always converted to float df = app_df[['src', 'hops']].groupby('src').agg(lambda x: mode(x)[0]) # Calculate PRR df['pdr'] = app_df.groupby('src')['drpd'] \ .apply(lambda x: ratio(len(x), x.sum())) df = df.groupby('hops')['pdr'] \ .apply(lambda x: x.mean()) \ .reset_index() \ .set_index('hops') x = df.index.tolist() y = df['pdr'].tolist() cpplot.plot_bar(df, 'usdn_pdr_v_hops', sim_dir, x, y, xlabel='Hops', ylabel='PDR (%)')
def atomic_op_times(df_dict): """Plot atomic op times.""" df = df_dict['atomic-op'].copy() g = df.groupby('op_type') data = pd.DataFrame() for k, v in g: data[k] = pd.Series(v['op_duration'].mean()) # # rearrage cols # data = data[['NONE', 'CLCT', 'CONF', 'RACT', 'ASSC']] # # rename cols # data = data.rename(columns={'NONE': 'IND', # 'CLCT': 'COLLECT', # 'CONF': 'CONFIGURE', # 'RACT': 'REACT', # 'ASSC': 'ASSOCIATE'}) x = list(data.columns.values) y = data.values.tolist()[0] cpplot.plot_bar(df, 'atomic_op', sim_dir, x, y, xlabel='Op Type', ylabel='Time(ms)')
def energy_v_hops(df_dict, **kwargs): """Plot energy vs hops.""" df_name = kwargs['df'] if 'df' in kwargs else None filename = kwargs['file'] if 'file' in kwargs else 'energy_v_hops' print('> Do energy_v_hops for ' + df_name) df = df_dict[df_name].copy() df.set_index('node', inplace=True) if 'all' in df_dict: df_all = df_dict['all'][df_dict['all']['node'] != 1] df['hops'] = df_all.groupby('node').apply(lambda x: x.hops.value_counts().index[0]) elif 'node' in df_dict: df['hops'] = df_dict['node']['hops'] # HACK: Why isnt the filter filtering for hops between 1 and 5? df = df[(df.hops <= 5) & (df.hops >= 1)] g = df.groupby('hops') data = {} for k, v in g: data[k] = v.groupby('node').last()['all_rdc'].mean() x = data.keys() y = data.values() if y is not list: y = list(y) cpplot.plot_bar(df, filename, sim_dir, x, y, xlabel='Hops', ylabel='Radio Duty Cycle (%)') print(' ... RDC mean: ' + str(np.mean(y)))
def atomic_op_times(df_dict, **kwargs): """Plot atomic op times.""" df_name = kwargs['df'] if 'df' in kwargs else None packets = kwargs['packets'] if 'packets' in kwargs else None filename = kwargs['file'] if 'file' in kwargs else 'atomic_op_times' df = df_dict[df_name].copy() # print(df[df['type'] == 'CLCT']) # Filter df for packet types in packets if 'type' in df and packets is not None: df = df[df['type'].isin(packets)] g = df.groupby('type') data = pd.DataFrame() for k, v in g: data[k] = pd.Series(v['op_duration'].mean()) # # rename cols data = data.rename(columns={'CONF': 'CONFIGURE', 'CLCT': 'COLLECT', 'RACT': 'REACT'}) data = data[['CONFIGURE', 'COLLECT', 'REACT']] x = list(data.columns.values) y = data.values.tolist()[0] print(' ... Op time mean: ' + str(np.mean(y))) print(' ... Op time median: ' + str(np.median(y))) print(' ... Op time max: ' + str(np.max(y))) cpplot.plot_bar(df, filename, sim_dir, x, y, xlabel='Op Type', ylabel='Time(ms)')
def graph_traffic_ratio(df_dict, **kwargs): """Graph ratio of traffic for packets.""" try: if 'sdn' in df_dict and 'icmp' in df_dict: sdn_df = df_dict['sdn'] icmp_df = df_dict['icmp'] else: raise Exception('ERROR: Correct df(s) not in dict!') except Exception: traceback.print_exc() sys.exit(0) cpplot.plot_bar(sdn_df, icmp_df, 'traffic_ratio', sim_dir)
def usdn_traffic_ratio(df_dict): """Plot traffic ratios.""" try: if 'app' in df_dict and 'icmp' in df_dict: app_df = df_dict['app'] icmp_df = df_dict['icmp'] if 'sdn' in df_dict: sdn_df = df_dict['sdn'] else: sdn_df = None else: raise Exception('ERROR: Correct df(s) not in dict!') except Exception: traceback.print_exc() sys.exit(0) cpplot.plot_bar(app_df, sdn_df, icmp_df, 'traffic_ratio', sim_dir)
def pdr_v_hops(df_dict, **kwargs): """Plot pdr vs hops.""" df_name = kwargs['df'] if 'df' in kwargs else None packets = kwargs['packets'] if 'packets' in kwargs else None filename = kwargs['file'] if 'file' in kwargs else 'pdr_v_hops' print('> Do pdr_v_hops for ' + str(packets) + ' in ' + df_name) if packets is None: raise Exception('ERROR: No packets to search for!') df = df_dict[df_name].copy() print(' ... Total for df (' + df_name + ') = ' + str(df.shape[0])) if 'type' in df: df = df[df['type'].isin(packets)] missed = df.received.str.count('missed').sum() received = df.received.str.count('correct').sum() if 'drpd' not in df: df['drpd'] = np.where(df['received'] == 'missed', True, False) total = df.shape[0] print(' ... Total: ' + str(total)) print(' ... Received: ' + str(received)) print(' ... Missed: ' + str(missed)) print(' ... Total PDR: ' + str(ratio(total, missed))) df_pdr = df.groupby('hops')['drpd'].apply(lambda x: ratio(len(x), x.sum())) df_pdr = df_pdr.groupby('hops') \ .apply(lambda x: x.mean()) \ .reset_index() \ .set_index('hops') x = df_pdr.index.tolist() y = df_pdr['drpd'].tolist() cpplot.plot_bar(df_pdr, filename, sim_dir, x, y, xlabel='Hops', ylabel='End-to-end PDR (%)')
def graph_pdr(df_dict, **kwargs): global hlp """Graph end-to-end PDR.""" df_name = kwargs['df'] if 'df' in kwargs else None packets = kwargs['packets'] if 'packets' in kwargs else None filename = kwargs['file'] if 'file' in kwargs else 'pdr' xlabel = kwargs['xlabel'] if 'xlabel' in kwargs else packets df = df_dict[df_name].copy() if packets is not None: print('> Do packet_pdr for ' + str(packets) + ' in ' + df_name) df = df[df['type'].isin(packets)] else: print('> Do packet_pdr for ALL_PACKETS in ' + df_name) total = df.shape[0] missed = df.received.str.count('missed').sum() received = df.received.str.count('correct').sum() print(' ... Total: ' + str(total)) print(' ... Received: ' + str(received)) print(' ... Missed: ' + str(missed)) print(' ... Total PDR: ' + str(ratio(total, missed))) if packets is not None: if 'drpd' not in df: df['drpd'] = np.where(df['received'] == 'missed', True, False) df_pdr = df.groupby('type')['drpd'].apply(lambda x: ratio(len(x), x.sum())) df_pdr = df_pdr.groupby('type') \ .apply(lambda x: x.mean()) \ .reset_index() \ .set_index('type') x = df_pdr.index.tolist() y = df_pdr['drpd'].tolist() else: x = [str(xlabel)] y = [ratio(total, missed)] cpplot.plot_bar(df, filename, sim_dir, x, y, xlabel='Packet Type', ylabel='End-to-end PDR (%)')
def atomic_energy_v_hops(df_dict): """Plot atomic energy vs hops.""" try: if 'atomic-energy' in df_dict: df = df_dict['atomic-energy'] else: raise Exception('ERROR: Correct df(s) not in dict!') except Exception: traceback.print_exc() sys.exit(0) g = df.groupby('hops') data = {} for k, v in g: # ignore the timesync (0 hops) if (k > 0): data[k] = v.groupby('id').last()['all_rdc'].mean() cpplot.plot_bar(df, 'atomic_energy_v_hops', sim_dir, data.keys(), data.values(), xlabel='Hops', ylabel='Radio Duty Cycle (%)')
def atomic_vs_usdn(df_dict): """Plot atomic vs usdn collect pdr and energy.""" # PDR if 'usdn' in sim_type: # copy dfs df_node = df_dict['node'].copy().reset_index() df_sdn = df_dict['sdn'].copy() # take only NSU and drop any dropped packets df = df_sdn[(df_sdn['typ'] == 'NSU')] df = df.rename(columns={'lat': 'collect_time'}) df = df[df['src'] != 1] df = df.merge(df_node, left_on='src', right_on='id') # merge hops col df = df[(df['hops'] > 0) & (df['hops'] <= 5)] elif 'atomic' in sim_type: df = df_dict['atomic-op'].copy() df = df[df['op_type'] == 'CLCT'] df['collect_time'] = df['c_time'].astype(int) df = df[df['hops'] != 0] df['drpd'] = np.where(df['collect_time'] == 0, True, False) else: raise Exception('ERROR: Unknown types!') df_pdr = df.groupby('hops')['drpd'] \ .apply(lambda x: ratio(len(x), x.sum())) df_pdr = df_pdr.groupby('hops') \ .apply(lambda x: x.mean()) \ .reset_index() \ .set_index('hops') x = df_pdr.index.tolist() y = df_pdr['drpd'].tolist() cpplot.plot_bar(df_pdr, 'atomic_vs_usdn_collect_pdr', sim_dir, x, y, xlabel='Hops', ylabel='End-to-end PDR (%)') # Energy if 'usdn' in sim_type: df_node = df_dict['node'].copy().reset_index() df = df_dict['pow'].copy().reset_index() df = df.merge(df_node, left_on='id', right_on='id') # merge hops col df = df[(df['hops'] > 0) & (df['hops'] <= 5)] elif 'atomic' in sim_type: df = df_dict['atomic-energy'].copy() df = df[df['op_type'] == 'CLCT'] df = df[df['hops'] != 0] else: raise Exception('ERROR: Unknown types!') g = df.groupby('hops') data = {} for k, v in g: data[k] = v.groupby('id').last()['all_rdc'].mean() x = data.keys() y = data.values() cpplot.plot_bar(df, 'atomic_vs_usdn_collect_energy', sim_dir, x, y, xlabel='Hops', ylabel='Radio Duty Cycle (%)')