def make_html(request):
    """i knit a bokeh html if asked from AJAX"""
    fig = figure()
    _=vis_bokeh.draw_1d_hist_from_es("avgMass",0,40,50,es,"run*",ax=fig)
    fig.xaxis.axis_label = time.strftime("%H:%M:%S")
    fig_html = vis_bokeh.fig_to_html(fig)
    return HttpResponse(fig_html)	
    def knit_html(self,es):
        #col1
        fig1 = figure(width=250,height=250)
        vis_bokeh.draw_1d_hist_from_es("dummy1",0,35,30,es,"run*",ax=fig1) #changes fig1, but also returns it

        fig2=figure(width=250,height=250)
        xmin,xmax = 0,65
        xbins = 20
        xname = "hcalEnergy"
        ymin,ymax = 0,65
        ybins = 20
        yname = "muonHits"
        vis_bokeh.draw_2d_hist_from_es(xname,xmin,xmax,xbins,yname,ymin,ymax,ybins,es,
                                         index="run*",ax=fig2)
        fig_column1 = vplot(fig1,fig2)

        #col2
        fig3 = figure(width=250,height=250)
        fig3=vis_bokeh.draw_1d_hist_from_es("dummy23",0,100,30,es,"run*",ax=fig3,hist_drawer="classic")
        fig4 = figure(width=250,height=250)
        fig4=vis_bokeh.draw_1d_hist_from_es("dummy45",0,40,30,es,"run*",ax=fig4)
        fig_column2 = vplot(fig3,fig4)

        fig_grid = hplot(fig_column1,fig_column2)
        
        return vis_bokeh.fig_to_html(fig_grid)
    def get_value(self):
        fig = figure()
        
        xname = "invariantMass"
        xmin,xmax,xbins = -5.,15.,50
        index = "run*"
        
        x,counts = vis_bokeh.get_1d_hist(xname,xmin,xmax,xbins,es,index=index)
        
        deltas = np.sqrt(counts)
        
        fig=vis_bokeh.whiskered_histogram(xmin,xmax,xbins,counts,deltas,-deltas)
        
        #fit params
        model = mix
        model.fit(sample_weight=counts)#,values_init={'sig_weightlog':np.log(0.4),'bck_weightlog':np.log(0.6)})
        parameters = model.parameters
        w_sig,w_bkg =np.exp(parameters['sig_weightlog']),np.exp(parameters['bck_weightlog'])
        w_sum = w_sig+w_bkg
        w_sig,w_bkg = w_sig/w_sum,w_bkg/w_sum
        n_events = np.sum(counts)
        norm = n_events*(xmax-xmin)/xbins
        
        #plot lines
        expo = lambda x_arr:st.expon(0,1./parameters['slope']).pdf(x_arr)*w_bkg*norm
        gauss = lambda x_arr:st.norm(parameters['mean'],parameters['sigma']).pdf(x_arr)*w_sig*norm
        pdf_x = np.arange(1000,dtype='float')/1000.*(xmax-xmin) + xmin
        
        fig.line(pdf_x, expo(pdf_x), legend="Background", line_width=2,color = 'red')
        fig.line(pdf_x, gauss(pdf_x), legend="Signal", line_width=2,color='blue')
        fig.line(pdf_x, gauss(pdf_x)+expo(pdf_x), legend="Sum", line_width=2,color='green')

        fig.xaxis.axis_label = time.strftime("%H:%M:%S")
        return vis_bokeh.fig_to_html(fig)
 def knit_html(self,es):
     
     figs = []
     for i in range(len(self.hists)):
         figs.append(
             [self.make_figure(hist,model,es,"run*") for hist,model in zip(self.hists[i],self.models[i])]
             )
     hrows = [hplot(*row) for row in figs]
     grid = vplot(*hrows)
         
         
         
     
     return vis_bokeh.fig_to_html(grid)
 def get_value(self):
     fig = figure()
     _=vis_bokeh.draw_1d_hist_from_es("avgMass",0,40,50,es,"run*",ax=fig)
     fig.xaxis.axis_label = time.strftime("%H:%M:%S")
     fig_html = vis_bokeh.fig_to_html(fig)
     return fig_html
 def knit_html(self,es):
     fig = figure()
     _=vis_bokeh.draw_1d_hist_from_es("avgMass",0,70,50,es,"run*",ax=fig)
     return vis_bokeh.fig_to_html(fig)
 def knit_html(self,es):
     hist = Histogram([1,2,3])
     return fig_to_html(hist)