Fraser-Greenlee
viz
9569e58
raw
history blame
836 Bytes
'''
- parse the AST for every line of code
- add this to a graph of all possibly trees with frequency counts
- plot this tree
'''
import json
with open('visualise/trie.json', 'r') as f:
trie = json.load(f)
def flatten_children(root):
children = []
for name, vals in root.items():
if name[0] == ' ':
continue
rr = {'name': name, 'value': vals[' count']}
rr['children'] = flatten_children(vals)
if not rr['children']:
del rr['children']
children.append(rr)
tot = sum(child['value'] for child in children)
for child in children:
child['value'] = child['value'] / tot
return children
trie = {
"name": "Module",
"children": flatten_children(trie)
}
with open('visualise/trie.flat.json', 'w') as f:
f.write(json.dumps(trie))