-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_pokepastes.py
52 lines (43 loc) · 1.79 KB
/
parse_pokepastes.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
50
51
52
import collections
import json
from showdown_replay_analyzer import pokepaste
pokepastes = []
def main():
pokemon_stats = {}
for paste in pokepastes:
team = pokepaste.parse_pokepaste(paste)
for p in team.pokemon:
if p.species not in pokemon_stats:
pokemon_stats[p.species] = {
'count': 0,
'ability': collections.Counter(),
'item': collections.Counter(),
'moves': {},
'tera': collections.Counter(),
}
pokemon = pokemon_stats[p.species]
pokemon['count'] += 1
for move in p.moves:
if move.name not in pokemon['moves']:
pokemon['moves'][move.name] = 0
pokemon['moves'][move.name] += 1
pokemon['tera'][p.tera_type] += 1
pokemon['ability'][p.ability] += 1
pokemon['item'][p.item] += 1
print('[', end='')
for i, x in enumerate(sorted(list(pokemon_stats.items()),
key=lambda x: x[1]['count'],
reverse=True)):
print('{', end='')
print(f'"species": "{x[0]}",', end='')
print(f'"count": {x[1]['count']},', end='')
print(f'"ability": {json.dumps(_sort_dict(x[1]['ability']))},', end='')
print(f'"item": {json.dumps(_sort_dict(x[1]['item']))},', end='')
print(f'"moves": {json.dumps(_sort_dict(x[1]['moves']))},', end='')
print(f'"tera": {json.dumps(_sort_dict(x[1]['tera']))}', end='')
print(f'}}{'' if i == len(pokemon_stats.keys()) - 1 else ','}', end='')
print(']')
def _sort_dict(d):
return dict(sorted(d.items(), key=lambda item: (-item[1], item[0])))
if __name__ == '__main__':
main()