diff --git a/run.py b/run.py index dd3abdd..7d57b95 100644 --- a/run.py +++ b/run.py @@ -11,5 +11,5 @@ def run(model, params=None): if __name__ == "__main__": - soil = Model(dump=False) + soil = Model(dump=True) run(soil) diff --git a/server.py b/server.py index 7ca841c..dd2cc4c 100644 --- a/server.py +++ b/server.py @@ -9,6 +9,12 @@ import webbrowser import yaml import logging +import logging +import threading +import io +from datetime import timedelta +from contextlib import contextmanager + logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -54,6 +60,7 @@ class SocketHandler(tornado.websocket.WebSocketHandler): def open(self): if self.application.verbose: logger.info('Socket opened!') + def check_origin(self, origin): return True @@ -79,9 +86,12 @@ class SocketHandler(tornado.websocket.WebSocketHandler): return else: config = config[0] + self.send_log('INFO.soil', 'Using config: {name}'.format(name=config['name'])) self.name = config['name'] - self.application.model.run(config) + + with self.logging(self.application.model.name): + self.application.model.run(config) trials = [] for i in range(config['num_trials']): @@ -92,6 +102,7 @@ class SocketHandler(tornado.websocket.WebSocketHandler): elif msg['type'] == 'get_trial': if self.application.verbose: logger.info('Trial {} requested!'.format(msg['data'])) + self.send_log('INFO.user', 'Trial {} requested!'.format(msg['data'])) self.write_message({'type': 'get_trial', 'data': self.application.model.get_trial(self.name, msg['data']) }) @@ -99,6 +110,41 @@ class SocketHandler(tornado.websocket.WebSocketHandler): if self.application.verbose: logger.info('Unexpected message!') + def update_logging(self): + try: + if (not self.log_capture_string.closed and self.log_capture_string.getvalue()): + self.send_log('INFO.soil', self.log_capture_string.getvalue()) + self.log_capture_string.truncate(0) + self.log_capture_string.seek(0) + finally: + if self.capture_logging: + thread = threading.Timer(0.01, self.update_logging) + thread.start() + + def on_close(self): + logger.info('Socket closed!') + + def send_log(self, logger, logging): + self.write_message({'type': 'log', + 'logger': logger, + 'logging': logging }) + + @contextmanager + def logging(self, logger): + self.capture_logging = True + self.logger_application = logging.getLogger(logger) + self.log_capture_string = io.StringIO() + ch = logging.StreamHandler(self.log_capture_string) + self.logger_application.addHandler(ch) + self.update_logging() + yield self.capture_logging + + self.capture_logging = False + self.log_capture_string.close() + self.logger_application.removeHandler(ch) + return self.capture_logging + + class ModularServer(tornado.web.Application): """ Main visualization application. """ @@ -110,7 +156,6 @@ class ModularServer(tornado.web.Application): page_handler = (r'/', PageHandler) socket_handler = (r'/ws', SocketHandler) static_handler = (r'/(.*)', tornado.web.StaticFileHandler, - # {'path': os.path.dirname(__file__)}) {'path': 'templates'}) local_handler = (r'/local/(.*)', tornado.web.StaticFileHandler, {'path': ''}) @@ -133,7 +178,6 @@ class ModularServer(tornado.web.Application): self.model = model self.model_args = args self.model_kwargs = kwargs - #self.reset_model() # Initializing the application itself: @@ -155,5 +199,5 @@ class ModularServer(tornado.web.Application): url = 'http://127.0.0.1:{PORT}'.format(PORT=self.port) print('Interface starting at {url}'.format(url=url)) self.listen(self.port) - webbrowser.open(url) + # webbrowser.open(url) tornado.ioloop.IOLoop.instance().start() diff --git a/templates/css/main.css b/templates/css/main.css index 75abcee..2e08cce 100644 --- a/templates/css/main.css +++ b/templates/css/main.css @@ -1,4 +1,20 @@ +html, body, .carousel-inner { + height: 100%; +} + +.carousel { + height: calc(100% - 150px); +} + +.carousel-indicators li { + border-color: black; +} + +.carousel-indicators li.active { + background-color: black; +} + .node { stroke: #fff; stroke-width: 1.5px; @@ -236,3 +252,42 @@ table#link-distance .min, table#link-distance .max { font-weight: normal !important; } + +/* Console */ + +#update, .console { + padding: 10px 15px; + height: 135px; + border: 1px solid #585858; +} + +#update { + border-top-right-radius: 5px; + border-bottom-right-radius: 5px; +} + +.container-fluid.fixed { + padding-top: 15px; +} + +.console { + background-color: rgb(88,88,88); + font-family: "Ubuntu Mono"; + font-size: 14px; + font-weight: 500; + color: white; + line-height: 14px; + overflow: auto; + border-top-left-radius: 5px; + border-bottom-left-radius: 5px; +} + +.console::-webkit-scrollbar { + width: 6px; + background-color: #F5F5F5; +} + +.console::-webkit-scrollbar-thumb { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); + background-color: #555; +} diff --git a/templates/index.html b/templates/index.html index 860177d..428ee62 100644 --- a/templates/index.html +++ b/templates/index.html @@ -28,13 +28,14 @@ +
min | -Link Distance | -max | -
---|