Example #1
0
 def test_register(self):
     #create a dummy config file
     config = tempfile.mkdtemp()
     #create server
     server = Session(name="foo", root_url="http://localhost:5006/",
                     configdir=config
                     )
     assert server.userapikey == "nokey"
     #register a user
     server.register("testuser", "fluffy")
     assert server.userapikey and server.userapikey != "nokey"
     #create a second server configuration
     #make sure it loads the proper api key
     server2 = Session(name="foo",
                      configdir=config
                      )
     assert server2.userapikey == server.userapikey
     assert server2.root_url == server.root_url
Example #2
0
 def test_register(self):
     #create a dummy config file
     config = tempfile.mkdtemp()
     #create server
     server = Session(name="foo", root_url="http://localhost:5006/",
                     configdir=config
                     )
     assert server.userapikey == "nokey"
     #register a user
     server.register("testuser", "fluffy")
     assert server.userapikey and server.userapikey != "nokey"
     #create a second server configuration
     #make sure it loads the proper api key
     server2 = Session(name="foo",
                      configdir=config
                      )
     assert server2.userapikey == server.userapikey
     assert server2.root_url == server.root_url
Example #3
0
    def test_login(self):
        #create a server config, register a user
        config1 = tempfile.mkdtemp()
        server = Session(name="foo", root_url="http://localhost:5006/",
                        configdir=config1
                        )
        assert server.userapikey == "nokey"
        server.register("testuser", "fluffy")
        assert server.userapikey and server.userapikey != "nokey"

        #create a separate server config, login a user
        config2 = tempfile.mkdtemp()
        server2 = Session(name="foo", root_url="http://localhost:5006/",
                         configdir=config2
                         )
        assert server2.userapikey == "nokey"
        server2.login("testuser", "fluffy")
        #make sure the userapikeys match
        assert server2.userapikey == server.userapikey
Example #4
0
    def test_login(self):
        #create a server config, register a user
        config1 = tempfile.mkdtemp()
        server = Session(name="foo", root_url="http://localhost:5006/",
                        configdir=config1
                        )
        assert server.userapikey == "nokey"
        server.register("testuser", "fluffy")
        assert server.userapikey and server.userapikey != "nokey"

        #create a separate server config, login a user
        config2 = tempfile.mkdtemp()
        server2 = Session(name="foo", root_url="http://localhost:5006/",
                         configdir=config2
                         )
        assert server2.userapikey == "nokey"
        server2.login("testuser", "fluffy")
        #make sure the userapikeys match
        assert server2.userapikey == server.userapikey
def prepare_widgets():
    print "initializing..."
    # start bokeh-server session
    global client
    client = Session(root_url='http://0.0.0.0:7010/', load_from_config=False)
    try:
        client.register(bs_login,bs_password)
    except:pass

    client.login(bs_login,bs_password)

    ###CREATE WIDGETS
    print "preaparing widgets..."
    #hist1: hist with overlay
    import analysis.distfit as distfit
    import pandas as pd
    xname,xmin,xmax,xbins = "invariantMass",0,10,50


    bin_separators = np.histogram([],bins=xbins, range=[xmin,xmax])[1]
    bin_centers = np.array([0.5*(bin_separators[i]+bin_separators[i+1]) for i in range(len(bin_separators)-1)])
    bins = pd.DataFrame({"x":bin_centers})

    expo_gap = lambda x,slope: (x>=xmin)*(x<=xmax)*distfit.exponential(x-xmin,slope)/(1.-np.e**(-(xmax-xmin)*slope))
    mix_model = distfit.DistributionsMixture(
        distributions={'sig': distfit.gauss, 'bck': expo_gap},
        weights_ranges={'sig': [1.,10.], 'bck': [1.,10.]},
        parameter_ranges={'mean': [xmin ,xmax], 'sigma': [0., xmax-xmin], 'slope': [0, 15.]},
        column_ranges={'x': [xmin, xmax]},
        sampling_strategy='grid',
    )


    mix_model.compile(bins,1000) #takes several seconds



    hist1_base = WhiskeredHistWidget(xname,xmin,xmax,xbins,es,
                       fig = figure(plot_width=600, plot_height=600,tools=['wheel_zoom','ywheel_zoom','pan','resize','reset']))
    hist1 = MLFitOverlayWidget(hist1_base,mix_model,n_pts=100)
    widgets.append(hist1)

    #hist2: just hist
    hist2 = ClassicHistWidget("muonHits",0,100,30,es,
                       fig = figure(plot_width=600, plot_height=600,tools=['wheel_zoom','ywheel_zoom','pan','reset']))
    widgets.append(hist2)


    #hist3: heatmap
    hist3 = HeatmapWidget("avgMass",0,35,50,
                          "muonHits",0,70,50,
                          es,fig = figure(plot_width=600, plot_height=600),)
    widgets.append(hist3)

    #hist4: hist with reference
    hist4_base = ClassicHistWidget("dskkpi",1920,2020,30,es,
                       fig = figure(plot_width=600, plot_height=600,tools=['wheel_zoom','ywheel_zoom','pan','reset']))
    
    from scipy.stats import laplace
    pdf = laplace(1970,7).pdf
    hist4 = ReferenceOverlay(hist4_base,pdf)
    widgets.append(hist4)    
    
    ###end CREATE PLOTS

    print "publishing plots..."
    #create a dashboard on bokeh_server
    output_server(dashboard_name,client)

    plots = [ hplot(widget.fig) for widget in widgets ]

    global whole_dashboard
    whole_dashboard = vplot(hplot(*plots[:2]),hplot(*plots[2:]))
    plots.append(whole_dashboard)    

    for plot in plots:
        client.show(plot)


    client.publish()
 
    print "creating static links..."
    #publish the thing
    from bokeh.embed import autoload_server
    scripts = [autoload_server(plot,client,public=True) for plot in plots]


    
    print "saving widget scripts..."
    
    #remove previous widgets
    for path_to_static in path_to_django_static,path_to_flask_static:
        path_to_widgets = os.path.join(path_to_static,dashboard_name)

        os.system("rm -rf " + path_to_widgets)
        os.mkdir(path_to_widgets)

        for i, source_script in enumerate(scripts):
            
            #convert script...
            script = assemble_script("widget"+str(i),source_script)
            
            with open("{}/widget{}.html".format(path_to_widgets,i),'w') as fscript:
                fscript.write(script)
    

    print "dashboard {} ready.".format(dashboard_name),