Skip to content
Snippets Groups Projects
Commit 3ec073ab authored by imcovangent's avatar imcovangent
Browse files

Update on visualization package (removed unnecessary json files) - part I

Former-commit-id: 5a79baf0bf691175ed8b0fd314a5163747692f41
parent 25fb1ad4
No related branches found
No related tags found
No related merge requests found
Pipeline #192871 canceled
......@@ -22,8 +22,8 @@ logger = logging.getLogger(__name__)
class VispackMixin(object):
def export_d3js_files(self, MPG=None, order=None, destination_folder=None, open_files=False,
no_circleView_variables_data=False, reference_file=None, progress_path=None):
def export_d3js_files(self, MPG=None, order=None, destination_folder=None, open_files=False, reference_file=None,
progress_path=None):
"""
Function to automatically export the json files required to build the D3.js visualization of the graphs.
......@@ -36,8 +36,6 @@ class VispackMixin(object):
:type order: list
:param open_files: Boolean on whether the files should be opened after creation
:type open_files: bool
:param no_circleView_variables_data: setting on whether to create this file
:type no_circleView_variables_data: bool
:param reference_file: file from which reference values are extracted (either full path or file in same folder)
:type reference_file: file
:return: a collection of json files
......@@ -189,11 +187,9 @@ class VispackMixin(object):
# CREATE TOOLS_DATA JSON
# Create empty dictionary circleView_tools_data
print 'Creating circleView_tools_data.json and serviceView_tools_data.json ...'
print 'Creating circleView_tools_data.json ...'
circleView_tools_data = dict(attributes=dict(tools=full_graph['attributes']['tools'],
variables=full_graph['attributes']['variables']))
serviceView_tools_data = dict(attributes=dict(tools=full_graph['attributes']['tools'],
variables=full_graph['attributes']['variables']))
# Setting for percentual progress
n_keys = len(full_graph.keys())
......@@ -209,19 +205,12 @@ class VispackMixin(object):
if key is not 'attributes' and key is not coordinator_str:
if self.node[key]['category'] == 'variable':
input_tools = full_graph[key]
# extend serviceView_tools_data with tool outputs
# TODO: if-statements can be adjusted / optimized!
for input_tool in input_tools:
if input_tool not in serviceView_tools_data:
serviceView_tools_data[input_tool] = dict(name=input_tool, input=[], output=[key])
else:
serviceView_tools_data[input_tool]['output'] = extend_list_uniquely(
serviceView_tools_data[input_tool]['output'], [key])
# Create circleView_tools_data
for tool in full_graph['attributes']['tools']:
if key in full_graph[tool]:
if tool not in circleView_tools_data:
circleView_tools_data[tool] = dict(name=tool, input=[], pipeline_data=dict())
circleView_tools_data[tool] = dict(name=format_string_for_d3js(tool), input=[],
pipeline_data=dict())
# Add input tools
circleView_tools_data[tool]['input'] = extend_list_uniquely(
circleView_tools_data[tool]['input'], input_tools)
......@@ -234,8 +223,8 @@ class VispackMixin(object):
# Check if variable is also input to the coordinator
if key in full_graph[coordinator_str]:
if coordinator_str not in circleView_tools_data:
circleView_tools_data[coordinator_str] = dict(name=coordinator_str, input=[],
pipeline_data=dict())
circleView_tools_data[coordinator_str] = dict(name=format_string_for_d3js(coordinator_str),
input=[], pipeline_data=dict())
# Add input tools to coordinator
circleView_tools_data[coordinator_str]['input'] = extend_list_uniquely(
circleView_tools_data[coordinator_str]['input'], input_tools)
......@@ -247,17 +236,6 @@ class VispackMixin(object):
circleView_tools_data[coordinator_str]['pipeline_data'][input_tool], [key])
elif not self.node[key]['category'] == 'function':
raise NotImplementedError('Node category %s is not allowed.' % self.node[key]['category'])
if key is not 'attributes':
if key is coordinator_str:
if key not in serviceView_tools_data:
serviceView_tools_data[key] = dict(name=key, input=full_graph[key], output=[])
else:
serviceView_tools_data[key]['input'] = full_graph[key]
elif self.node[key]['category'] == 'function':
if key not in serviceView_tools_data:
serviceView_tools_data[key] = dict(name=key, input=full_graph[key], output=[])
else:
serviceView_tools_data[key]['input'] = full_graph[key]
# Export circleView_tools_data dictionary to list
circleView_tools_data_list = []
......@@ -272,64 +250,7 @@ class VispackMixin(object):
# Move and open json file
move_and_open(filename, destination_folder, open=open_files)
# Export serviceView_tools_data dictionary to list
serviceView_tools_data_list = []
for key in serviceView_tools_data.iterkeys():
if key is not 'attributes':
new_dict = serviceView_tools_data[key]
new_dict['type'] = 'function'
serviceView_tools_data_list.append(new_dict)
# Write json file
filename = 'serviceView_tools_data.json'
export_as_json(serviceView_tools_data_list, filename)
# Move and open json file
move_and_open(filename, destination_folder, open=open_files)
print 'Successfully created circleView_tools_data.json and serviceView_tools_data.json.'
# CREATE VARIABLES_DATA JSON
# Create empty dictionary circleView_variables_data
if not no_circleView_variables_data:
print 'Creating circleView_variables_data.json ...'
circleView_variables_data = dict(attributes=dict(tools=full_graph['attributes']['tools'],
variables=full_graph['attributes']['variables']))
for key in full_graph:
if key is not 'attributes' and key is not coordinator_str:
if self.node[key]['category'] == 'variable':
source_tools = full_graph[key]
circleView_variables_data[key] = dict(name=key, input=[], pipeline_data=dict())
for source_tool in source_tools:
if source_tool is not coordinator_str: # To avoid circular dependencies on system I/Os
input_of_source_tool = full_graph[source_tool]
# Add input variables
circleView_variables_data[key]['input'] = extend_list_uniquely(
circleView_variables_data[key]['input'], input_of_source_tool)
# Add pipeline data (tools present between these variables)
for input_variable in input_of_source_tool:
if input_variable not in circleView_variables_data[key]['pipeline_data']:
circleView_variables_data[key]['pipeline_data'][input_variable] = []
circleView_variables_data[key]['pipeline_data'][input_variable] = \
extend_list_uniquely(
circleView_variables_data[key]['pipeline_data'][input_variable], [source_tool])
elif not self.node[key]['category'] == 'function':
raise NotImplementedError('Node category %s is not allowed.' % self.node[key]['category'])
# Export circleView_variables_data dictionary to list
circleView_variables_data_list = []
for key in circleView_variables_data.iterkeys():
if key is not 'attributes':
circleView_variables_data_list.append(circleView_variables_data[key])
# Write json file
filename = 'circleView_variables_data.json'
export_as_json(circleView_variables_data_list, filename)
# Move and open json file
move_and_open(filename, destination_folder, open=open_files)
print 'Successfully created circleView_variables_data.json'
print 'Successfully created circleView_tools_data.json.'
# CREATE VARIABLE TREE BASED ON SCHEMA
print 'Creating variableTree_dataschema.json ...'
......@@ -570,9 +491,8 @@ class VispackMixin(object):
def create_visualization_package(self, vispack_folder, MPG=None, order=None, open_files=False,
no_circleView_variables_data=False, vispack_version=None,
reference_file=None, compress=False, remove_after_compress=True,
progress_path=None):
vispack_version=None, reference_file=None, compress=False,
remove_after_compress=True, progress_path=None):
"""
Function to automatically build the D3.js visualization package of the graphs.
......@@ -585,8 +505,6 @@ class VispackMixin(object):
:type order: list
:param open_files: Boolean on whether the files should be opened after creation
:type open_files: bool
:param no_circleView_variables_data: setting on whether to create this file
:type no_circleView_variables_data: bool
:param vispack_version: version of the visualization package to be used (as stored in the package itself)
:type vispack_version: basestring
:param reference_file: file from which reference values are extracted (either full path or file in same folder)
......@@ -626,7 +544,7 @@ class VispackMixin(object):
temp_d3js_folder = os.path.join(os.path.dirname(vispack_folder), 'temp_d3js_' + str(time.time()).replace('.', ''))
self.export_d3js_files(MPG=MPG, order=order,
destination_folder=temp_d3js_folder,
open_files=open_files, no_circleView_variables_data=no_circleView_variables_data,
open_files=open_files,
reference_file=reference_file, progress_path=progress_path)
# Create visualization package
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment