File size: 836 Bytes
9569e58 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
'''
- 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))
|