示例#1
0
    def test_manager_view_computed_schema(self):
        post_callback = partial(self.validate_post,
                                expected={
                                    "id": 1,
                                    "data": {
                                        "abc": "float"
                                    }
                                })

        message = {
            "id": 1,
            "name": "view1",
            "cmd": "view_method",
            "method": "computed_schema",
            "args": [False]
        }
        manager = PerspectiveManager()
        table = Table(data)
        view = table.view(computed_columns=[{
            "column": "abc",
            "computed_function_name": "+",
            "inputs": ["a", "a"]
        }])
        manager.host_table("table1", table)
        manager.host_view("view1", view)
        manager._process(message, post_callback)
示例#2
0
def make_app():
    with open(file_path, mode='rb') as file:
        # Create an instance of `PerspectiveManager` and a table.
        MANAGER = PerspectiveManager()
        TABLE = Table(file.read(), index="Row ID")

        # Track the table with the name "data_source_one", which will be used
        # in the front-end to access the Table.
        MANAGER.host_table("data_source_one", TABLE)
        MANAGER.host_view("view_one", TABLE.view())

        return tornado.web.Application(
            [
                # create a websocket endpoint that the client Javascript can access
                (r"/websocket", PerspectiveTornadoHandler, {
                    "manager": MANAGER,
                    "check_origin": True
                }),
                (r"/node_modules/(.*)", tornado.web.StaticFileHandler, {
                    "path": "../../node_modules/@finos/"
                }),
                (r"/(.*)", tornado.web.StaticFileHandler, {
                    "path": "./",
                    "default_filename": "index.html"
                })
            ],
            websocket_ping_interval=15)
def make_app():
    # Create an instance of `PerspectiveManager` and a table.
    MANAGER = PerspectiveManager()
    TABLE = Table({
        "name": str,
        "client": str,
        "open": float,
        "high": float,
        "low": float,
        "close": float,
        "lastUpdate": datetime,
    }, limit=2500)

    # Track the table with the name "data_source_one", which will be used in
    # the front-end to access the Table.
    MANAGER.host_view("data_source_one", TABLE.view())

    # update with new data every 50ms
    def updater():
        TABLE.update(data_source())

    callback = tornado.ioloop.PeriodicCallback(callback=updater, callback_time=1)
    callback.start()

    return tornado.web.Application([
        (r"/", MainHandler),
        # create a websocket endpoint that the client Javascript can access
        (r"/websocket", PerspectiveTornadoHandler, {"manager": MANAGER, "check_origin": True})
    ])
示例#4
0
 def test_locked_manager_create_view(self):
     message = {"id": 1, "name": "view1", "cmd": "view_method", "method": "schema", "args": []}
     manager = PerspectiveManager(lock=True)
     table = Table(data)
     view = table.view()
     manager.host_table("table1", table)
     manager.host_view("view1", view)
     manager._process(message, self.post)
     assert manager.get_view("view1").schema() == {
         "a": int,
         "b": str
     }
示例#5
0
    def test_manager_view_schema(self):
        post_callback = partial(self.validate_post, expected={
            "id": 1,
            "data": {
                "a": "integer",
                "b": "integer"
            }
        })

        message = {"id": 1, "name": "view1", "cmd": "view_method", "method": "schema", "args": [False]}
        manager = PerspectiveManager()
        table = Table(data)
        view = table.view(row_pivots=["a"])
        manager.host_table("table1", table)
        manager.host_view("view1", view)
        manager._process(message, post_callback)
示例#6
0
def make_app():
    here = os.path.abspath(os.path.dirname(__file__))

    DATA_HOST = DataHost()
    MANAGER = PerspectiveManager(lock=True)
    STATE_TABLE = DATA_HOST.state_table
    COUNTY_TABLE = DATA_HOST.county_table
    MANAGER.host_view("state_data_source", STATE_TABLE.view())
    MANAGER.host_view("county_data_source", COUNTY_TABLE.view())

    return tornado.web.Application([
        (r"/", MainHandler),
        # create a websocket endpoint that the client Javascript can access
        (r"/static/(.*)", StaticHandler, {"path": os.path.join(here, "static")}),
        (r"/ws", PerspectiveTornadoHandler, {"manager": MANAGER, "check_origin": True})
    ])
示例#7
0
    def test_manager_table_get_computation_input_types(self):
        post_callback = partial(self.validate_post, expected={
            "id": 1,
            "data": ["string"]
        })

        message = {
            "id": 1,
            "name": "table1",
            "cmd": "table_method",
            "method": "get_computation_input_types",
            "args": ["concat_comma"]
        }
        manager = PerspectiveManager()
        table = Table(data)
        view = table.view()
        manager.host_table("table1", table)
        manager.host_view("view1", view)
        manager._process(message, post_callback)
示例#8
0
def make_app():
    # Create an instance of `PerspectiveManager` and a table.
    MANAGER = PerspectiveManager()
    TABLE = None

    TABLE = Table(pd.read_csv(os.path.join(here, "superstore.csv")),
                  index="Row ID")

    # Track the table with the name "data_source_one", which will be used in
    # the front-end to access the Table.
    MANAGER.host_table("data_source_one", TABLE)
    MANAGER.host_view("view_one", TABLE.view())

    return tornado.web.Application(
        [
            (r"/", MainHandler),
            # create a websocket endpoint that the client Javascript can access
            (r"/websocket", PerspectiveTornadoHandler, {
                "manager": MANAGER,
                "check_origin": True
            })
        ],
        websocket_ping_interval=15)
示例#9
0
 def test_manager_host_view(self):
     manager = PerspectiveManager()
     table = Table(data)
     view = table.view()
     manager.host_view("view1", view)
     assert manager.get_view("view1").to_dict() == data