Пример #1
0
 def dashboard_devices_page():
     script = server_document("http://%s:5006/devices" % self.ip)
     return render_template(
         "device_table.html",
         sidebar=create_sidebar(devices_class='class="active"'),
         bokeh_script=script,
         template="Flask",
     )
Пример #2
0
 def bkapp_trends_page():
     if self.network.number_of_registered_trends > 0:
         script = server_document("http://%s:5006/trends" % self.ip)
     else:
         script = "<div>No trend registered yet...</div>"
     return render_template(
         "trends.html",
         sidebar=create_sidebar(trends_class='class="active"'),
         bokeh_script=script,
         template="Flask",
     )
Пример #3
0
def bokeh_row(request, job_id, type='individual-graph'):
    """
    Returns an embeded bokeh document in json. Javascript can use this method to inject bokeh document to jobs table.
    """
    try:
        job = TethysJob.objects.get_subclass(id=job_id)
        status = job.status

        # Get dashboard link for a given job_id
        scheduler_id = job.scheduler_id
        dask_scheduler = DaskScheduler.objects.get(id=scheduler_id)
        base_link = dask_scheduler.dashboard

        # Append http if not exists
        if 'http' not in base_link:
            base_link = 'http://' + base_link

        # Add forward slash if not exist
        if base_link[-1] != '/':
            base_link = base_link + '/'

        # use bokeh server_document to embed
        url_link = base_link + type
        script = server_document(url_link)

        context = {"the_script": script}
        success = True

    except Exception as e:
        log.error('The following error occurred when getting bokeh chart '
                  'from scheduler {} for job {}: {}'.format(dask_scheduler.name, job_id, str(e)))
        return

    # Render bokeh app into a string to pass in JsonResponse
    html = render_to_string('tethys_gizmos/gizmos/bokeh_application.html', context)
    return JsonResponse({'success': success, 'status': status, 'html': html})
Пример #4
0
def pdlgd():
    script = server_document('http://localhost:5006/bkapp')
    return render_template("embed.html", script=script, template="Flask")
Пример #5
0
def electricity_grid(request: HttpRequest) -> HttpResponse:
    script = server_document(bokeh_base_url + url_prefix + "/bokeh_grid",
                             relative_urls=relative_urls)
    return render(request, "main/grid.html", dict(script=script))
Пример #6
0
def python_bokeh():
    utils.bokehGarbageCollector()
    # retrieve input parameters
    document_id, widget_id = utils.retrieveWidgetInfo(request.get_json())
    script_file_name = constants.TMP_FOLDER + "bokeh_script_" + str(
        widget_id) + ".txt"
    user_id = utils.retrieveKnowageInfo(request.headers)
    dataset_name, datastore_request = utils.retrieveDatasetInfo(
        request.get_json())
    drivers = utils.retrieveAnalyticalDriversInfo(request.get_json())
    python_widget = PythonWidgetExecution(analytical_drivers=drivers,
                                          user_id=user_id,
                                          document_id=document_id,
                                          widget_id=widget_id,
                                          dataset_name=dataset_name,
                                          datastore_request=datastore_request)
    python_widget.script = security.loadScriptFromDB(python_widget)
    #destroy old bokeh server
    if utils.serverExists(python_widget.widget_id):
        utils.destroyServer(python_widget.widget_id)
    # resolve analytical drivers
    for d in drivers:
        python_widget.script = python_widget.script.replace(
            "$P{" + d + "}", "drivers_.get(\'" + d + "\')")
    # retrieve dataset
    if python_widget.dataset_name != None:
        dataset_file = constants.TMP_FOLDER + python_widget.dataset_name + ".pckl"
        df = utils.getDatasetAsDataframe(python_widget)
        df.to_pickle(dataset_file)
        python_widget.script = "import pandas as pd\n" + python_widget.dataset_name + " = pd.read_pickle(\"" + dataset_file + "\")\n" + python_widget.script

    #function executed by bokeh server
    def modify_doc(doc):
        # retrieve script from file
        with open(script_file_name, "r") as bk_file:
            bk_script = bk_file.read()
        #replace curdoc() with keyword "curdoc_"
        bk_script = bk_script.replace("curdoc()", "curdoc_")
        # execute script
        namespace = {'curdoc_': doc, "drivers_": drivers}
        exec(bk_script, namespace)

    #secondary thread function (bokeh server)
    def bk_worker():
        server = Server({'/bkapp' + str(python_widget.widget_id): modify_doc},
                        io_loop=IOLoop(),
                        allow_websocket_origin=["*"],
                        port=cuncurrency_manager.bokeh_resources[
                            python_widget.widget_id].port)
        with cuncurrency_manager.lck:
            cuncurrency_manager.active_servers.update(
                {python_widget.widget_id: server})  #{widget_id : bokeh_server}
        server.start()
        server.io_loop.start()

    #flush script content to file so that modify_doc() can retrieve the code to be executed
    with open(script_file_name, "w") as bokeh_file:
        bokeh_file.write(python_widget.script)

    #instance a bokeh server for the widget if not instanciated yet
    if not utils.serverExists(python_widget.widget_id):  #allocate bokeh server
        t = Thread(target=bk_worker)  #thread that hosts bokeh server
        bk_res = BokehResourceList(thread=t,
                                   timestamp=datetime.now(),
                                   port=utils.findFreePort(),
                                   dataset_name=dataset_name)
        with cuncurrency_manager.lck:
            cuncurrency_manager.bokeh_resources.update(
                {python_widget.widget_id:
                 bk_res})  #{widget_id : BokehResourceList}
        t.start()
    #serve plot
    jscript = server_document(utils.getPythonAddress() + ":" + str(
        cuncurrency_manager.bokeh_resources[python_widget.widget_id].port) +
                              "/bkapp" + str(python_widget.widget_id))
    return render_template("embed.html", script=jscript)
Пример #7
0
 def get(self):
     template = env.get_template('embed.html')
     script = server_document('http://localhost:5006/bkapp')
     self.write(template.render(script=script, template="Tornado"))
Пример #8
0
def dask_dashboard(request, dask_scheduler_id, page='status'):
    dask_object = DaskScheduler.objects.get(id=dask_scheduler_id)
    name = dask_object.name
    base_link = dask_object.dashboard

    # Append http(s) if not exists
    if 'http' not in base_link:
        base_link = 'http://' + base_link

    # Add forward slash if not exist
    if base_link[-1] != '/':
        base_link = base_link + '/'

    # Define url link for each page
    url_link = base_link + page
    status_link = reverse('admin:dask_dashboard', kwargs={'page': 'status', 'dask_scheduler_id': dask_scheduler_id})
    workers_link = reverse('admin:dask_dashboard', kwargs={'page': 'workers', 'dask_scheduler_id': dask_scheduler_id})
    tasks_link = reverse('admin:dask_dashboard', kwargs={'page': 'tasks', 'dask_scheduler_id': dask_scheduler_id})
    systems_link = reverse('admin:dask_dashboard', kwargs={'page': 'system', 'dask_scheduler_id': dask_scheduler_id})
    profile_link = reverse('admin:dask_dashboard', kwargs={'page': 'profile', 'dask_scheduler_id': dask_scheduler_id})
    graph_link = reverse('admin:dask_dashboard', kwargs={'page': 'graph', 'dask_scheduler_id': dask_scheduler_id})

    header_link = {"workers_link": workers_link, "tasks_link": tasks_link, "systems_link": systems_link,
                   "profile_link": profile_link, "graph_link": graph_link, "status_link": status_link}

    if page == 'status':
        # Get link for each bokeh application
        url_link_nbytes = base_link + 'individual-nbytes'
        url_link_nprocessing = base_link + 'individual-nprocessing'
        url_link_task_stream = base_link + 'individual-task-stream'
        url_link_progress = base_link + 'individual-progress'

        # Generate script using bokeh server_document method
        nbyte_script = server_document(url_link_nbytes)
        nprocessing_script = server_document(url_link_nprocessing)
        task_stream_script = server_document(url_link_task_stream)
        progress_script = server_document(url_link_progress)

        # get Div ID
        nbyte_id = re.search('id="(.+?)"><', nbyte_script).group(1)
        nprocessing_id = re.search('id="(.+?)"><', nprocessing_script).group(1)
        task_stream_id = re.search('id="(.+?)"><', task_stream_script).group(1)
        progress_id = re.search('id="(.+?)"><', progress_script).group(1)

        context = {"the_name": name, "nbyte_script": nbyte_script, "nprocessing_script": nprocessing_script,
                   "task_stream_script": task_stream_script, "progress_script": progress_script, "nbyte_id": nbyte_id,
                   "nprocessing_id": nprocessing_id, "task_stream_id": task_stream_id, "progress_id": progress_id}

        # add Header link into context
        context.update(header_link)

        return render(request, "tethys_compute/dask_scheduler_status.html", context)

    # For system we have to use session to load because they have many plots inside one application. If we use
    # use server_document, it will look very ugly when load to our page.
    elif page == 'system':
        with pull_session(url=url_link) as session:
            id_dict = {}
            scripts, divs = components({session.document.roots[0].title.text: session.document.roots[0],
                                        session.document.roots[1].title.text: session.document.roots[1],
                                        session.document.roots[2].title.text: session.document.roots[2],
                                        session.document.roots[3].title.text: session.document.roots[3]})
            # Extract out ID for each graph type
            for div in divs:
                id_value = re.search('id="(.+?)"><', divs[div]).group(1)
                id_dict[div.replace(' ', '_')] = {'id': id_value}

            context = {"the_script": scripts, "the_divs": id_dict, "the_name": name}

            # add Header link into context
            context.update(header_link)

            # use the script in the rendered page
            return render(request, "tethys_compute/dask_scheduler_system.html", context)
    else:
        script = server_document(url_link)

        context = {"the_name": name, "the_script": script}

        # Add header link into context
        context.update(header_link)

        if page == 'workers':
            return render(request, "tethys_compute/dask_scheduler_workers.html", context)
        elif page == 'tasks':
            return render(request, "tethys_compute/dask_scheduler_tasks.html", context)
        elif page == 'profile':
            return render(request, "tethys_compute/dask_scheduler_profile.html", context)
        elif page == 'graph':
            return render(request, "tethys_compute/dask_scheduler_graph.html", context)
Пример #9
0
 def bkapp_notes_page():
     script = server_document("http://%s:5006/notes" % self.ip)
     return render_template("embed.html", script=script, template="Flask")
Пример #10
0
def bkapp_page():
    script = server_document('http://localhost:5006/bkapp')
    return render_template("embed.html", script=script, template="Flask")
def ag():
    script = server_document("http://localhost:5007/ANN")
    return render_template("index2.html", script=script)
def tree():
    script = server_document("http://localhost:5006/Decision_Tree")
    return render_template("index.html", script=script)
Пример #13
0
def gbm(request: HttpRequest) -> HttpResponse:
    script = server_document(request.build_absolute_uri())
    return render(request, "gbm/gbm.html", dict(script=script))
Пример #14
0
def sea_surface_custom_uri(request: HttpRequest) -> HttpResponse:
    script = server_document(request._current_scheme_host + "/sea_surface")
    return render(request, "embed.html", dict(script=script))
Пример #15
0
def sea_surface(request: HttpRequest) -> HttpResponse:
    script = server_document(request.build_absolute_uri())
    return render(request, "embed.html", dict(script=script))
Пример #16
0
def bkapp_page():
    # Hier wird der Bokeh-Server gestartet
    script = server_document('http://localhost:%d/bkapp' % port)
    # und dem Flask Template zum einbetten übergeben
    return render_template("embed.html", script=script, template="Flask")
Пример #17
0
 def bkapp_notes_page():
     script = server_document('http://%s:5006/notes' % self.ip)
     return render_template("embed.html",
                            script=script,
                            template="Flask")
def bkapp_page():
    script = server_document('http://localhost:%d/bkapp' % port)
    return render_template("embed.html", script=script, template="Flask")
 def index():
     bokeh_script = server_document(
         url='http://localhost:5006/random_generator')
     return render_template('index_server.html',
                            bokeh_script=bokeh_script)
Пример #20
0
def index():
    tag = server_document(url=r'/bokeh', relative_urls=True)
    return render_template('index.html', tag=tag)
Пример #21
0
def pop(request: HttpRequest) -> HttpResponse:
    script = server_document(bokeh_base_url + url_prefix + "/bokeh_pop",
                             relative_urls=relative_urls)
    return render(request, "main/pop.html", dict(script=script))
Пример #22
0
def visualization(batchid):
    bokeh_script = server_document(url='http://localhost:5006/bokeh_server', arguments=dict(batchid=batchid))
    return render_template_string(app_html, bokeh_script=bokeh_script)
Пример #23
0
def visualization_page():
    script = server_document('http://localhost:5006/visualization')
    return render_template('embed.html', script=script, template='Flask')