1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-22 19:22:29 +00:00

Script options

This commit is contained in:
Tasio Mendez 2018-02-05 12:47:56 +01:00
parent c2d1e0d4f2
commit 3383318fea
2 changed files with 26 additions and 15 deletions

18
run.py
View File

@ -1,15 +1,23 @@
import argparse
from server import ModularServer
from visualization import GraphVisualization, Model
def run(model, params=None):
def run(model, name="SOIL Model", verbose=False, params=None):
graphVisualization = GraphVisualization(params)
server = ModularServer(model, graphVisualization, name="SOIL Model")
server = ModularServer(model, graphVisualization, name=(name[0] if isinstance(name, list) else name), verbose=verbose)
server.port = 8001
server.launch()
if __name__ == "__main__":
soil = Model(dump=False)
run(soil)
parser = argparse.ArgumentParser(description='Visualization of a Graph Model')
parser.add_argument('--name', '-n', nargs=1, default='SOIL Model', help='name of the simulation')
parser.add_argument('--dump', '-d', help='dumping results in folder output', action='store_true')
parser.add_argument('--verbose', '-v', help='verbose mode', action='store_true')
args = parser.parse_args()
soil = Model(dump=args.dump)
run(soil, name=args.name, verbose=args.verbose)

View File

@ -1,19 +1,17 @@
import io
import logging
import networkx as nx
import os
import threading
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.escape
import tornado.gen
import webbrowser
import yaml
import logging
import threading
import io
import networkx as nx
from time import sleep
import webbrowser
from contextlib import contextmanager
from time import sleep
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
@ -56,6 +54,7 @@ class PageHandler(tornado.web.RequestHandler):
class SocketHandler(tornado.websocket.WebSocketHandler):
""" Handler for websocket. """
def open(self):
if self.application.verbose:
@ -116,6 +115,9 @@ class SocketHandler(tornado.websocket.WebSocketHandler):
'data': self.get_trial( int(msg['data'] )) })
elif msg['type'] == 'run_simulation':
if self.application.verbose:
logger.info('Running new simulation for {name}'.format(name=self.config['name']))
print(msg['data'])
self.send_log('INFO.soil', 'Running new simulation for {name}'.format(name=self.config['name']))
self.config['environment_params'] = msg['data']
self.run_simulation()
@ -137,6 +139,7 @@ class SocketHandler(tornado.websocket.WebSocketHandler):
thread.start()
def on_close(self):
if self.application.verbose:
logger.info('Socket closed!')
def send_log(self, logger, logging):
@ -229,5 +232,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()