예제 #1
0
def gg_get_format(gg, data_format):
    from reprep import Report
    r = Report()
    do_dot = data_format == 'dot'
    do_png = data_format == 'png'
    do_pdf = data_format == 'pdf'
    do_svg = data_format == 'svg'

    with timeit_wall('gg_figure %s' % data_format):
        gg_figure(r,
                  'graph',
                  gg,
                  do_dot=do_dot,
                  do_png=do_png,
                  do_pdf=do_pdf,
                  do_svg=do_svg)

    if data_format == 'pdf':
        pdf = r.resolve_url('graph_pdf').get_raw_data()
        return pdf
    elif data_format == 'png':
        png = r.resolve_url('graph/graph').get_raw_data()
        return png
    elif data_format == 'dot':
        dot = r.resolve_url('dot').get_raw_data()
        return dot
    elif data_format == 'svg':
        svg = r.resolve_url('graph_svg').get_raw_data()
        if '<html>' in svg:
            msg = 'I did not expect a tag <html> in the SVG output'
            svg = indent(svg, '> ')
            raise_desc(Exception, msg, svg=svg)
        return svg
    else:
        raise ValueError('No known format %r.' % data_format)
예제 #2
0
def save_plot(output):
    """
        output = {}
        with save_plot(output) as pylab:
            pylab.plot(0,0)
    """
    r = Report()
    f = r.figure()
    with f.plot("plot") as pylab:
        yield pylab
    output['png'] = r.resolve_url('png').get_raw_data()
    output['pdf'] = r.resolve_url('plot').get_raw_data()
예제 #3
0
        def go():
            string = request.params['string'].encode('utf-8')
            nl = int(request.params['nl'])
            nu = int(request.params['nu'])
            key = (string, nl, nu)
            s = self.solutions[key]

            result_l = s['result_l']
            result_u = s['result_u']
            # print result_l, result_u
            dpl = s['dpl']
            _dpu = s['dpu']

            R = dpl.get_res_space()
            UR = UpperSets(R)
            r = Report()
            f = r.figure()
            plotter = get_best_plotter(space=UR)
            # print plotter
            # generic_plot(f, space=UR, value=result_l)

            axis = plotter.axis_for_sequence(UR, [result_l, result_u])

            with f.plot("plot") as pylab:
                plotter.plot(pylab, axis, UR, result_l,
                             params=dict(markers='g.', color_shadow='green'))
                plotter.plot(pylab, axis, UR, result_u,
                             params=dict(markers='b.', color_shadow='blue'))


            png_node = r.resolve_url('png')
            png_data = png_node.get_raw_data()

            return response_data(request=request, data=png_data,
                                 content_type='image/png')
예제 #4
0
def gg_get_format(gg, data_format):
    from reprep import Report
    r = Report()
    do_dot = data_format == 'dot'
    do_png = data_format == 'png'
    do_pdf = data_format == 'pdf'
    do_svg = data_format == 'svg'
    gg_figure(r, 'graph', gg, do_dot=do_dot,
              do_png=do_png, do_pdf=do_pdf, do_svg=do_svg)

    if data_format == 'pdf':
        pdf = r.resolve_url('graph_pdf').get_raw_data()
        return pdf
    elif data_format == 'png':
        png = r.resolve_url('graph/graph').get_raw_data()
        return png
    elif data_format == 'dot':
        dot = r.resolve_url('dot').get_raw_data()
        return dot
    elif data_format == 'svg':
        svg = r.resolve_url('graph_svg').get_raw_data()
        return svg
    else:
        raise ValueError('No known format %r.' % data_format)
예제 #5
0
    def plot_value_generic(tag, vu):  # @UnusedVariable
        r = Report()
        f = r.figure()
        try:
            available = dict(get_plotters(get_all_available_plotters(), vu.unit))
            assert available
        except NotPlottable as e:
            msg = 'No plotters available for %s' % vu.unit
            raise_wrapped(ValueError, e, msg, compact=True)

        plotter = list(available.values())[0]

        axis = plotter.axis_for_sequence(vu.unit, [vu.value])
        axis = enlarge(axis, 0.15)
        with f.plot('generic') as pylab:
            plotter.plot(pylab, axis, vu.unit, vu.value, params={})
            pylab.axis(axis)
        png_node = r.resolve_url('png')
        png = png_node.get_raw_data()
        return png
예제 #6
0
    def plot_value_generic(tag, vu):  # @UnusedVariable
        r = Report()
        f = r.figure()
        try:
            available = dict(
                get_plotters(get_all_available_plotters(), vu.unit))
            assert available
        except NotPlottable as e:
            msg = 'No plotters available for %s' % vu.unit
            raise_wrapped(ValueError, e, msg, compact=True)

        plotter = list(available.values())[0]

        axis = plotter.axis_for_sequence(vu.unit, [vu.value])
        axis = enlarge(axis, 0.15)
        with f.plot('generic') as pylab:
            plotter.plot(pylab, axis, vu.unit, vu.value, params={})
            pylab.axis(axis)
        png_node = r.resolve_url('png')
        png = png_node.get_raw_data()
        return png
예제 #7
0
        def go():
            xaxis = str(e.request.params['xaxis'])
            yaxis = str(e.request.params['yaxis'])

            ndp, dp = self.get_ndp_dp_e(e)

            fnames = ndp.get_fnames()
            rnames = ndp.get_rnames()

            if not xaxis in fnames:
                msg = 'Could not find function %r.' % xaxis
                raise_desc(ValueError, msg, fnames=fnames)

            if not yaxis in rnames:
                msg = 'Could not find resource %r.' % yaxis
                raise_desc(ValueError, msg, rnames=rnames)

            fsamples = get_samples(e.request, ndp)

            nl = int(e.request.params.get('nl', 1))
            nu = int(e.request.params.get('nu', 1))

            dpl, dpu = get_dp_bounds(dp, nl, nu)

            def extract_ri(r):
                if len(rnames) == 1:
                    return r
                else:
                    i = rnames.index(yaxis)
                    return r[i]

            ru_samples = []
            rl_samples = []
            for f in fsamples:
                rl = dpl.solve(f)
                ru = dpu.solve(f)

                mcdp_dev_warning('should use join instead of min')

                values = filter(extract_ri, rl.minimals)
                rli = min(values) if values else None
                values = filter(extract_ri, ru.minimals)
                rui = max(values) if values else None

                ru_samples.append(rui)
                rl_samples.append(rli)

            r = Report()
            f = r.figure()
            with f.plot("plot") as pylab:
                pylab.plot(fsamples, rl_samples, 'b.-')
                pylab.plot(fsamples, ru_samples, 'm.-')

                xlabel = xaxis + ' ' + format_unit(ndp.get_ftype(xaxis))
                pylab.xlabel(xlabel)
                ylabel = yaxis + ' ' + format_unit(ndp.get_rtype(yaxis))
                pylab.ylabel(ylabel)
                y_axis_extra_space(pylab)
                x_axis_extra_space(pylab)
                ax = pylab.gca()
                XCOLOR = 'green'
                YCOLOR = 'red'
                ax.tick_params(axis='x', colors=XCOLOR)
                ax.tick_params(axis='y', colors=YCOLOR)
                ax.yaxis.label.set_color(YCOLOR)
                ax.xaxis.label.set_color(XCOLOR)

                ax.spines['bottom'].set_color(XCOLOR)
                ax.spines['left'].set_color(YCOLOR)

            png_node = r.resolve_url('png')
            png_data = png_node.get_raw_data()

            return response_data(request=e.request,
                                 data=png_data,
                                 content_type='image/png')
예제 #8
0
        def go():
            xaxis = str(request.params['xaxis'])
            yaxis = str(request.params['yaxis'])

            model_name = self.get_model_name(request)
            library = self.get_current_library_name(request)
            ndp, dp = self._get_ndp_dp(library, model_name)

            fnames = ndp.get_fnames()
            rnames = ndp.get_rnames()

            if not xaxis in fnames:
                msg = 'Could not find function %r.' % xaxis
                raise_desc(ValueError, msg, fnames=fnames)

            if not yaxis in rnames:
                msg = 'Could not find resource %r.' % yaxis
                raise_desc(ValueError, msg, rnames=rnames)

            fsamples = get_samples(request, ndp)

            nl = int(request.params.get('nl', 1))
            nu = int(request.params.get('nu', 1))
            
            dpl, dpu = get_dp_bounds(dp, nl, nu)
            
            def extract_ri(r):
                if len(rnames) == 1:
                    return r
                else:
                    i = rnames.index(yaxis)
                    return r[i]
                
            ru_samples = []
            rl_samples = []
            for f in fsamples:
                rl = dpl.solve(f)
                ru = dpu.solve(f)
                
                mcdp_dev_warning('should use join instead of min')
        
                values = filter(extract_ri, rl.minimals)
                rli = min(values) if values else None
                values = filter(extract_ri, ru.minimals)
                rui = max(values) if values else None

                ru_samples.append(rui)
                rl_samples.append(rli)

            r = Report()
            f = r.figure()
            with f.plot("plot") as pylab:
                pylab.plot(fsamples, rl_samples, 'b.-')
                pylab.plot(fsamples, ru_samples, 'm.-')

                xlabel = xaxis + ' ' + format_unit(ndp.get_ftype(xaxis))
                pylab.xlabel(xlabel)
                ylabel = yaxis + ' ' + format_unit(ndp.get_rtype(yaxis))
                pylab.ylabel(ylabel)
                y_axis_extra_space(pylab)
                x_axis_extra_space(pylab)
                ax = pylab.gca()
                XCOLOR = 'green'
                YCOLOR = 'red'
                ax.tick_params(axis='x', colors=XCOLOR)
                ax.tick_params(axis='y', colors=YCOLOR)
                ax.yaxis.label.set_color(YCOLOR)
                ax.xaxis.label.set_color(XCOLOR)

                ax.spines['bottom'].set_color(XCOLOR)
                ax.spines['left'].set_color(YCOLOR)

            png_node = r.resolve_url('png')
            png_data = png_node.get_raw_data()

            return response_data(request=request, data=png_data,
                                 content_type='image/png')