Skip to content
Permalink
Browse files
Fixed bug in sankey
  • Loading branch information
michellebeard committed Aug 7, 2017
1 parent 7e6d714 commit d4f5f00e3823708f7ab350fc6cd88aafc055b05a
Showing 1 changed file with 12 additions and 8 deletions.
@@ -234,8 +234,9 @@ def generate_graph(app,
newSessions.append(pairs)

# Node Map
node_map = [] # Need to keep 0based index for sankey diagram
node_list = [] # Need to keep 0-based index for sankey diagram
links = [] # Aggregate sequence list
node_map = [] # Final node map {"name": "foo", "id": 0"}

# Align the sequences
alignment = itertools.izip_longest(*newSessions)
@@ -277,16 +278,19 @@ def generate_graph(app,

# How many users visited a sequence at this step
counts = collections.Counter(k['sequenceID'] for k in visitedLinks if k.get('sequenceID'))
# print(counts)
# Append into growing node_list
map(lambda x: node_list.append(x), nodenames)

# Append into growing nodeMap
map(lambda x: node_map.append(x), nodenames)
map(lambda x: node_map.append({ "name": x,
"id": len(node_list) - 1 - node_list[::-1].index(x)}), nodenames)

for v in visitedLinks:
# Pass through and update count, also generate src and target id
v['value'] = c[v['sequenceID']]
v['value'] = counts[v['sequenceID']]
# Last occurence is the src and target id
v['sourceID'] = len(node_map) -1 - node_map[::-1].index(v['sourceName'])
v['targetID'] = len(node_map) -1 - node_map[::-1].index(v['targetName'])
v['source'] = len(node_list) -1 - node_list[::-1].index(v['sourceName'])
v['target'] = len(node_list) -1 - node_list[::-1].index(v['targetName'])
links.append(v)

# Save everything
@@ -297,8 +301,8 @@ def generate_graph(app,
'nodes': node_map
}

# with open('sankey.json', 'w') as outfile:
# json.dump(res, outfile, indent=4, sort_keys=False)
with open('sankey.json', 'w') as outfile:
json.dump(res, outfile, sort_keys=False)

# with open('data.txt', 'w') as outfile:
# json.dump(intervalSessions, outfile, indent=4, sort_keys=False)

0 comments on commit d4f5f00

Please sign in to comment.