Ejemplo n.º 1
0
        def go():
            image_source = image_source_from_env(e)
            library = library_from_env(e)

            with timeit_wall('graph_generic', 1.0):
                key = (e.library_name, e.spec.url_part, e.thing_name,
                       text_hash)

                if not key in self.last_processed2:
                    logger.error('Cannot find key %s' % str(key))
                    logger.error('keys: %s' % list(self.last_processed2))
                    context = e.library._generate_context_with_hooks()
                    thing = e.spec.load(e.library,
                                        e.thing_name,
                                        context=context)
                else:
                    thing = self.last_processed2[key]
                    if thing is None:
                        return response_image(e.request, 'Could not parse.')

                with timeit_wall('graph_generic - get_png_data', 1.0):
                    data = e.spec.get_png_data(image_source=image_source,
                                               name=e.thing_name,
                                               thing=thing,
                                               data_format=data_format,
                                               library=library)
                mime = get_mime_for_format(data_format)
                return response_data(e.request, data, mime)
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
    def serve_scraped(self, request):
        hexified = request.matchdict['hex']
        num = int(request.matchdict['num'])

        qrstring = binascii.unhexlify(hexified)
        resource = self.retrieved[qrstring]['resources'][num]
        return response_data(request=request, data=resource.content,
                             content_type=resource.content_type)
Ejemplo n.º 4
0
    def serve_scraped(self, request):
        hexified = request.matchdict['hex']
        num = int(request.matchdict['num'])

        qrstring = binascii.unhexlify(hexified)
        resource = self.retrieved[qrstring]['resources'][num]
        return response_data(request=request, data=resource.content,
                             content_type=resource.content_type)
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
        def go():
            h = e.request.params['hash'].encode('utf-8')
            if not h in self.solutions:
                try:
                    h2 = base64.b64decode(h, altchars=altchars)
                    decoded = json.loads(h2)
                except Exception:
                    decoded = '(unparsable)'

                msg = 'Cannot find solution from hash.'
                others = list(self.solutions)
                raise_desc(DPInternalError,
                           msg,
                           h=h,
                           decoded=decoded,
                           others=others)
                #logger.error('do not have solution for %s' % orig)
            data = self.solutions[h]
            key = data['key']

            if key['type'] == QUERY_TYPE_FTOR:

                if key['do_approximations']:
                    result_l, result_u = data['result_l'], data['result_u']

                    dpl, _dpu = data['dpl'], data['dpu']

                    R = dpl.get_res_space()
                    UR = UpperSets(R)

                    output = {}
                    with save_plot(output) as pylab:
                        plotter = get_best_plotter(space=UR)
                        axis = plotter.axis_for_sequence(
                            UR, [result_l, result_u])
                        plotter.plot(pylab,
                                     axis,
                                     UR,
                                     result_l,
                                     params=dict(markers='g.',
                                                 color_shadow='orange'))
                        plotter.plot(pylab,
                                     axis,
                                     UR,
                                     result_u,
                                     params=dict(markers='b.',
                                                 color_shadow='blue'))

                    png = output['png']
                    return response_data(e.request, png, MIME_PNG)
                else:
                    result = data['result']
                    dp = data['dp']
                    R = dp.get_res_space()
                    UR = UpperSets(R)

                    output = {}
                    with save_plot(output) as pylab:
                        plotter = get_best_plotter(space=UR)
                        axis = plotter.axis_for_sequence(UR, [result])
                        plotter.plot(pylab,
                                     axis,
                                     UR,
                                     result,
                                     params=dict(markers='r.',
                                                 color_shadow='darkred'))

                    png = output['png']
                    return response_data(e.request, png, MIME_PNG)
            else:
                msg = 'Cannot display this.'
                return response_image(e.request, msg, color=(125, 125, 125))
Ejemplo n.º 7
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')