mirror of
https://github.com/gsi-upm/soil
synced 2024-11-22 19:22:29 +00:00
Script options
This commit is contained in:
parent
c2d1e0d4f2
commit
3383318fea
18
run.py
18
run.py
@ -1,15 +1,23 @@
|
|||||||
|
import argparse
|
||||||
from server import ModularServer
|
from server import ModularServer
|
||||||
from visualization import GraphVisualization, Model
|
from visualization import GraphVisualization, Model
|
||||||
|
|
||||||
|
|
||||||
def run(model, params=None):
|
def run(model, name="SOIL Model", verbose=False, params=None):
|
||||||
graphVisualization = GraphVisualization(params)
|
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.port = 8001
|
||||||
server.launch()
|
server.launch()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
||||||
|
23
server.py
23
server.py
@ -1,19 +1,17 @@
|
|||||||
|
import io
|
||||||
|
import logging
|
||||||
|
import networkx as nx
|
||||||
import os
|
import os
|
||||||
|
import threading
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.websocket
|
import tornado.websocket
|
||||||
import tornado.escape
|
import tornado.escape
|
||||||
import tornado.gen
|
import tornado.gen
|
||||||
import webbrowser
|
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
import webbrowser
|
||||||
|
|
||||||
import threading
|
|
||||||
import io
|
|
||||||
import networkx as nx
|
|
||||||
from time import sleep
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
@ -56,6 +54,7 @@ class PageHandler(tornado.web.RequestHandler):
|
|||||||
|
|
||||||
|
|
||||||
class SocketHandler(tornado.websocket.WebSocketHandler):
|
class SocketHandler(tornado.websocket.WebSocketHandler):
|
||||||
|
""" Handler for websocket. """
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if self.application.verbose:
|
if self.application.verbose:
|
||||||
@ -116,6 +115,9 @@ class SocketHandler(tornado.websocket.WebSocketHandler):
|
|||||||
'data': self.get_trial( int(msg['data'] )) })
|
'data': self.get_trial( int(msg['data'] )) })
|
||||||
|
|
||||||
elif msg['type'] == 'run_simulation':
|
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.send_log('INFO.soil', 'Running new simulation for {name}'.format(name=self.config['name']))
|
||||||
self.config['environment_params'] = msg['data']
|
self.config['environment_params'] = msg['data']
|
||||||
self.run_simulation()
|
self.run_simulation()
|
||||||
@ -137,7 +139,8 @@ class SocketHandler(tornado.websocket.WebSocketHandler):
|
|||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
logger.info('Socket closed!')
|
if self.application.verbose:
|
||||||
|
logger.info('Socket closed!')
|
||||||
|
|
||||||
def send_log(self, logger, logging):
|
def send_log(self, logger, logging):
|
||||||
self.write_message({'type': 'log',
|
self.write_message({'type': 'log',
|
||||||
@ -229,5 +232,5 @@ class ModularServer(tornado.web.Application):
|
|||||||
url = 'http://127.0.0.1:{PORT}'.format(PORT=self.port)
|
url = 'http://127.0.0.1:{PORT}'.format(PORT=self.port)
|
||||||
print('Interface starting at {url}'.format(url=url))
|
print('Interface starting at {url}'.format(url=url))
|
||||||
self.listen(self.port)
|
self.listen(self.port)
|
||||||
# webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
|
Loading…
Reference in New Issue
Block a user