-
Notifications
You must be signed in to change notification settings - Fork 4
/
tool-count.py
39 lines (29 loc) · 978 Bytes
/
tool-count.py
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
39
import json
import sys
try:
data = json.load(sys.stdin)
except ValueError:
print('galaxy.tools,server="%s" count=%s,uniq=%s' % (sys.argv[1], 0, 0))
sys.exit(0)
seen_before = {}
def process_elems(elems, section=None):
for e in elems:
if e['model_class'] == 'ToolSection':
for x in process_elems(e['elems'], section=e['name']):
yield x
elif e['model_class'][-4:] == 'Tool':
i = e['id'].split('/')
yield '/'.join(i)
if len(i) > 2:
i = '%s/%s' % (i[2], i[3])
else:
i = e['id']
n = '%s|%s' % (i, e['name'])
if n not in seen_before:
seen_before[n] = []
seen_before[n].append(section)
data = list(process_elems(data))
tools = list(data)
uniq_tools = set(tools)
print('galaxy.tools,server="%s" count=%s,uniq=%s' %
(sys.argv[1].replace(' ', '\\ '), len(tools), len(uniq_tools)))