2012-12-07 00:02:39 -08:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
|
|
|
|
"""List the ways that pokemon forms differ from one another.
|
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
This is not a one-shot script--it is probably unmaintained though!
|
2012-12-07 00:02:39 -08:00
|
|
|
"""
|
|
|
|
|
2012-12-07 00:04:16 -08:00
|
|
|
import itertools
|
|
|
|
|
2012-12-07 00:02:39 -08:00
|
|
|
from pokedex.db import connect
|
|
|
|
import pokedex.db.tables as t
|
|
|
|
from sqlalchemy.orm import lazyload, joinedload, subqueryload
|
|
|
|
|
|
|
|
session = connect()
|
|
|
|
#session.bind.echo = True
|
|
|
|
|
|
|
|
def getstats(stats):
|
|
|
|
return dict((stat.stat_id, stat.base_stat) for stat in stats)
|
|
|
|
|
|
|
|
def geteffort(stats):
|
|
|
|
return dict((stat.stat_id, stat.effort) for stat in stats)
|
|
|
|
|
|
|
|
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):
|
2012-12-07 00:04:16 -08:00
|
|
|
return sorted((item.version_id, item.item_id, item.rarity) for item in items)
|
2012-12-07 00:02:39 -08:00
|
|
|
|
|
|
|
def getform(form):
|
|
|
|
return {
|
|
|
|
'ability': form.pokemon.all_abilities,
|
|
|
|
'items': getitems(form.pokemon.items),
|
|
|
|
'pokeathlon': getpokeathlon(form.pokeathlon_stats),
|
|
|
|
'stats': getstats(form.pokemon.stats),
|
|
|
|
'effort': geteffort(form.pokemon.stats),
|
2012-12-07 00:04:16 -08:00
|
|
|
'type': form.pokemon.types,
|
2012-12-07 00:02:39 -08:00
|
|
|
'exp': form.pokemon.base_experience,
|
|
|
|
'weight': form.pokemon.weight,
|
|
|
|
'height': form.pokemon.height,
|
|
|
|
}
|
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
def getmoves(form):
|
|
|
|
moves = sorted((move.version_group_id, move.method.identifier, move.move_id, move.level, move.order) for move in form.pokemon.pokemon_moves)
|
2012-12-07 00:04:16 -08:00
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
# {version: {method: moves}}
|
|
|
|
version_method_moves = {}
|
|
|
|
for version, group in itertools.groupby(moves, lambda x: x[0]):
|
|
|
|
version_method_moves[version] = method_moves = {}
|
|
|
|
for method, group in itertools.groupby(group, lambda x: x[1]):
|
|
|
|
method_moves[method] = list(group)
|
2012-12-07 00:04:16 -08:00
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
return version_method_moves
|
2012-12-07 00:04:16 -08:00
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
def dictacc(a, b):
|
|
|
|
for k in b:
|
|
|
|
if k not in a:
|
|
|
|
a[k] = []
|
|
|
|
a[k] += [b[k]]
|
|
|
|
return a
|
2012-12-07 00:04:16 -08:00
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
def union(sets):
|
|
|
|
return reduce(set.union, sets, set())
|
2012-12-07 00:04:16 -08:00
|
|
|
|
2012-12-07 00:02:39 -08:00
|
|
|
def gcd(a, b):
|
2012-12-07 02:52:22 -08:00
|
|
|
"""Return a new dict containing only items which have the same value in both a and b."""
|
2012-12-07 00:02:39 -08:00
|
|
|
keys = set(a.keys()) & set(b.keys())
|
|
|
|
result = {}
|
|
|
|
for k in keys:
|
|
|
|
if a[k] == b[k]:
|
|
|
|
result[k] = a[k]
|
|
|
|
return result
|
|
|
|
|
2012-12-07 00:04:16 -08:00
|
|
|
def find_uncommon_keys(dicts):
|
2012-12-07 02:52:22 -08:00
|
|
|
keys = union(d.keys() for d in dicts)
|
2012-12-07 00:04:16 -08:00
|
|
|
|
|
|
|
common_keys = set(reduce(gcd, dicts).keys())
|
|
|
|
unique_keys = keys - common_keys
|
|
|
|
|
|
|
|
return unique_keys
|
|
|
|
|
2012-12-07 00:02:39 -08:00
|
|
|
q = session.query(t.PokemonSpecies)
|
|
|
|
q = q.options(
|
|
|
|
lazyload('default_pokemon'),
|
|
|
|
|
|
|
|
joinedload('forms'),
|
|
|
|
lazyload('forms.pokemon'),
|
|
|
|
)
|
|
|
|
|
|
|
|
for species in q.all():
|
|
|
|
forms = species.forms
|
|
|
|
|
|
|
|
if len(forms) == 1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
forms = (session.query(t.PokemonForm)
|
|
|
|
.join(t.Pokemon)
|
|
|
|
.filter(t.Pokemon.species_id==species.id)
|
|
|
|
.options(
|
2012-12-07 00:04:16 -08:00
|
|
|
subqueryload('pokeathlon_stats'),
|
|
|
|
|
2012-12-07 00:02:39 -08:00
|
|
|
joinedload('pokemon'),
|
|
|
|
joinedload('pokemon.all_abilities'),
|
|
|
|
joinedload('pokemon.items'),
|
|
|
|
joinedload('pokemon.types'),
|
2012-12-07 00:04:16 -08:00
|
|
|
joinedload('pokemon.pokemon_moves.method'),
|
2012-12-07 02:52:22 -08:00
|
|
|
#joinedload('pokemon.pokemon_moves.version_group'),
|
2012-12-07 00:04:16 -08:00
|
|
|
subqueryload('pokemon.stats'),
|
2012-12-07 00:02:39 -08:00
|
|
|
subqueryload('pokemon.pokemon_moves'),
|
2012-12-07 00:04:16 -08:00
|
|
|
|
|
|
|
lazyload('pokemon.default_form'),
|
|
|
|
lazyload('pokemon.forms'),
|
|
|
|
lazyload('pokemon.items.item'),
|
2012-12-07 00:02:39 -08:00
|
|
|
lazyload('pokemon.pokemon_moves.pokemon'),
|
|
|
|
lazyload('pokemon.pokemon_moves.move'),
|
2012-12-07 00:04:16 -08:00
|
|
|
lazyload('pokemon.species'),
|
2012-12-07 00:02:39 -08:00
|
|
|
)
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
### Okay, grab some info for each form and and find the differences
|
2012-12-07 00:04:16 -08:00
|
|
|
uncommon = sorted(find_uncommon_keys(map(getform, forms)))
|
|
|
|
|
2012-12-07 02:52:22 -08:00
|
|
|
### Moves are a bit different.
|
|
|
|
### First off, we want to split them up by method so we can narrow down the
|
|
|
|
### difference a little; this works the same as above. Second, if a form
|
|
|
|
### has no moves at all in some version group (because it didn't exist yet)
|
|
|
|
### then we don't want to count that as a difference.
|
|
|
|
|
|
|
|
# Start off by grabbing the movepool for each form
|
|
|
|
# This gives us pools = [{version: {method: moves}}]
|
|
|
|
pools = [getmoves(form) for form in forms]
|
|
|
|
# Next we combine the pools to get {version: [{method: moves}]}
|
|
|
|
version_pools = reduce(dictacc, pools, {})
|
|
|
|
# Now we can calculate the uncommon methods in each version.
|
|
|
|
uncommon_move_methods = union(map(find_uncommon_keys, version_pools.values()))
|
|
|
|
|
|
|
|
if uncommon_move_methods:
|
|
|
|
uncommon.append("moves ({})".format(", ".join(sorted(uncommon_move_methods))))
|
2012-12-07 00:02:39 -08:00
|
|
|
|
2012-12-07 00:04:16 -08:00
|
|
|
print "{}: {}".format(species.name, ", ".join(uncommon))
|