Skip to content
Browse files

Made a testing query which generates a random sequence, formated to be

copmatible with Rickshaw.
  • Loading branch information...
1 parent 317cc83 commit 074394321259ba4fc7a054ff6dfc9fc9f1f29a1c @vals committed May 10, 2012
Showing with 35 additions and 16 deletions.
  1. +35 −16 status_app.py
View
51 status_app.py
@@ -10,6 +10,8 @@
from couchdb import Server
import yaml
+import random
+
PORT = 9999
@@ -22,36 +24,45 @@ class MainHandler(tornado.web.RequestHandler):
def get(self):
# Send our main document
- self.render("index.html")
+ self.render("/Users/vale/html/ajax.html")
class DataHandler(tornado.web.RequestHandler):
- def get(self):
- dates_and_sizes = []
- for i in self.application.illumina_db.view("status/final_sizes_tmp", group_level=1):
- dates_and_sizes.append({"time": dateutil.parser.parse(i.value[0]), "size": i.value[1]})
- dates_and_sizes = sorted(dates_and_sizes, key=lambda entry: entry["time"])
+ def options(self):
+ self.set_header('Access-Control-Allow-Origin', '*')
+ self.set_header('Access-Control-Allow-Methods', 'GET', 'OPTIONS')
+
+ def get(self, q1, q2):
+ # dates_and_sizes = []
+ # for i in self.application.illumina_db.view("status/final_sizes_tmp", group_level=1):
+ # dates_and_sizes.append({"time": dateutil.parser.parse(i.value[0]), "size": i.value[1]})
+ # dates_and_sizes = sorted(dates_and_sizes, key=lambda entry: entry["time"])
self.set_header("Content-type", "application/json")
- print(self.application.illumina_db)
+ # print(self.application.illumina_db)
+
+ if q1 == "test":
+ self.write(json.dumps(self.random_series(int(q2)), default=dthandler))
+
+ else:
+ # self.write(json.dumps(dates_and_sizes, default=dthandler))
+ self.write(json.dumps((q1, q2), default=dthandler))
- self.write(json.dumps(dates_and_sizes, default=dthandler))
+ def random_series(self, n):
+ s = [{"y":random.randint(10, 99), "x":i} for i in xrange(int(n))]
+ d = dict()
+ d["data"] = s
+ d["name"] = "series"
+ return [d]
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", MainHandler),
- (r"/data.json", DataHandler),
+ ("/data/(\w+)?/(\w+)?", DataHandler)
]
- # Setup the Tornado Application
- settings = {
- "debug": True,
- "static_path": os.path.join(os.path.dirname(__file__), "static")
- }
-
- tornado.web.Application.__init__(self, handlers, **settings)
with open("settings.yaml") as settings_file:
server_settings = yaml.load(settings_file)
@@ -60,6 +71,14 @@ def __init__(self):
couch = Server(server_settings["couch_server"])
self.illumina_db = couch["illumina_logs"]
+ # Setup the Tornado Application
+ settings = {
+ "debug": True,
+ "static_path": server_settings["static_path"]
+ }
+
+ tornado.web.Application.__init__(self, handlers, **settings)
+
def main():
# Instantiate Application

0 comments on commit 0743943

Please sign in to comment.
Something went wrong with that request. Please try again.