def graph_min_max_versus(result_name): name = 'min-max-{}-versus-{}'.format(adaptive.name, result_name) yextractor = lambda x: scalar_extractor(x.get((0, 0), None)) if result_name == 'attacker distance' else scalar_extractor(x) g = min_max_versus.Grapher( self.algorithm_module.graphs_path, name, xaxis='network size', yaxis=result_name, vary='approach', yextractor=yextractor) g.xaxis_label = 'Network Size' g.yaxis_label = graph_parameters[result_name][0] g.key_position = graph_parameters[result_name][1] g.yaxis_font = g.xaxis_font = "',15'" g.nokey = True #g.key_font = "',20'" #g.key_spacing = "2" #g.key_width = "+6" g.point_size = '2' g.line_width = 4 g.min_label = 'Dynamic - Lowest' g.max_label = 'Dynamic - Highest' g.comparison_label = 'DynamicSpr' g.vary_label = '' if result_name in custom_yaxis_range_max: g.yaxis_range_max = custom_yaxis_range_max[result_name] def vvalue_converter(name): return { "PB_FIXED1_APPROACH": "Fixed1", "PB_FIXED2_APPROACH": "Fixed2", "PB_RND_APPROACH": "Rnd", }[name] g.vvalue_label_converter = vvalue_converter g.generate_legend_graph = True if result_name in protectionless_results.result_names: g.create(adaptive_spr_results, our_results, baseline_results=protectionless_results) else: g.create(adaptive_spr_results, our_results) summary.GraphSummary( os.path.join(self.algorithm_module.graphs_path, name), '{}-{}'.format(self.algorithm_module.name, name).replace(" ", "_") ).run()
def yextractor(yvalue): print(yvalue) return scalar_extractor(yvalue, key=(0, 0))
def _run_graph_testbed(self, args): graph_parameters = { 'normal latency': ('Normal Message Latency (ms)', 'left top'), #'ssd': ('Sink-Source Distance (hops)', 'left top'), 'captured': ('Capture Ratio (%)', 'left top'), #'fake': ('Fake Messages Sent', 'left top'), #'sent': ('Total Messages Sent', 'left top'), 'received ratio': ('Receive Ratio (%)', 'left bottom'), #'tfs': ('Number of TFS Created', 'left top'), #'pfs': ('Number of PFS Created', 'left top'), #'tailfs': ('Number of TailFS Created', 'left top'), 'attacker distance': ('Attacker-Source Distance (Meters)', 'left top'), 'norm(norm(sent,time taken),network size)': ('Messages Sent per Second per Node', 'left top'), 'norm(norm(fake,time taken),network size)': ('Fake Messages Sent per Second per node', 'left top'), 'average power consumption': ('Average Power Consumption (mA)', 'left top'), 'average power used': ('Average Energy Consumed (mAh)', 'left top'), 'norm(average power used,time taken)': ('Normalised Average Power Used (mAh)', 'left top'), 'time taken': ('Time Taken (sec)', 'left top'), } varying = [ #(('network size', ''), ('source period', ' seconds')), (('source period', ' seconds'), ('approach', '~')), ] custom_yaxis_range_max = { 'received ratio': 100, 'captured': 20, 'norm(norm(sent,time taken),network size)': 6, 'norm(norm(fake,time taken),network size)': 6, 'average power used': 0.035, 'average power consumption': 20, } def vvalue_converter(name): try: return { "PB_FIXED1_APPROACH": "Fixed1", "PB_FIXED2_APPROACH": "Fixed2", "PB_RND_APPROACH": "Rnd", }[name] except KeyError: return name yextractors = { "attacker distance": lambda vvalue: scalar_extractor(vvalue, key=(1, 0)) } def filter_params(all_params): return all_params['source period'] == '0.5' self._create_baseline_versus_graph( "real", protectionless, graph_parameters, varying, custom_yaxis_range_max=custom_yaxis_range_max, testbed=args.testbed, vvalue_label_converter=vvalue_converter, yextractor=yextractors, generate_legend_graph=True, xaxis_font="',16'", yaxis_font="',16'", xlabel_font="',14'", ylabel_font="',14'", line_width=3, point_size=1, nokey=True, legend_divisor=2, legend_font_size='14', legend_base_height=0.5, vary_label="", baseline_label="Protectionless", results_filter=filter_params, )
def _run_graph_testbed(self, args): graph_parameters = { 'normal latency': ('Normal Message Latency (ms)', 'left top'), #'ssd': ('Sink-Source Distance (hops)', 'left top'), 'captured': ('Capture Ratio (%)', 'left top'), #'fake': ('Fake Messages Sent', 'left top'), #'sent': ('Total Messages Sent', 'left top'), 'received ratio': ('Receive Ratio (%)', 'left bottom'), #'tfs': ('Number of TFS Created', 'left top'), #'pfs': ('Number of PFS Created', 'left top'), #'tailfs': ('Number of TailFS Created', 'left top'), 'attacker distance': ('Attacker-Source Distance (Meters)', 'left top'), #"attacker distance percentage": ('Normalised Attacker Distance (%)', 'left top'), 'norm(norm(sent,time taken),network size)': ('Messages Sent per Second per Node', 'left top'), 'norm(norm(fake,time taken),network size)': ('Fake Messages Sent per Second per node', 'left top'), 'average power consumption': ('Average Current Draw (mA)', 'left top'), 'average power used': ('Average Energy Consumed (mAh)', 'left top'), 'time taken': ('Time Taken (sec)', 'left top'), 'average duty cycle': ('Average Duty Cycle (%)', 'right top'), } lpl_params = self.algorithm_module.extra_parameter_names varying = [ #(('network size', ''), ('source period', ' seconds')), #(('source period', ' seconds'), ('approach', '~')), (('source period', ' seconds'), (lpl_params, '~')), ] custom_yaxis_range_max = { 'received ratio': 100, 'captured': 30, 'norm(norm(sent,time taken),network size)': 4, 'norm(norm(fake,time taken),network size)': 4, 'average power consumption': 20, 'average power used': 0.04, 'normal latency': 300, 'attacker distance': 600, 'average duty cycle': 100, } def vvalue_converter(name): try: return { "PB_FIXED1_APPROACH": "Fixed1", "PB_FIXED2_APPROACH": "Fixed2", }[name] except KeyError: return name yextractors = { "attacker distance": lambda vvalue: scalar_extractor(vvalue)[(1, 0)] } def fetch_baseline_result(baseline_results, data_key, src_period, baseline_params): if data_key[-1] != 'enabled': raise RuntimeError(f"Expected 'enabled', got {data_key[-1]}") # adaptive_spr_notify doesn't run with lpl enabled, but that is what we want to compare against data_key = data_key[:-1] + ('disabled', ) return baseline_results.data[data_key][src_period][baseline_params] def filter_params(all_params): return all_params['source period'] == '0.5' self._create_baseline_versus_graph( "real", adaptive_spr_notify, graph_parameters, varying, custom_yaxis_range_max=custom_yaxis_range_max, testbed=args.testbed, vvalue_label_converter=vvalue_converter, yextractor=yextractors, generate_legend_graph=True, xaxis_font="',16'", yaxis_font="',16'", xlabel_font="',14'", ylabel_font="',14'", line_width=3, point_size=1, nokey=True, legend_divisor=3, legend_font_size='14', legend_base_height=0.5, vary_label="", baseline_label="DynamicSPR (no duty cycle)", fetch_baseline_result=fetch_baseline_result, results_filter=filter_params, )
def _run_graph_min_max(self, args): graph_parameters = { 'normal latency': ('Normal Message Latency (ms)', 'left top'), #'ssd': ('Sink-Source Distance (hops)', 'left top'), 'captured': ('Capture Ratio (%)', 'left top'), #'fake': ('Fake Messages Sent', 'left top'), #'sent': ('Total Messages Sent', 'left top'), 'received ratio': ('Receive Ratio (%)', 'left bottom'), #'tfs': ('Number of TFS Created', 'left top'), #'pfs': ('Number of PFS Created', 'left top'), #'tailfs': ('Number of TailFS Created', 'left top'), 'attacker distance': ('Attacker-Source Distance (Meters)', 'left top'), #"attacker distance percentage": ('Normalised Attacker Distance (%)', 'left top'), 'average duty cycle': ('Average Duty Cycle (%)', 'right top'), 'norm(norm(sent,time taken),network size)': ('Messages Sent per Sec per Node', 'left top'), 'norm(norm(fake,time taken),network size)': ('Fake Messages Sent per Sec per Node', 'left top'), } lpl_params = self.algorithm_module.extra_parameter_names varying = [ #(('network size', ''), ('source period', ' seconds')), #(('network size', ''), (lpl_params, '~')), (('source period', ''), (lpl_params, '~')), ] custom_yaxis_range_max = { 'captured': 25, 'received ratio': 100, 'average duty cycle': 100, 'normal latency': 1000, 'attacker distance': 70, 'norm(norm(fake,time taken),network size)': 4, 'norm(norm(sent,time taken),network size)': 5, } key_equivalence = {"low power listening": {"enabled": "disabled"}} #custom_yaxis_range_min = { # 'received ratio': 70, #} def vvalue_converter(name): try: return { "PB_FIXED1_APPROACH": "Fixed1", "PB_FIXED2_APPROACH": "Fixed2", }[name] except KeyError: return name yextractors = { # Just get the distance of attacker 0 from node 0 (the source in SourceCorner) "attacker distance": lambda yvalue: scalar_extractor(yvalue, key=(0, 0)) } def fetch_baseline_result(baseline_results, data_key, src_period, baseline_params): if data_key[-1] != 'enabled': raise RuntimeError(f"Expected 'enabled', got {data_key[-1]}") # adaptive_spr_notify doesn't run with lpl enabled, but that is what we want to compare against data_key = data_key[:-1] + ('disabled', ) return baseline_results.data[data_key][src_period][baseline_params] # These are the wakeups that need to be graphed valid_wakeups = [ (200, 200, 250, 250, 75, 75), (80, 80, 120, 130, 5, 50), (40, 40, 120, 130, 5, 50), (35, 35, 100, 100, 5, 50), (35, 35, 60, 60, 5, 50), ] wakeup_names = ('lpl normal early', 'lpl normal late', 'lpl fake early', 'lpl fake late', 'lpl choose early', 'lpl choose late') def filter_params(all_params): try: wakeup = tuple(int(all_params[name]) for name in wakeup_names) except KeyError: wakeup = None return all_params['source period'] == '0.25' or all_params[ 'network size'] == '5' or (wakeup is not None and wakeup not in valid_wakeups) self._create_min_max_versus_graph( args.sim, [adaptive_spr_notify_tinyoslpl], adaptive_spr_notify, graph_parameters, varying, #testbed=args.testbed, vvalue_label_converter=vvalue_converter, results_filter=filter_params, custom_yaxis_range_max=custom_yaxis_range_max, #custom_yaxis_range_min=custom_yaxis_range_min, key_equivalence=key_equivalence, yextractor=yextractors, xaxis_font="',18'", yaxis_font="',18'", xlabel_font="',16'", ylabel_font="',15'", line_width=3, point_size=1, nokey=True, generate_legend_graph=True, legend_font_size=16, legend_divisor=4, legend_base_height=0.5, vary_label="", #baseline_label="DynamicSPR (no duty cycle)", max_label=['TinyOS LPL Max'], #'DynamicSPR Max', min_label=['TinyOS LPL Min'], #'DynamicSPR Min', min_max_same_label=["TinyOS LPL"], #"DynamicSPR", comparison_label="DC", baseline_label="DynamicSPR", #squash_path=True, fetch_baseline_result=fetch_baseline_result, )
def _run_graph(self, args): graph_parameters = { 'normal latency': ('Normal Message Latency (seconds)', 'left top'), #'ssd': ('Sink-Source Distance (hops)', 'left top'), 'captured': ('Capture Ratio (%)', 'left top'), #'sent': ('Total Messages Sent', 'left top'), 'received ratio': ('Receive Ratio (%)', 'left bottom'), 'norm(sent,time taken)': ('Total Messages Sent per Second', 'left top'), 'attacker distance': ('Attacker-Source Distance (Meters)', 'left top'), #"attacker distance percentage": ('Normalised Attacker Distance (%)', 'left top'), #'failed avoid sink': ('Failed to Avoid Sink (%)', 'left top'), #'failed avoid sink when captured': ('Failed to Avoid Sink When Captured (%)', 'left top'), } varying = [ #(('network size', ''), ('msg group size', '')), (('pr direct to sink', ''), ('msg group size', '')), #(('network size', ''), ('source period', ' seconds')), #(('network size', ''), ('pr direct to sink', '')), ] custom_yaxis_range_max = { 'received ratio': 100, 'norm(sent,time taken)': 500, 'captured': 25, 'normal latency': 4000, 'attacker distance': 80, } yextractors = { # Just get the distance of attacker 0 from node 0 (the source in SourceCorner) "attacker distance": lambda yvalue: scalar_extractor(yvalue, key=(0, 0)), "attacker distance percentage": lambda yvalue: scalar_extractor(yvalue, key=(0, 0)) * 100 } kwargs = { "custom_yaxis_range_max": custom_yaxis_range_max, "yextractor": yextractors, "xaxis_font": "',16'", "yaxis_font": "',16'", "xlabel_font": "',14'", "ylabel_font": "',14'", "line_width": 3, "point_size": 1, "nokey": True, "generate_legend_graph": True, "legend_font_size": 16, } self._create_versus_graph(args.sim, graph_parameters, varying, **kwargs) varying = [ (('network size', ''), ('msg group size', '')), ] kwargs["xvalues_to_tic_label"] = lambda x: f'{x}x{x}' self._create_versus_graph(args.sim, graph_parameters, varying, **kwargs)
def _run_graph(self, args): graph_parameters = { 'normal latency': ('Normal Message Latency (ms)', 'left top'), #'ssd': ('Sink-Source Distance (hops)', 'left top'), 'captured': ('Capture Ratio (%)', 'left top'), 'fake': ('Fake Messages Sent', 'left top'), 'sent': ('Total Messages Sent', 'left top'), 'received ratio': ('Receive Ratio (%)', 'left bottom'), #'tfs': ('Number of TFS Created', 'left top'), #'pfs': ('Number of PFS Created', 'left top'), 'attacker distance': ('Attacker-Source Distance (Meters)', 'left top'), 'norm(norm(sent,time taken),network size)': ('Messages Sent per Second per Node', 'left top'), 'norm(norm(fake,time taken),network size)': ('Fake Messages Sent per Second per node', 'left top'), } varying = [ #(('network size', ''), ('source period', ' seconds')), #(('network size', ''), ('communication model', '~')), (('network size', ''), ('approach', '')), ] custom_yaxis_range_max = { 'received ratio': 100, 'norm(norm(fake,time taken),network size)': 25, 'norm(norm(sent,time taken),network size)': 25, 'captured': 14, 'normal latency': 120 } yextractors = { # Just get the distance of attacker 0 from node 0 (the source in SourceCorner) "attacker distance": lambda yvalue: scalar_extractor(yvalue)[(0, 0)] } def vvalue_converter(name): try: return { "PB_FIXED1_APPROACH": "Fixed1", "PB_FIXED2_APPROACH": "Fixed2", "PB_RND_APPROACH": "Rnd", "PB_ATTACKER_EST_APPROACH": "AttackerEst", "PB_SINK_APPROACH": "Sink", }[name] except KeyError: return name self._create_versus_graph( args.sim, graph_parameters, varying, custom_yaxis_range_max=custom_yaxis_range_max, vvalue_label_converter=vvalue_converter, yextractor=yextractors, xaxis_font="',16'", yaxis_font="',16'", xlabel_font="',14'", ylabel_font="',14'", line_width=3, point_size=1, nokey=True, generate_legend_graph=True, legend_font_size=16, xvalues_to_tic_label=lambda x: f'"{x}x{x}"')
def _run_graph(self, args): graph_parameters = { 'normal latency': ('Normal Message Latency (ms)', 'left top'), #'ssd': ('Sink-Source Distance (hops)', 'left top'), 'captured': ('Capture Ratio (%)', 'left top'), #'sent': ('Total Messages Sent', 'left top'), 'received ratio': ('Receive Ratio (%)', 'left bottom'), #'tfs': ('Number of TFS Created', 'left top'), #'pfs': ('Number of PFS Created', 'left top'), #'tailfs': ('Number of TailFS Created', 'left top'), 'attacker distance': ('Attacker-Source Distance (Meters)', 'left top'), #"attacker distance percentage": ('Normalised Attacker Distance (%)', 'left top'), 'average duty cycle': ('Average Duty Cycle (%)', 'right top'), 'norm(sent,time taken)': ('Messages Sent per Second', 'left top'), 'norm(norm(sent,time taken),num_nodes)': ('Messages Sent per Sec per Node', 'left top'), } lpl_params = self.algorithm_module.extra_parameter_names varying = [ #(('network size', ''), ('source period', ' seconds')), #(('network size', ''), (lpl_params, '~')), (('source period', ''), (lpl_params, '~')), ] custom_yaxis_range_max = { 'captured': 25, 'received ratio': 100, 'average duty cycle': 100, 'normal latency': 3000, 'attacker distance': 70, 'norm(norm(sent,time taken),num_nodes)': 5, } #custom_yaxis_range_min = { # 'received ratio': 70, #} yextractors = { # Just get the distance of attacker 0 from node 0 (the source in SourceCorner) "attacker distance": lambda yvalue: scalar_extractor(yvalue, key=(0, 0)) } def fetch_baseline_result(baseline_results, data_key, src_period, baseline_params): if data_key[-1] != 'enabled': raise RuntimeError(f"Expected 'enabled', got {data_key[-1]}") # adaptive_spr_notify doesn't run with lpl enabled, but that is what we want to compare against data_key = data_key[:-1] + ('disabled', ) return baseline_results.data[data_key][src_period][baseline_params] def filter_params(all_params): return all_params['source period'] == '0.25' self._create_baseline_versus_graph( args.sim, phantom, graph_parameters, varying, results_filter=filter_params, custom_yaxis_range_max=custom_yaxis_range_max, #custom_yaxis_range_min=custom_yaxis_range_min, yextractor=yextractors, xaxis_font="',18'", yaxis_font="',18'", xlabel_font="',16'", ylabel_font="',15'", line_width=3, point_size=1, nokey=True, generate_legend_graph=True, legend_font_size=16, legend_divisor=4, legend_base_height=0.3, vary_label="", baseline_label="Phantom (no duty cycle)", fetch_baseline_result=fetch_baseline_result, )
def yextractor(yvalue): print(yvalue) return scalar_extractor(yvalue)[(0, 0)]