Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated io tree response to add link type information #2033

Merged
merged 5 commits into from
Oct 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 69 additions & 46 deletions aiida/restapi/translator/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,77 +573,100 @@ def get_node_shape(ntype):
qb = QueryBuilder()
qb.append(Node, tag="main", project=['*'],
filters=self._id_filter)
qb.append(Node, tag="in", project=['*'], edge_project=['label'],
qb.append(Node, tag="in", project=['*'], edge_project=['label', 'type'],
input_of='main')

input_node_pks = {}

if qb.count() > 0:
for input in qb.iterdict():
node = input['in']['*']
linktype = input['main--in']['label']
pk = node.pk
uuid = node.uuid
nodetype = node.type
display_type = nodetype.split('.')[-2]
description = node.get_desc()
if description == '':
description = node.type.split('.')[-2]

nodes.append({
"id": nodeCount,
"nodeid": pk,
"nodeuuid": uuid,
"nodetype": nodetype,
"displaytype": display_type,
"group": "inputs",
"description": description,
"linktype": linktype,
"shape": get_node_shape(nodetype)
})
linklabel = input['main--in']['label']
linktype = input['main--in']['type']

# add node if it is not present
if pk not in input_node_pks.keys():
input_node_pks[pk] = nodeCount
uuid = node.uuid
nodetype = node.type
display_type = nodetype.split('.')[-2]
description = node.get_desc()
if description == '':
description = node.type.split('.')[-2]

nodes.append({
"id": nodeCount,
"nodeid": pk,
"nodeuuid": uuid,
"nodetype": nodetype,
"displaytype": display_type,
"group": "inputs",
"description": description,
"linklabel": linklabel,
"linktype": linktype,
"shape": get_node_shape(nodetype)
})
nodeCount += 1

from_edge = input_node_pks[pk]
edges.append({
"from": nodeCount,
"from": from_edge,
"to": 0,
"arrows": "to",
"color": {"inherit": 'from'},
"linktype": linktype,
"label": linktype,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linklabel should be moved here from nodes, and this should remain to be called linktype

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'label' is the name used by JS library to display value on edge. This endpoint is specifically written for materials cloud and passes the data in format used in MC. Otherwise we can reprocess the data completely in frontend again before passing it to the visualization library.

})
nodeCount += 1


# get all outputs
qb = QueryBuilder()
qb.append(Node, tag="main", project=['*'],
filters=self._id_filter)
qb.append(Node, tag="out", project=['*'], edge_project=['label'],
qb.append(Node, tag="out", project=['*'], edge_project=['label', 'type'],
output_of='main')

output_node_pks = {}

if qb.count() > 0:
for output in qb.iterdict():
node = output['out']['*']
linktype = output['main--out']['label']
pk = node.pk
uuid = node.uuid
nodetype = node.type
display_type = nodetype.split('.')[-2]
description = node.get_desc()
if description == '':
description = node.type.split('.')[-2]

nodes.append({
"id": nodeCount,
"nodeid": pk,
"nodeuuid": uuid,
"nodetype": nodetype,
"displaytype": display_type,
"group": "outputs",
"description": description,
"linktype": linktype,
"shape": get_node_shape(nodetype)
})
linklabel = output['main--out']['label']
linktype = output['main--out']['type']

# add node if it is not present
if pk not in output_node_pks.keys():
output_node_pks[pk] = nodeCount
uuid = node.uuid
nodetype = node.type
display_type = nodetype.split('.')[-2]
description = node.get_desc()
if description == '':
description = node.type.split('.')[-2]

nodes.append({
"id": nodeCount,
"nodeid": pk,
"nodeuuid": uuid,
"nodetype": nodetype,
"displaytype": display_type,
"group": "outputs",
"description": description,
"linklabel": linklabel,
"linktype": linktype,
"shape": get_node_shape(nodetype)
})
nodeCount += 1

to_edge = output_node_pks[pk]
edges.append({
"from": 0,
"to": nodeCount,
"to": to_edge,
"arrows": "to",
"color": {"inherit": 'to'},
"linktype": linktype
"label": linktype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

})
nodeCount += 1


return {"nodes": nodes, "edges": edges}