forked from AliShug/musicleague-scraper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess.py
49 lines (44 loc) · 1.57 KB
/
process.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
40
41
42
43
44
45
46
47
48
49
def kinda_next(x):
try:
return next(x)
except:
return None
def process(data):
players = []
for round in data:
for song in round['songs']:
submitter = song['submitter']
if not submitter in players:
players.append(submitter)
print("round;", "submitter;", "song;", ";".join(players))
for i, round in enumerate(data):
# Sort by players
songs = round['songs']
songs = [kinda_next(song for song in songs if song['submitter'] == player) for player in players]
for song_i, (song, submitter) in enumerate(zip(songs, players)):
round_name = round['name']
tab = ';'
if song is None:
song_name = '~No submission~😭'
votes = [0 for player in players]
else:
song_name = song['name']
votes = [song['votes'].get(player, 0) for player in players]
print(f'{round_name if song_i == 0 else ""};{submitter};"{song_name}";{tab.join([str(vote) for vote in votes])}')
if __name__=='__main__':
import json
with open('data.json', 'r') as f:
data = json.load(f)
process(data)
# import matplotlib.pyplot as plt
# import numpy as np
# poi = 'Someone'
# vote_totals = np.array([0]*len(players))
# for songs in data:
# for song in songs:
# if song['submitter'] == poi:
# votes = [song['votes'].get(player, 0) for player in players]
# vote_totals += votes
# plt.bar(players, vote_totals)
# plt.title(f'Votes for {poi}')
# plt.show()