Example #1
0
 def test_publish_fails_for_invalid_auth(self):
     sess = Session(client=app.test_client())
     sess.register('testuser', 'testpassword')
     sess.use_doc('test_cow')
     sess2 = Session(client=app.test_client())
     sess2.register('testuser2', 'testpassword')
     sess2.docid = sess.docid
     self.assertRaises(Exception, sess2.publish)
Example #2
0
def init_plot(crawl_name):
    session = Session()
    document = Document()
    session.use_doc(crawl_name)
    session.load_document(document)

    if document.context.children:
        plot = document.context.children[0]
    else:
        output_server(crawl_name)
        # TODO: Remove these when Bokeh is upgraded
        # placeholders or Bokeh can't inject properly
        current = np.datetime64(datetime.now())
        xdr = Range1d(current, current + 1)
        ydr = ["urls"]

        # styling suggested by Bryan
        plot = figure(title="Crawler Monitor",
                      tools="hover",
                      x_axis_type="datetime",
                      y_axis_location="right",
                      x_range=xdr,
                      y_range=ydr,
                      width=1200,
                      height=600)
        plot.toolbar_location = None
        plot.xgrid.grid_line_color = None

    document.add(plot)
    session.store_document(document)
    script = autoload_server(plot, session)

    #TODO: Looks like a Bokeh bug, probably not repeatable with current code
    script = script.replace("'modelid': u'", "'modelid': '")
    return script
Example #3
0
 def __init__(self, document_name, server_url=None, clear_document=True):
     super(PlottingExtension, self).__init__()
     self.document_name = document_name
     self.server_url = DEFAULT_SRV_URL if server_url is None else server_url
     self.session = Session(root_url=self.server_url)
     self.document = Document()
     self._setup_document(clear_document)
    def test_heatmap_recipe(self):
        ar_downsample._loadAR()
        reset_output()
        sess = Session(client=app.test_client())
        output_server('Census', session=sess)
        source = ServerDataSource(expr={
            'op': 'Field',
            'args': [':leaf', 'bivariate']
        })
        plot = figure(plot_width=600, plot_height=400, title="Test Title")
        plot.square('A', 'B', source=source)

        plot2 = ar_downsample.heatmap(plot,
                                      palette="Reds9",
                                      reserve_val=0,
                                      points=True,
                                      client_color=True,
                                      title="Test Title 2")
        source2 = self._find_source(plot2)

        self.assertEquals("Test Title 2", plot2.title)
        self.assertEquals(type(source2), ServerDataSource)

        transform = source2.transform
        self.assertEquals(type(transform['info']), ar_downsample.Const)
        self.assertEquals(type(transform['agg']), ar_downsample.Count)
        self.assertEquals(type(transform['shader']), ar_downsample.Seq)
        self.assertEquals(transform['shader'].out, "image")
    def test_source(self):
        ar_downsample._loadAR()
        sess = Session(client=app.test_client())
        output_server('Census', session=sess)
        source = ServerDataSource(expr={
            'op': 'Field',
            'args': [':leaf', 'bivariate']
        })

        plot = figure()
        plot.square('A', 'B', source=source)

        agg = ar_downsample.CountCategories()
        info = ar_downsample.Const(val=1)
        shader = ar_downsample.InterpolateColor()

        new_source = ar_downsample.source(plot,
                                          agg=agg,
                                          info=info,
                                          shader=shader)
        self.assertIsNotNone(new_source.transform)
        trans = new_source.transform

        self.assertEquals(trans['resample'], 'abstract rendering')
        self.assertEquals(trans['agg'], agg)
        self.assertEquals(trans['info'], info)
        self.assertEquals(trans['shader'], shader)
        self.assertEquals(trans['glyphspec'],
                          plot.select({'type': GlyphRenderer})[0].glyph)
        self.assertEquals(trans['points'], False)
    def test_replot_result_type(self):
        ar_downsample._loadAR()
        sess = Session(client=app.test_client())
        output_server('Census', session=sess)
        source = ServerDataSource(expr={
            'op': 'Field',
            'args': [':leaf', 'bivariate']
        })
        plot = figure()
        plot.square('A', 'B', source=source)

        expected = {
            "image": "Image",
            "image_rgb": "ImageRGBA",
            "multi_line": "MultiLine"
        }

        shaders = dict()

        for name in dir(ar_downsample):
            item = getattr(ar_downsample, name)
            if isinstance(item, ar_downsample.Shader):
                shaders[item] = item.out

        for shader_class in shaders:
            shader = shader_class()
            rslt = ar_downsample.replot(plot, shader=shader)
            self.assertEquals(
                expected[shader.out],
                self._glyphspec(rslt)['type'],
                "Error with {0}. Expected {1}, recieved {2}".format(
                    str(shader_class), expected[shader.out],
                    self._glyphspec(rslt)))
Example #7
0
 def test_publish(self):
     sess = Session(client=app.test_client())
     sess.register('testuser', 'testpassword')
     sess.use_doc('test_cow')
     sess.publish()
     doc = Doc.load(bokeh_app.servermodel_storage, sess.docid)
     assert doc.title == 'test_cow'
     assert doc.published == True
Example #8
0
    def __init__(self, **kw):
        super(RadialGraph, self).__init__(**kw)
        self._node_source = ColumnDataSource(dict(id=[], time=[],
                                                  relevance=[]))
        self._edge_source = ColumnDataSource(dict(parent=[], child=[]))

        self._session = Session()
        self._doc = Document()
Example #9
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 #10
0
 def test_register_configuration(self):
     #create a dummy config file
     config = tempfile.mkdtemp()
     #create server
     server = Session(name="foo",
                      client=app.test_client(),
                      configdir=config,
                      load_from_config=True)
     assert server.userapikey == "nokey"
     #register a user
     server.register("testuser", "fluffy")
     assert server.userapikey and server.userapikey != "nokey"
     server2 = Session(name="foo",
                       client=app.test_client(),
                       configdir=config,
                       load_from_config=True)
     assert server2.userapikey == server.userapikey
     assert server2.root_url == server.root_url
Example #11
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 #12
0
    def test_login2(self):
        #create a server config, register a user
        config1 = tempfile.mkdtemp()
        server = Session(name="foo",
                         client=app.test_client(),
                         configdir=config1,
                         load_from_config=True)
        assert server.userapikey == "nokey"
        server.register("testuser", "fluffy")
        assert server.userapikey and server.userapikey != "nokey"

        config2 = tempfile.mkdtemp()
        server2 = Session(name="foo",
                          client=app.test_client(),
                          configdir=config2,
                          load_from_config=True)
        assert server2.userapikey == "nokey"
        server2.login("testuser", "fluffy")
        #make sure the userapikeys match
        assert server2.userapikey == server.userapikey
Example #13
0
    def __init__(self):
        from bokeh.document import Document
        from bokeh.session import Session
        from bokeh.models import ColumnDataSource
        from bokeh.sampledata.population import load_population

        self.document = Document()
        self.session = Session()
        self.session.use_doc('population')
        self.session.load_document(self.document)

        self.df = load_population()
        self.source_pyramid = ColumnDataSource(data=dict())
Example #14
0
    def test_login1(self):
        username = "******"
        password = "******"
        user.new_user(bokeh_app.servermodel_storage, username, password)
        sess = Session(client=app.test_client())
        #have not logged in yet, so userinfo should return http error
        self.assertRaises(Exception, lambda: sess.userinfo)

        #try logging in with wrong password, should be 403
        self.assertRaises(Exception, sess.login, 'testuser2', 'wrong password')

        #actually login
        sess.login('testuser2', 'fluffy')
        assert sess.userinfo['username'] == 'testuser2'
Example #15
0
 def __init__(self,
              document_name,
              server_url=None,
              start_server=False,
              clear_document=True,
              **kwargs):
     self.document_name = document_name
     self.server_url = (config.bokeh_server
                        if server_url is None else server_url)
     self.start_server = start_server
     self.sub = self._start_server_process() if self.start_server else None
     self.session = Session(root_url=self.server_url)
     self.document = Document()
     self._setup_document(clear_document)
     super(PlottingExtension, self).__init__(**kwargs)
Example #16
0
    def __init__(self):
        self.document = Document()
        self.session = Session()
        self.session.use_doc('data_tables_server')
        self.session.load_document(self.document)

        self.manufacturer_filter = None
        self.model_filter = None
        self.transmission_filter = None
        self.drive_filter = None
        self.class_filter = None

        self.source = ColumnDataSource()
        self.update_data()

        self.document.add(self.create())
        self.session.store_document(self.document)
Example #17
0
        def wrapper(*args, **kwargs):
            docname = prefix + str(uuid.uuid4())
            session = Session(name=url, root_url=url)
            session.use_doc(docname)
            session.load_document(curdoc())
            curdoc().autoadd = False
            curdoc().autostore = False

            obj = func(*args, **kwargs)
            tag = embed.autoload_server(obj, session)
            obj.tag = tag

            curdoc().add(obj)
            changed = session.store_document(curdoc())

            logger.debug("stored: %s", str(changed))

            return obj
Example #18
0
    def __init__(self):
        self.document = Document()
        self.session = Session()
        self.session.use_doc('crawler_dashboard')
        self.session.load_document(self.document)

        #self.harvest_source = ColumnDataSource(data=dict())
        #self.domain_relevant_source = ColumnDataSource(data=dict())
        #self.domain_crawled_source = ColumnDataSource(data=dict())
        #self.domain_frontier_source = ColumnDataSource(data=dict())
        #self.handson_source = ColumnDataSource(data=dict())
        #self.termite_source = ColumnDataSource(data=dict())

        self.harvest = Harvest()
        self.domain = Domain()
        #handson = Handson()
        self.termite = Termite()

        self.document.add(self.create_layout())
        self.session.store_document(self.document)
Example #19
0
    def __init__(self, path, url):
        self.document = Document()
        self.session = Session(name=url, root_url=url)
        #self.session = Session('load_from_config=False')
        self.session.use_doc('crawler_dashboard')
        self.session.load_document(self.document)

        #self.harvest_source = ColumnDataSource(data=dict())
        #self.domain_relevant_source = ColumnDataSource(data=dict())
        #self.domain_crawled_source = ColumnDataSource(data=dict())
        #self.domain_frontier_source = ColumnDataSource(data=dict())
        #self.handson_source = ColumnDataSource(data=dict())
        #self.termite_source = ColumnDataSource(data=dict())
        self.harvest = Harvest(path)
        self.domain = Domain(path)
        #handson = Handson()
        #self.termite = Termite()

        self.document.add(self.create_layout())
        self.session.store_document(self.document)
    def test_replot_remove(self):
        ar_downsample._loadAR()
        reset_output()
        sess = Session(client=app.test_client())
        output_server('Census', session=sess)
        source = ServerDataSource(expr={
            'op': 'Field',
            'args': [':leaf', 'bivariate']
        })
        plot = figure()
        plot.square('A', 'B', source=source)
        ar_downsample.replot(plot, remove_original=False)

        self.assertTrue(plot in curdoc().context.children, "Not retained")
        ar_downsample.replot(plot, remove_original=True)
        self.assertTrue(plot not in curdoc().context.children, "Not removed")

        try:
            ar_downsample.replot(plot, remove_original=True)
        except:
            self.assertTrue(False, "Error reploting plot not in curdoc")
    def test_replot_property_transfer(self):
        ar_downsample._loadAR()
        sess = Session(client=app.test_client())
        output_server('Census', session=sess)
        source = ServerDataSource(expr={
            'op': 'Field',
            'args': [':leaf', 'bivariate']
        })

        plot_width = 612
        plot_height = 408
        plot_title = "Test title"

        plot = figure(plot_width=plot_width,
                      plot_height=plot_height,
                      title=plot_title)
        plot.square('A', 'B', source=source)
        ar_plot = ar_downsample.replot(plot)

        self.assertEquals(ar_plot.plot_width, plot_width,
                          "Plot width not transfered")
        self.assertEquals(ar_plot.plot_height, plot_height,
                          "Plot height not transfered")
        self.assertEquals(ar_plot.title, plot_title,
                          "Plot title not transfered")

        plot_width = 612
        plot_height = 408
        plot_title = "Test title"
        ar_plot = ar_downsample.replot(plot,
                                       title=plot_title,
                                       plot_width=plot_width,
                                       plot_height=plot_height)
        self.assertEquals(ar_plot.plot_width, plot_width,
                          "Plot width override failed")
        self.assertEquals(ar_plot.plot_height, plot_height,
                          "Plot height override failed")
        self.assertEquals(ar_plot.title, plot_title,
                          "Plot title override failed")
    def test_contour_recipe(self):
        ar_downsample._loadAR()
        reset_output()
        sess = Session(client=app.test_client())
        output_server('Census', session=sess)
        source = ServerDataSource(expr={
            'op': 'Field',
            'args': [':leaf', 'bivariate']
        })
        plot = figure(plot_width=600, plot_height=400, title="Test Title")
        plot.square('A', 'B', source=source)

        plot2 = ar_downsample.contours(plot, title="Contour")
        source2 = self._find_source(plot2)

        self.assertEquals("Contour", plot2.title)
        self.assertEquals(type(source2), ServerDataSource)

        transform = source2.transform
        self.assertEquals(type(transform['info']), ar_downsample.Const)
        self.assertEquals(type(transform['agg']), ar_downsample.Count)
        self.assertEquals(type(transform['shader']), ar_downsample.Seq)
        self.assertEquals(transform['shader'].out, "multi_line")
Example #23
0
    def __init__(self, crawl_name, num_urls=DEFAULT_NUM_URLS):
        """
        Create a NutchUrlTrails instance for visualizing a running Nutch crawl in real-time using Bokeh
        :param name: The name of the crawl (as identified by the queue)
        :param num_urls: The number of URLs to display in the visualization
        :return: A NutchUrLTrails instance
        """
        self.crawl_name = crawl_name
        self.num_urls = num_urls
        self.open_urls = {}
        self.closed_urls = {}
        self.old_segments = None
        self.old_circles = None

        self.session = Session()
        self.session.use_doc(self.crawl_name)
        self.document = Document()

        con = Connection()

        exchange = Exchange(EXCHANGE_NAME, 'direct', durable=False)
        queue = Queue(crawl_name, exchange=exchange, routing_key=crawl_name)
        self.queue = con.SimpleQueue(name=queue)
Example #24
0
from requests.exceptions import ConnectionError
import pandas as pd
from bokeh.objects import (Plot, ColumnDataSource, DataRange1d, FactorRange,
                           LinearAxis, CategoricalAxis, Grid, Glyph)
from bokeh.widgetobjects import (DateRangeSlider, HBox, VBox, Paragraph,
                                 Select, VBoxModelForm)
from bokeh.glyphs import Rect
from bokeh.document import Document
from bokeh.session import Session

import employment_data_reader as emp
from employment_utils import get_country_for_byte, get_jobtype_for_byte

document = Document()
session = Session()
session.use_doc('employment_server')
session.load_document(document)

days_of_week = {
    0: "Monday",
    1: "Tuesday",
    2: "Wednesday",
    3: "Thursday",
    4: "Friday",
    5: "Saturday",
    6: "Sunday"
}
bounds_start = datetime.date(2012, 11, 1)
bounds_end = datetime.date(2013, 12, 30)
start = datetime.date(2013, 5, 26)
Example #25
0
 def test_register_twice_should_fail(self):
     sess = Session(client=app.test_client())
     sess.register('testuser1', 'testpassword1')
     self.assertRaises(RuntimeError, sess.register, 'testuser1',
                       'testpassword1')
Example #26
0
 def test_register(self):
     sess = Session(client=app.test_client())
     sess.register('testuser1', 'testpassword1')
     sess.userinfo['username'] == 'testuser1'
Example #27
0
 def __setstate__(self, state):
     self.__dict__.update(state)
     self.session = Session(root_url=self.server_url)
     self._document_setup_done = False
Example #28
0
 def setUp(self):
     self.sess = Session(load_from_config=False)
     self.sess.docid = 'docid10'
     self.sess.apikey = 'apikey123'
     self.sess.root_url = "http://foo"
Example #29
0
import pandas as pd

from bokeh.plotting import figure, vplot, output_server, show, push, cursession, ColumnDataSource
from bokeh.models import HoverTool, PanTool, BoxZoomTool, ResizeTool, WheelZoomTool, PreviewSaveTool, ResetTool
from bokeh.models.formatters import DatetimeTickFormatter, PrintfTickFormatter
from bokeh.models.widgets import Panel, Tabs
from bokeh.session import Session
from json import load
from urllib2 import urlopen
from bokeh.embed import autoload_server
from pymongo import MongoClient
import time
import os
import sys

ssn = Session(load_from_config=False)
output_server("predictions", session=ssn)

ec2host = os.environ['EC2HOST']
client = MongoClient(host=ec2host, port=27017)
db = client['apidata']
collection = db['uberapi']

model1_file = 'data/model1_w_surgemulti_forecast.csv'
# model2_file = 'data/model2_wo_surgemulti_forecast.csv'
model3_file = 'data/ridgecv_uber_forecast.csv'
model4_file = 'data/uber_arima_forecast.csv'
model5_file = 'data/xgboost_model_forecast.csv'


def get_forecast_data(forecast_file):
# The plot server must be running
# The server must run with --multi-user for this example to work
# Go to http://localhost:5006/bokeh to view this plot

import time

import numpy as np

from bokeh.plotting import *
from bokeh.session import Session
from bokeh import embed
Session().register('testuser', 'testpassword')
N = 80
x = np.linspace(0, 4 * np.pi, N)
y = np.sin(x)
output_server("line_animate")
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"
p = figure(tools=TOOLS)
p.circle(x, y, color="#3333ee", name="sin")
push()
renderer = p.select(dict(name="sin"))
ds = renderer[0].data_source
cursession().publish()
tag = embed.autoload_server(p, cursession(), public=True)
html = """
<html>
<head></head>
<body>
%s
</body>
</html>