mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Show move methods in form-differences.py
This commit is contained in:
parent
04f1013981
commit
ce1e98d805
1 changed files with 38 additions and 12 deletions
|
@ -5,6 +5,8 @@
|
|||
This is not a one-shot script! It is probably unmaintained though.
|
||||
"""
|
||||
|
||||
import itertools
|
||||
|
||||
from pokedex.db import connect
|
||||
import pokedex.db.tables as t
|
||||
from sqlalchemy.orm import lazyload, joinedload, subqueryload
|
||||
|
@ -22,25 +24,32 @@ def getpokeathlon(stats):
|
|||
return dict((stat.pokeathlon_stat_id, (stat.minimum_stat, stat.base_stat, stat.maximum_stat)) for stat in stats)
|
||||
|
||||
def getitems(items):
|
||||
return list(sorted((item.version_id, item.item, item.rarity) for item in items))
|
||||
|
||||
def getmoves(moves):
|
||||
return list(sorted((move.version_group_id, move.move_id, move.pokemon_move_method_id, move.level, move.order) for move in moves))
|
||||
return sorted((item.version_id, item.item_id, item.rarity) for item in items)
|
||||
|
||||
def getform(form):
|
||||
return {
|
||||
'ability': form.pokemon.all_abilities,
|
||||
'items': getitems(form.pokemon.items),
|
||||
'moves': getmoves(form.pokemon.pokemon_moves),
|
||||
'pokeathlon': getpokeathlon(form.pokeathlon_stats),
|
||||
'stats': getstats(form.pokemon.stats),
|
||||
'effort': geteffort(form.pokemon.stats),
|
||||
'types': form.pokemon.types,
|
||||
'type': form.pokemon.types,
|
||||
'exp': form.pokemon.base_experience,
|
||||
'weight': form.pokemon.weight,
|
||||
'height': form.pokemon.height,
|
||||
}
|
||||
|
||||
def groupdict(it, key):
|
||||
"""Group an iterable by a key and return a dict."""
|
||||
|
||||
return dict((group_key, list(group)) for group_key, group in itertools.groupby(it, key))
|
||||
|
||||
def getmoves(form):
|
||||
all_moves = sorted((move.method.identifier, move.version_group_id, move.move_id, move.level, move.order) for move in form.pokemon.pokemon_moves)
|
||||
|
||||
return groupdict(all_moves, lambda x: x[0])
|
||||
|
||||
|
||||
def gcd(a, b):
|
||||
keys = set(a.keys()) & set(b.keys())
|
||||
result = {}
|
||||
|
@ -49,6 +58,14 @@ def gcd(a, b):
|
|||
result[k] = a[k]
|
||||
return result
|
||||
|
||||
def find_uncommon_keys(dicts):
|
||||
keys = set(dicts[0])
|
||||
|
||||
common_keys = set(reduce(gcd, dicts).keys())
|
||||
unique_keys = keys - common_keys
|
||||
|
||||
return unique_keys
|
||||
|
||||
q = session.query(t.PokemonSpecies)
|
||||
q = q.options(
|
||||
lazyload('default_pokemon'),
|
||||
|
@ -67,21 +84,30 @@ for species in q.all():
|
|||
.join(t.Pokemon)
|
||||
.filter(t.Pokemon.species_id==species.id)
|
||||
.options(
|
||||
subqueryload('pokeathlon_stats'),
|
||||
|
||||
joinedload('pokemon'),
|
||||
joinedload('pokemon.all_abilities'),
|
||||
joinedload('pokemon.items'),
|
||||
joinedload('pokemon.stats'),
|
||||
joinedload('pokemon.types'),
|
||||
joinedload('pokeathlon_stats'),
|
||||
joinedload('pokemon.pokemon_moves.method'),
|
||||
subqueryload('pokemon.stats'),
|
||||
subqueryload('pokemon.pokemon_moves'),
|
||||
|
||||
lazyload('pokemon.default_form'),
|
||||
lazyload('pokemon.forms'),
|
||||
lazyload('pokemon.items.item'),
|
||||
lazyload('pokemon.pokemon_moves.pokemon'),
|
||||
lazyload('pokemon.pokemon_moves.move'),
|
||||
lazyload('pokemon.species'),
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
keys = set(getform(forms[0]).keys())
|
||||
common_keys = set(reduce(gcd, map(getform, forms)).keys())
|
||||
unique_keys = keys - common_keys
|
||||
uncommon = sorted(find_uncommon_keys(map(getform, forms)))
|
||||
uncommon_moves = sorted(find_uncommon_keys(map(getmoves, forms)))
|
||||
|
||||
print "{}: {}".format(species.name, ", ".join(sorted(unique_keys)))
|
||||
if uncommon_moves:
|
||||
uncommon.append("moves ({})".format(", ".join(sorted(uncommon_moves))))
|
||||
|
||||
print "{}: {}".format(species.name, ", ".join(uncommon))
|
||||
|
|
Loading…
Reference in a new issue