From 563587193a06ed33f99f9b3a037a0243c0911f3e Mon Sep 17 00:00:00 2001 From: Tasio Mendez Date: Thu, 12 Apr 2018 18:00:44 +0200 Subject: [PATCH] Download results --- server.py | 25 ++++++++++++++++++++++++- templates/index.html | 29 +++++++++++++++++++++++++++-- templates/js/socket.js | 35 ++++++++++++++++++++++++++++++++++- templates/js/visualization.js | 2 +- visualization.py | 12 ++++++------ 5 files changed, 92 insertions(+), 11 deletions(-) diff --git a/server.py b/server.py index 254f68f..cc50e5c 100644 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ import yaml import webbrowser from contextlib import contextmanager from time import sleep +from xml.etree.ElementTree import tostring logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -118,7 +119,7 @@ class SocketHandler(tornado.websocket.WebSocketHandler): 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.get_trial( int(msg['data'] )) }) + 'data': self.get_trial( int(msg['data']) ) }) elif msg['type'] == 'run_simulation': if self.application.verbose: @@ -127,6 +128,28 @@ class SocketHandler(tornado.websocket.WebSocketHandler): self.config['environment_params'] = msg['data'] self.run_simulation() + elif msg['type'] == 'download_gexf': + G = self.simulation[ int(msg['data']) ].history_to_graph() + for node in G.nodes(): + if 'pos' in G.node[node]: + G.node[node]['viz'] = {"position": {"x": G.node[node]['pos'][0], "y": G.node[node]['pos'][1], "z": 0.0}} + del (G.node[node]['pos']) + writer = nx.readwrite.gexf.GEXFWriter(version='1.2draft') + writer.add_graph(G) + self.write_message({'type': 'download_gexf', + 'filename': self.config['name'] + '_trial_' + str(msg['data']), + 'data': tostring(writer.xml).decode(writer.encoding) }) + + elif msg['type'] == 'download_json': + G = self.simulation[ int(msg['data']) ].history_to_graph() + for node in G.nodes(): + if 'pos' in G.node[node]: + G.node[node]['viz'] = {"position": {"x": G.node[node]['pos'][0], "y": G.node[node]['pos'][1], "z": 0.0}} + del (G.node[node]['pos']) + self.write_message({'type': 'download_json', + 'filename': self.config['name'] + '_trial_' + str(msg['data']), + 'data': nx.node_link_data(G) }) + else: if self.application.verbose: logger.info('Unexpected message!') diff --git a/templates/index.html b/templates/index.html index 6bac09a..201e54f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -197,6 +197,7 @@