-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenriching.py
28 lines (20 loc) · 1.03 KB
/
enriching.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
import json
def enrich_with_apparatus_rankings(results):
for category_name in results['categories'].keys():
category = results['categories'][category_name]
first_entity = category['general'][0][0]
if len(first_entity['apparatuses'].keys()) == 1:
continue
category['apparatuses'] = {}
for apparatus in first_entity['apparatuses'].keys():
entities = []
# put all the gymnasts in there
for rank in category['general']:
for entity in rank:
if apparatus in entity['apparatuses']:
entities.append(entity)
else:
print("/!\ Gymnast [%s] in category [%s] has been excluded from ranking with apparatus [%s] as she did not perform with it" % (entity["name"], category_name, apparatus))
entities.sort(key=lambda e: float(e['apparatuses'][apparatus]['total']), reverse=True)
category['apparatuses'][apparatus] = entities
return results