-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmost_frequent_blocks.py
More file actions
34 lines (27 loc) · 1.11 KB
/
most_frequent_blocks.py
File metadata and controls
34 lines (27 loc) · 1.11 KB
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
import sys
from os import walk
import json
from collections import defaultdict, OrderedDict
import string
d = defaultdict(int)
ordered = OrderedDict()
characters = string.ascii_letters + string.punctuation + string.digits
characters += "€£ñÑçÇáÁéÉíÍóÓúÚäÄëËïÏöÖüÜàÀèÈìÌòÒùÙâÂêÊîÎôÔûÛ¶§©ŠØ®ГДЕЖИЛśĥčýÿў±žПШΘЯбψξλσαβδ"
mypath = sys.argv[1]
_, _, filenames = next(walk(mypath))
for filename in filenames:
json_project = json.loads(open(mypath + filename).read())
# Loops through all sprites
for sprites_dict in json_project["targets"]:
sprite = sprites_dict["name"]
# Gets all blocks out of sprite
for blocks, blocks_value in sprites_dict["blocks"].items():
try:
d[blocks_value['opcode']] += 1
except TypeError:
pass
most_frequent = sorted(d.items(), key=lambda kv: kv[1], reverse=True)
for block, frequency in most_frequent:
ordered[block] = characters[len(ordered)]
with open('blocks.json', 'w') as outfile:
json.dump(dict(ordered), outfile, indent=4)