Exemple #1
0
 def test_serialize_numpy_array(self):
     data = np.arange(5).astype('float64')
     data = protocol.serialize_json(data)
     data = protocol.deserialize_json(data)
     #we don't convert lists to numpy arrays, we just want to make sure
     #that we can go from numpy to lists/json
     assert data == [0., 1., 2., 3., 4.]
Exemple #2
0
    def make_html(self, all_models, model=None, inline=True,
                  template="bokeh.html", script_paths=None,
                  css_paths=None):
        import jinja2
        if script_paths is None:
            script_paths = dump.script_paths
        if css_paths is None:
            css_paths=dump.css_paths
        if model is None:
            model = self.ic
        template = get_template(template)
        elementid = str(uuid.uuid4())
        if inline:
            jsstr = inline_scripts(script_paths)
            cssstr = inline_css(css_paths)
            result = template.render(
                script_block=jsstr.decode('utf8'),
                css_block=cssstr.decode('utf8'),
                all_models=serialize_json([x.to_broadcast_json() \
                                       for x in all_models]),
                modelid=model.id,
                modeltype=model.typename,
                elementid=elementid
                )

            return result
Exemple #3
0
 def test_serialize_numpy_array(self):
     data = np.arange(5).astype('float64')
     data = protocol.serialize_json(data)
     data = protocol.deserialize_json(data)
     #we don't convert lists to numpy arrays, we just want to make sure
     #that we can go from numpy to lists/json
     assert data == [0.,1.,2.,3.,4.]
Exemple #4
0
 def deselect(self, deselect, transform):
     remotedata = self
     url = "http://%s:%s/array/%s/deselect" % (
         remotedata.host, remotedata.port, remotedata.varname)
     data = transform
     data['selected'] = deselect
     requests.post(url, data=protocol.serialize_json(data))
     self.selected = self.selected + 1
Exemple #5
0
 def get_data(self, transform):
     remotedata = self
     url = "http://%s:%s/array/%s" % (remotedata.host, remotedata.port,
                                      remotedata.varname)
     data = requests.get(url,
                         data=protocol.serialize_json(transform)).json()
     self.metadata = data.pop('metadata', {})
     return data
Exemple #6
0
 def get_data(self, transform):
     remotedata = self
     url = "http://%s:%s/array/%s" % (remotedata.host,
                                      remotedata.port,
                                      remotedata.varname)
     data = requests.get(url, data=protocol.serialize_json(transform)).json()
     self.metadata = data.pop('metadata', {})
     return data
Exemple #7
0
 def deselect(self, deselect, transform):
     remotedata = self
     url = "http://%s:%s/array/%s/deselect" % (remotedata.host,
                                               remotedata.port,
                                               remotedata.varname)
     data = transform
     data['selected'] = deselect
     requests.post(url, data=protocol.serialize_json(data))
     self.selected = self.selected + 1        
Exemple #8
0
    def set_computed_columns(self, computed_columns):

        remotedata = self
        url = "http://%s:%s/array/%s/computed" % (
            remotedata.host, remotedata.port, remotedata.varname)
        data = requests.get(
            url, data=protocol.serialize_json(computed_columns)).json()
        self.computed_columns = computed_columns
        self.data += 1
        return data
Exemple #9
0
 def set_computed_columns(self, computed_columns):
     
     remotedata = self
     url = "http://%s:%s/array/%s/computed" % (remotedata.host,
                                               remotedata.port,
                                               remotedata.varname)
     data = requests.get(
         url,
         data=protocol.serialize_json(computed_columns)).json()
     self.computed_columns = computed_columns
     self.data += 1
     return data
Exemple #10
0
 def create(self, model, defer=False):
     model.set('doc', self.docid)
     if defer:
         self.buffer.append(model)
     else:
         url = utils.urljoin(self.baseurl,
                             self.docid + "/",
                             model.typename +"/")
         log.debug("create %s", url)
         self.s.post(url, data=protocol.serialize_json(
             model.to_json(include_hidden=True)))
         model.set('created', True)
     return model
Exemple #11
0
 def make_html(self, all_models, model=None, template="base.html",
               script_paths=None, css_paths=None):
     if model is None:
         model = self.ic
     elementid = str(uuid.uuid4())
     plot_js = get_template('plots.js').render(
         elementid=elementid,
         modelid=model.id,
         all_models=serialize_json([x.to_broadcast_json()\
                                    for x in all_models]),
         modeltype=model.typename,
         )
     plot_div = get_template('plots.html').render(
         elementid=elementid
         )
     result = self.html(js_snippets=[plot_js],
                        template=template,
                        html_snippets=[plot_div],
                        script_paths=script_paths,
                        css_paths=css_paths
                        )
     return result
Exemple #12
0
 def make_html(self,
               all_models,
               model=None,
               template="base.html",
               script_paths=None,
               css_paths=None):
     if model is None:
         model = self.ic
     elementid = str(uuid.uuid4())
     plot_js = get_template('plots.js').render(
         elementid=elementid,
         modelid=model.id,
         all_models=serialize_json([x.to_broadcast_json()\
                                    for x in all_models]),
         modeltype=model.typename,
         )
     plot_div = get_template('plots.html').render(elementid=elementid)
     result = self.html(js_snippets=[plot_js],
                        template=template,
                        html_snippets=[plot_div],
                        script_paths=script_paths,
                        css_paths=css_paths)
     return result
Exemple #13
0
 def test_serialize_numpy_array_ints(self):        
     data = np.arange(5)
     data = protocol.serialize_json(data)
     data = protocol.deserialize_json(data)
     assert data == [0, 1, 2, 3, 4]
Exemple #14
0
 def test_serialize_numpy_array_ints(self):
     data = np.arange(5)
     data = protocol.serialize_json(data)
     data = protocol.deserialize_json(data)
     assert data == [0, 1, 2, 3, 4]
Exemple #15
0
 def test_numpy_2d(self):
     data = np.array([[1, 2], [3, 4]])
     data = protocol.serialize_json(data)
     data = protocol.deserialize_json(data)
     assert data == [[1, 2], [3, 4]]
Exemple #16
0
 def test_numpy_nested(self):
     data = np.array([[1, 2], [3, 4]])
     a = {'a': data}
     data = protocol.serialize_json(a)
     data = protocol.deserialize_json(data)
     assert data['a'] == [[1, 2], [3, 4]]
Exemple #17
0
 def test_numpy_nested(self):
     data = np.array([[1,2],[3,4]])
     a =  {'a' : data}
     data = protocol.serialize_json(a)
     data = protocol.deserialize_json(data)
     assert data['a'] == [[1, 2], [3, 4]]
Exemple #18
0
 def test_numpy_2d(self):
     data = np.array([[1,2],[3,4]])
     data = protocol.serialize_json(data)
     data = protocol.deserialize_json(data)
     assert data == [[1, 2], [3, 4]]