-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
50 lines (38 loc) · 1.36 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import tornado.ioloop
import tornado.web
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static"),
"template_path": os.path.join(os.path.dirname(__file__), "templates"),
"debug": True
}
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("main.html")
class VisHandler(tornado.web.RequestHandler):
def get(self):
template = self.request.path[1:] + ".html"
self.render(template)
class DataHandler(tornado.web.RequestHandler):
def get(self):
data_filename = self.request.path.split("/")[-1]
data_filepath = os.path.join(settings["static_path"], data_filename)
data_file = open(data_filepath, 'r')
data = data_file.read()
self.write(data)
data_file.close()
class PlotHandler(tornado.web.RequestHandler):
def get(self):
data_filepath = os.path.join(settings["static_path"], "regression")
plots = os.listdir(data_filepath)
plots = [os.path.join(data_filepath, plot) for plot in plots]
self.render("plots.html", plots=plots)
application = tornado.web.Application([
(r"/", MainHandler),
(r"/plots", PlotHandler),
(r"/data/.+\.json", DataHandler),
(r"/.+", VisHandler)
], **settings)
if __name__ == "__main__":
application.listen(8080)
tornado.ioloop.IOLoop.instance().start()