1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-14 15:32:29 +00:00
soil/visualization.py

51 lines
1.4 KiB
Python
Raw Normal View History

2017-12-15 16:59:50 +00:00
import os
2018-04-10 16:26:24 +00:00
import networkx as nx
2017-12-15 16:59:50 +00:00
from server import VisualizationElement
from soil.simulation import SoilSimulation
from xml.etree import ElementTree
class Model():
2018-02-02 14:01:17 +00:00
def __init__(self, dump=False, dir_path='output'):
2018-02-01 18:37:10 +00:00
self.name = 'soil'
self.dump = dump
self.dir_path = dir_path
2018-02-02 14:01:17 +00:00
self.simulation = list()
2017-12-15 16:59:50 +00:00
2018-02-01 18:37:10 +00:00
def run(self, config):
name = config['name']
print('Using config(s): {name}'.format(name=name))
2017-12-15 16:59:50 +00:00
2018-02-01 18:37:10 +00:00
sim = SoilSimulation(**config)
sim.dir_path = os.path.join(self.dir_path, name)
sim.dump = self.dump
2017-12-15 16:59:50 +00:00
2018-02-01 18:37:10 +00:00
print('Dumping results to {} : {}'.format(sim.dir_path, sim.dump))
2018-04-10 16:26:24 +00:00
simulation_results = sim.run_simulation()
G = simulation_results[0].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'])
nx.write_gexf(G, 'test.gexf', version='1.2draft')
return simulation_results
2017-12-15 16:59:50 +00:00
2018-02-01 18:37:10 +00:00
def reset(self):
pass
2017-12-15 16:59:50 +00:00
class GraphVisualization(VisualizationElement):
2018-02-01 18:37:10 +00:00
package_includes = []
2017-12-15 16:59:50 +00:00
2018-02-01 18:37:10 +00:00
# TODO: esta por definir todos los ajustes de simulacion
def __init__(self, params=None):
new_element = ("new funcion()")
self.js_code = "elements.push(" + new_element + ");"
2017-12-15 16:59:50 +00:00
2018-02-01 18:37:10 +00:00
def render(self, model):
pass