예제 #1
0
파일: plot_cdfs.py 프로젝트: sdsd08013/cpp
def do_cdfs(options, stats, write_filepath):

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    for metric in options.metrics:
        print("reformatting data...")
        data = {}
        for i, g in enumerate(stats['group']):
            if options.max and i >= options.max:
                break
            data[g] = [d[metric] for d in stats['data'][g]["distribution"]]

        print("plotting CDFs")
        xmax = round(math.ceil(max(data[stats['group'][0]])))
        axis_limits = [0, xmax, 0, 1]
        if options.minx:
            axis_limits[0] = options.minx
        if options.maxx:
            axis_limits[1] = options.maxx
        plot.plot('cdf',
                  data,
                  COLORS,
                  axis_limits,
                  metric,
                  "linear",
                  "linear",
                  write_filepath + '_' + metric + '_cdfs',
                  options.write,
                  xlabel=metric_fullname(metric) + ' (miles)',
                  ylabel='fraction of \ncontroller placements',
                  ext=options.ext)

    if not options.write:
        plot.show()
예제 #2
0
def do_plot(options, stats, g, write_filepath):
    city_data = None
    if os.path.isfile(LATLONG_FILE):
        city_data = read_json_file(LATLONG_FILE)

    data = {}
    if not write_filepath:
        write_filepath = get_output_filepath(options.input)
    write_filepath += "_map_"

    print "reformatting data & doing plot..."
    for i, c in enumerate(stats["group"]):
        if options.max and i >= options.max:
            break
        data[str(c)] = stats["data"][str(c)]
        metric_data = []
        for metric in options.metrics:
            metric_data.append(data[str(c)][metric]["lowest_combo"])
        write_map(
            g,
            city_data,
            options.metrics,
            metric_data,
            write_filepath + str(c),
            options.write,
            options.ext,
            options.labels,
            color=COLORS[i],
        )
예제 #3
0
파일: plot_cdfs.py 프로젝트: NKSG/cpp
def do_cdfs(options, stats, write_filepath):

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    for metric in options.metrics:
        print "reformatting data..."
        data = {}
        for i, g in enumerate(stats['group']):
            if options.max and i >= options.max:
                break
            data[g] = [d[metric] for d in stats['data'][g]["distribution"]]

        print "plotting CDFs"
        xmax = round(math.ceil(max(data[stats['group'][0]])))
        axis_limits = [0, xmax, 0, 1]
        if options.minx:
            axis_limits[0] = options.minx
        if options.maxx:
            axis_limits[1] = options.maxx
        plot.plot('cdf', data, COLORS, axis_limits,
                  metric, "linear", "linear", write_filepath + '_' + metric + '_cdfs',
                  options.write,
                  xlabel = metric_fullname(metric) + ' (miles)',
                  ylabel = 'fraction of \ncontroller placements',
                  ext = options.ext)

    if not options.write:
        plot.show()
예제 #4
0
파일: plot_ranges.py 프로젝트: NKSG/cpp
def do_ranges(options, stats, write_filepath, topo_name):

    # Grab topo to enable analysis that requires generating new metric values,
    # such as the value of one metric with a combo optimized for another one.
    '''
    topo_graph returns
        @param g: NetworkX Graph
        @param usable: boolean: locations on all nodes and connected?
        @param note: error or note about mods
    '''
    print "generating topo for: %s" % topo_name
    graph, usable, note = get_topo_graph(topo_name)
    if not usable:
        raise Exception("unusable graph?")

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    for metric in options.metrics:

        this_write_filepath = write_filepath + '_' + metric
        xlabel = 'number of controllers (k)'

        for ptype in options.plots:
            if ptype in PLOT_FCNS.keys():
                p = PLOT_FCNS[ptype]
                #print "plotting %s" % ptype

                filepath = this_write_filepath + '_' + ptype
                aspect_fcns = get_aspect_fcns(p, stats, metric, graph)
                aspects = aspect_fcns.keys()
                aspect_colors = p['aspect_colors']
                ylabel = p['ylabel'](metric)
                min_x = p['min_x'](options) if 'min_x' in p else None
                max_x = p['max_x'](options) if 'max_x' in p else None
                min_y = p['min_y'](options) if 'min_y' in p else None
                max_y = p['max_y'](options) if 'max_y' in p else None
                ylabel2 = p['ylabel2'](metric) if 'ylabel2' in p else None
                y2_scale_factor = p['y2_scale_factor'] if 'y2_scale_factor' in p else None
                hlines = p['hlines'] if 'hlines' in p else None

                plot.ranges(stats, metric, aspects, aspect_colors, aspect_fcns,
                            "linear", "linear", None, None, filepath,
                            options.write, ext = options.ext,
                            xlabel = xlabel,
                            ylabel = ylabel,
                            min_x = min_x,
                            max_x = max_x,
                            min_y = min_y,
                            max_y = max_y,
                            ylabel2 = ylabel2,
                            y2_scale_factor = y2_scale_factor,
                            hlines = hlines)
            else:
                raise Exception("undefined ptype: %s" % ptype)

    if not options.write:
        plot.show()
예제 #5
0
파일: plot_pareto.py 프로젝트: NKSG/cpp
def do_pareto(options, stats, write_filepath):

    assert len(options.metrics) == 2
    x_metric, y_metric = options.metrics
    print "reformatting data..."
    data = {}
    for i, g in enumerate(stats['group']):
        if options.max and i >= options.max:
            break
        data[g] = [d for d in stats['data'][g]["distribution"]]

    print "plotting point pareto"
    if not write_filepath:
        write_filepath = get_output_filepath(options.input)
    write_filepath += '_pareto_' + ','.join(options.metrics)
    plot.pareto(data, COLORS, None,
               "linear", "linear", write_filepath,
               options.write,
               xlabel = metric_fullname(x_metric) + ' (miles)',
               ylabel = metric_fullname(y_metric) + ' (miles)',
               ext = options.ext,
               x_metric = x_metric,
               y_metric = y_metric,
               min_x = 0,
               min_y = 0)

    plot.pareto(data, COLORS, None,
               "linear", "linear", write_filepath + '_zoom',
               options.write,
               xlabel = metric_fullname(x_metric) + ' (miles)',
               ylabel = metric_fullname(y_metric) + ' (miles)',
               ext = options.ext,
               min_x = 0,
               min_y = 0,
               x_metric = x_metric,
               y_metric = y_metric,
               loc = "lower right")

    plot.pareto(data, COLORS, None,
               "linear", "linear", write_filepath + '_norm',
               options.write,
               xlabel = metric_fullname(x_metric) + ' (ratio)',
               ylabel = metric_fullname(y_metric) + ' (ratio)',
               ext = options.ext,
               x_metric = x_metric,
               y_metric = y_metric,
#               max_x = 1.2,
#               max_y = 1.2,
               normalize = True,
               legend = True,
               loc = "upper right")

    if not options.write:
        plot.show()
예제 #6
0
파일: plot_cloud.py 프로젝트: sdsd08013/cpp
def do_cloud(options, stats, write_filepath, ext=None):

    assert len(options.metrics) == 2
    x_metric, y_metric = options.metrics
    print("reformatting data...")
    metrics = [x_metric, y_metric]
    data = {}
    for i, g in enumerate(stats['group']):
        if options.max and i >= options.max:
            break
        data[g] = [d for d in stats['data'][g]["distribution"]]

    print("plotting point cloud")

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    # Series may not have values that monotonically decrease by the controller
    # number, so consider each value when choosing axis extents.
    extra_margin = 1.02
    maxes = {x_metric: [], y_metric: []}
    for c in stats['group']:
        for metric in options.metrics:
            maxes[metric].append(stats['data'][c][metric]['highest'])
    axes = [
        0,
        max(maxes[x_metric]) * extra_margin, 0,
        max(maxes[y_metric]) * extra_margin
    ]
    if not ext:
        ext = options.ext
    plot.cloud(data,
               COLORS,
               axes,
               "linear",
               "linear",
               write_filepath + '_cloud_' + ','.join(options.metrics),
               options.write,
               xlabel=metric_fullname(x_metric) + ' (miles)',
               ylabel=metric_fullname(y_metric) + ' (miles)',
               ext=ext,
               x_metric=x_metric,
               y_metric=y_metric,
               legend=True)

    if not options.write:
        plot.show()
예제 #7
0
def do_plot(options, stats, g, write_filepath):
    city_data = None
    if os.path.isfile(LATLONG_FILE):
        city_data = read_json_file(LATLONG_FILE)

    data = {}
    if not write_filepath:
        write_filepath = get_output_filepath(options.input)
    write_filepath += '_map_'

    print "reformatting data & doing plot..."
    for i, c in enumerate(stats['group']):
        if options.max and i >= options.max:
            break
        data[str(c)] = stats['data'][str(c)]
        metric_data = []
        for metric in options.metrics:
            metric_data.append(data[str(c)][metric]['lowest_combo'])
        write_map(g, city_data, options.metrics, metric_data, write_filepath + str(c), options.write,
                  options.ext, options.labels, color = COLORS[i])
예제 #8
0
파일: plot_cloud.py 프로젝트: NKSG/cpp
def do_cloud(options, stats, write_filepath, ext = None):

    assert len(options.metrics) == 2
    x_metric, y_metric = options.metrics
    print "reformatting data..."
    metrics = [x_metric, y_metric]
    data = {}
    for i, g in enumerate(stats['group']):
        if options.max and i >= options.max:
            break
        data[g] = [d for d in stats['data'][g]["distribution"]]

    print "plotting point cloud"

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    # Series may not have values that monotonically decrease by the controller
    # number, so consider each value when choosing axis extents.
    extra_margin = 1.02
    maxes = {x_metric: [], y_metric: []}
    for c in stats['group']:
        for metric in options.metrics:
            maxes[metric].append(stats['data'][c][metric]['highest'])
    axes = [0, max(maxes[x_metric]) * extra_margin, 0, max(maxes[y_metric]) * extra_margin]
    if not ext:
        ext = options.ext
    plot.cloud(data, COLORS, axes,
               "linear", "linear", write_filepath + '_cloud_' + ','.join(options.metrics),
               options.write,
               xlabel = metric_fullname(x_metric) + ' (miles)',
               ylabel = metric_fullname(y_metric) + ' (miles)',
               ext = ext,
               x_metric = x_metric,
               y_metric = y_metric,
               legend = True)

    if not options.write:
        plot.show()
예제 #9
0
def do_ranges(options, stats, write_filepath, topo_name):

    # Grab topo to enable analysis that requires generating new metric values,
    # such as the value of one metric with a combo optimized for another one.
    '''
    topo_graph returns
        @param g: NetworkX Graph
        @param usable: boolean: locations on all nodes and connected?
        @param note: error or note about mods
    '''
    print "generating topo for: %s" % topo_name
    graph, usable, note = get_topo_graph(topo_name)
    if not usable:
        raise Exception("unusable graph?")

    if not write_filepath:
        write_filepath = get_output_filepath(options.input)

    for metric in options.metrics:

        this_write_filepath = write_filepath + '_' + metric
        xlabel = 'number of controllers (k)'

        for ptype in options.plots:
            if ptype in PLOT_FCNS.keys():
                p = PLOT_FCNS[ptype]
                #print "plotting %s" % ptype

                filepath = this_write_filepath + '_' + ptype
                aspect_fcns = get_aspect_fcns(p, stats, metric, graph)
                aspects = aspect_fcns.keys()
                aspect_colors = p['aspect_colors']
                ylabel = p['ylabel'](metric)
                min_x = p['min_x'](options) if 'min_x' in p else None
                max_x = p['max_x'](options) if 'max_x' in p else None
                min_y = p['min_y'](options) if 'min_y' in p else None
                max_y = p['max_y'](options) if 'max_y' in p else None
                ylabel2 = p['ylabel2'](metric) if 'ylabel2' in p else None
                y2_scale_factor = p[
                    'y2_scale_factor'] if 'y2_scale_factor' in p else None
                hlines = p['hlines'] if 'hlines' in p else None

                plot.ranges(stats,
                            metric,
                            aspects,
                            aspect_colors,
                            aspect_fcns,
                            "linear",
                            "linear",
                            None,
                            None,
                            filepath,
                            options.write,
                            ext=options.ext,
                            xlabel=xlabel,
                            ylabel=ylabel,
                            min_x=min_x,
                            max_x=max_x,
                            min_y=min_y,
                            max_y=max_y,
                            ylabel2=ylabel2,
                            y2_scale_factor=y2_scale_factor,
                            hlines=hlines)
            else:
                raise Exception("undefined ptype: %s" % ptype)

    if not options.write:
        plot.show()
예제 #10
0
def do_pareto(options, stats, write_filepath):

    assert len(options.metrics) == 2
    x_metric, y_metric = options.metrics
    print "reformatting data..."
    data = {}
    for i, g in enumerate(stats['group']):
        if options.max and i >= options.max:
            break
        data[g] = [d for d in stats['data'][g]["distribution"]]

    print "plotting point pareto"
    if not write_filepath:
        write_filepath = get_output_filepath(options.input)
    write_filepath += '_pareto_' + ','.join(options.metrics)
    plot.pareto(data,
                COLORS,
                None,
                "linear",
                "linear",
                write_filepath,
                options.write,
                xlabel=metric_fullname(x_metric) + ' (miles)',
                ylabel=metric_fullname(y_metric) + ' (miles)',
                ext=options.ext,
                x_metric=x_metric,
                y_metric=y_metric,
                min_x=0,
                min_y=0)

    plot.pareto(data,
                COLORS,
                None,
                "linear",
                "linear",
                write_filepath + '_zoom',
                options.write,
                xlabel=metric_fullname(x_metric) + ' (miles)',
                ylabel=metric_fullname(y_metric) + ' (miles)',
                ext=options.ext,
                min_x=0,
                min_y=0,
                x_metric=x_metric,
                y_metric=y_metric,
                loc="lower right")

    plot.pareto(
        data,
        COLORS,
        None,
        "linear",
        "linear",
        write_filepath + '_norm',
        options.write,
        xlabel=metric_fullname(x_metric) + ' (ratio)',
        ylabel=metric_fullname(y_metric) + ' (ratio)',
        ext=options.ext,
        x_metric=x_metric,
        y_metric=y_metric,
        #               max_x = 1.2,
        #               max_y = 1.2,
        normalize=True,
        legend=True,
        loc="upper right")

    if not options.write:
        plot.show()