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.
|
This is not a one-shot script! It is probably unmaintained though.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import itertools
|
||||||
|
|
||||||
from pokedex.db import connect
|
from pokedex.db import connect
|
||||||
import pokedex.db.tables as t
|
import pokedex.db.tables as t
|
||||||
from sqlalchemy.orm import lazyload, joinedload, subqueryload
|
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)
|
return dict((stat.pokeathlon_stat_id, (stat.minimum_stat, stat.base_stat, stat.maximum_stat)) for stat in stats)
|
||||||
|
|
||||||
def getitems(items):
|
def getitems(items):
|
||||||
return list(sorted((item.version_id, item.item, item.rarity) for item in items))
|
return sorted((item.version_id, item.item_id, 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))
|
|
||||||
|
|
||||||
def getform(form):
|
def getform(form):
|
||||||
return {
|
return {
|
||||||
'ability': form.pokemon.all_abilities,
|
'ability': form.pokemon.all_abilities,
|
||||||
'items': getitems(form.pokemon.items),
|
'items': getitems(form.pokemon.items),
|
||||||
'moves': getmoves(form.pokemon.pokemon_moves),
|
|
||||||
'pokeathlon': getpokeathlon(form.pokeathlon_stats),
|
'pokeathlon': getpokeathlon(form.pokeathlon_stats),
|
||||||
'stats': getstats(form.pokemon.stats),
|
'stats': getstats(form.pokemon.stats),
|
||||||
'effort': geteffort(form.pokemon.stats),
|
'effort': geteffort(form.pokemon.stats),
|
||||||
'types': form.pokemon.types,
|
'type': form.pokemon.types,
|
||||||
'exp': form.pokemon.base_experience,
|
'exp': form.pokemon.base_experience,
|
||||||
'weight': form.pokemon.weight,
|
'weight': form.pokemon.weight,
|
||||||
'height': form.pokemon.height,
|
'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):
|
def gcd(a, b):
|
||||||
keys = set(a.keys()) & set(b.keys())
|
keys = set(a.keys()) & set(b.keys())
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -49,6 +58,14 @@ def gcd(a, b):
|
||||||
result[k] = a[k]
|
result[k] = a[k]
|
||||||
return result
|
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 = session.query(t.PokemonSpecies)
|
||||||
q = q.options(
|
q = q.options(
|
||||||
lazyload('default_pokemon'),
|
lazyload('default_pokemon'),
|
||||||
|
@ -67,21 +84,30 @@ for species in q.all():
|
||||||
.join(t.Pokemon)
|
.join(t.Pokemon)
|
||||||
.filter(t.Pokemon.species_id==species.id)
|
.filter(t.Pokemon.species_id==species.id)
|
||||||
.options(
|
.options(
|
||||||
|
subqueryload('pokeathlon_stats'),
|
||||||
|
|
||||||
joinedload('pokemon'),
|
joinedload('pokemon'),
|
||||||
joinedload('pokemon.all_abilities'),
|
joinedload('pokemon.all_abilities'),
|
||||||
joinedload('pokemon.items'),
|
joinedload('pokemon.items'),
|
||||||
joinedload('pokemon.stats'),
|
|
||||||
joinedload('pokemon.types'),
|
joinedload('pokemon.types'),
|
||||||
joinedload('pokeathlon_stats'),
|
joinedload('pokemon.pokemon_moves.method'),
|
||||||
|
subqueryload('pokemon.stats'),
|
||||||
subqueryload('pokemon.pokemon_moves'),
|
subqueryload('pokemon.pokemon_moves'),
|
||||||
|
|
||||||
|
lazyload('pokemon.default_form'),
|
||||||
|
lazyload('pokemon.forms'),
|
||||||
|
lazyload('pokemon.items.item'),
|
||||||
lazyload('pokemon.pokemon_moves.pokemon'),
|
lazyload('pokemon.pokemon_moves.pokemon'),
|
||||||
lazyload('pokemon.pokemon_moves.move'),
|
lazyload('pokemon.pokemon_moves.move'),
|
||||||
|
lazyload('pokemon.species'),
|
||||||
)
|
)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
keys = set(getform(forms[0]).keys())
|
uncommon = sorted(find_uncommon_keys(map(getform, forms)))
|
||||||
common_keys = set(reduce(gcd, map(getform, forms)).keys())
|
uncommon_moves = sorted(find_uncommon_keys(map(getmoves, forms)))
|
||||||
unique_keys = keys - common_keys
|
|
||||||
|
|
||||||
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