Exemplo n.º 1
0
def make_app():
    """Create a `PerspectiveManager` and host our tables and views so they
    can be accessed over a Websocket."""
    MANAGER = perspective.PerspectiveManager()

    # Seed the initial holdings table
    TABLES["holdings"].update({
        "symbol":
        symbols,
        "quantity": [holdings[symbol] for symbol in symbols],
    })

    # Set up the on_update callbacks
    def update_total(port, delta):
        """When the indexed table updates with the latest price, update the
        unindexed table with the rows that changed."""
        TABLES["holdings_total"].update(delta)

    VIEWS["holdings"].on_update(update_total, mode="row")

    def update_holdings(port, delta):
        TABLES["holdings"].update(delta)

    VIEWS["quotes"].on_update(update_holdings, mode="row")

    MANAGER.host_table("holdings_table", TABLES["holdings"])
    MANAGER.host_view("holdings_view", VIEWS["holdings"])

    MANAGER.host_table("holdings_total_table", TABLES["holdings_total"])
    MANAGER.host_view("holdings_total_view", VIEWS["holdings_total"])

    MANAGER.host_table("quotes_table", TABLES["quotes"])
    MANAGER.host_view("quotes_view", VIEWS["quotes"])

    MANAGER.host_table("charts_table", TABLES["charts"])
    MANAGER.host_view("charts_view", VIEWS["charts"])

    return tornado.web.Application([
        # create a websocket endpoint that the client Javascript can access
        (
            r"/websocket",
            perspective.PerspectiveTornadoHandler,
            {
                "manager": MANAGER,
                "check_origin": True
            },
        ),
        (r"/", MainHandler),
    ])
Exemplo n.º 2
0
def server(queue, is_async):
    """Start a server, within this process."""
    manager = perspective.PerspectiveManager()
    table = get_table()
    manager.host_table("data_source_one", table)

    if is_async:
        thread = threading.Thread(target=perspective_thread, args=(manager, ))
        thread.daemon = True
        thread.start()

    loop = tornado.ioloop.IOLoop.current()
    loop.add_callback(queue.put, True)
    if not is_async:
        manager.set_loop_callback(loop.add_callback)

    make_app(manager)
    loop.start()
Exemplo n.º 3
0
                'port_number' : port_number,
            }
            with open (BASE_DIR + "\port-data.json", 'w') as fp:
                json.dump(port_data, fp)
        else:
            port_number = 8888
            port_data = {
                'port_number' : port_number,
            }
            with open (BASE_DIR + "\port-data.json", 'w') as fp:
                json.dump(port_data, fp)

    except:
        port_number = 8888
        port_data = {
                'port_number' : port_number,
            }
            with open (BASE_DIR + "\port-data.json", 'w') as fp:
                json.dump(port_data, fp)
        app.listen(port_number)
    print("Listening on http://localhost:", port_number)
    loop = tornado.ioloop.IOLoop.current()
    loop.start()

if __name__ == "__main__":
    with qpython.qconnection.QConnection("localhost", 5000) as conn:
        manager = perspective.PerspectiveManager()
        start_server(manager = manager, qconn = conn)
   
    
Exemplo n.º 4
0
PARSER.add_argument(
    "--latest",
    dest="latest",
    default=False,
    type=bool,
    help=
    "Whether to find the newest folder of results, or use the exact results path.",
)

PARSER.add_argument(
    "results_path",
    help=
    "A path to a folder containing test results stored as Arrows. If --latest is True, the script will find the newest created folder of results.",
)

MANAGER = perspective.PerspectiveManager()


class MainHandler(tornado.web.RequestHandler):
    def set_default_headers(self):
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "x-requested-with")
        self.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")

    def get(self):
        self.render("results.html")


def make_results_table(results_path):
    """Given a path to a folder containing Arrow files, create a Perspective
    Table from the first arrow and update with the rest. This allows us to