mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Merge branch 'generated-order'
This commit is contained in:
commit
13e2709668
4 changed files with 1440 additions and 1380 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1267,8 +1267,11 @@ class PokemonForm(TableBase):
|
||||||
info=dict(description=u'Set for exactly one form used as the default for each pokemon (not necessarily species).'))
|
info=dict(description=u'Set for exactly one form used as the default for each pokemon (not necessarily species).'))
|
||||||
is_battle_only = Column(Boolean, nullable=False,
|
is_battle_only = Column(Boolean, nullable=False,
|
||||||
info=dict(description=u'Set iff the form can only appear in battle.'))
|
info=dict(description=u'Set iff the form can only appear in battle.'))
|
||||||
|
form_order = Column(Integer, nullable=False, autoincrement=False,
|
||||||
|
info=dict(description=u"The order in which forms should be sorted within a species' forms. Multiple forms may have equal order, in which case they should fall back on sorting by name. "
|
||||||
|
u"Used in generating `pokemon_forms.order` and `pokemon.order`."))
|
||||||
order = Column(Integer, nullable=False, autoincrement=False,
|
order = Column(Integer, nullable=False, autoincrement=False,
|
||||||
info=dict(description=u'The order in which forms should be sorted. Multiple forms may have equal order, in which case they should fall back on sorting by name.'))
|
info=dict(description=u'The order in which forms should be sorted within all forms. Multiple forms may have equal order, in which case they should fall back on sorting by name.'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -1443,6 +1446,8 @@ class PokemonSpecies(TableBase):
|
||||||
info=dict(description="ID of the growth rate for this family"))
|
info=dict(description="ID of the growth rate for this family"))
|
||||||
forms_switchable = Column(Boolean, nullable=False,
|
forms_switchable = Column(Boolean, nullable=False,
|
||||||
info=dict(description=u"True iff a particular individual of this species can switch beween its different forms."))
|
info=dict(description=u"True iff a particular individual of this species can switch beween its different forms."))
|
||||||
|
order = Column(Integer, nullable=False, index=True,
|
||||||
|
info=dict(description=u'The order in which species should be sorted. Based on National Dex order, except families are grouped together and sorted by stage.'))
|
||||||
|
|
||||||
create_translation_table('pokemon_species_names', PokemonSpecies, 'names',
|
create_translation_table('pokemon_species_names', PokemonSpecies, 'names',
|
||||||
relation_lazy='joined',
|
relation_lazy='joined',
|
||||||
|
@ -2094,7 +2099,7 @@ PokemonSpecies.egg_groups = relationship(EggGroup,
|
||||||
secondary=PokemonEggGroup.__table__,
|
secondary=PokemonEggGroup.__table__,
|
||||||
innerjoin=True,
|
innerjoin=True,
|
||||||
order_by=PokemonEggGroup.egg_group_id.asc(),
|
order_by=PokemonEggGroup.egg_group_id.asc(),
|
||||||
backref=backref('species', order_by=Pokemon.order.asc()))
|
backref=backref('species', order_by=PokemonSpecies.order.asc()))
|
||||||
PokemonSpecies.forms = relationship(PokemonForm,
|
PokemonSpecies.forms = relationship(PokemonForm,
|
||||||
secondary=Pokemon.__table__,
|
secondary=Pokemon.__table__,
|
||||||
primaryjoin=PokemonSpecies.id==Pokemon.species_id,
|
primaryjoin=PokemonSpecies.id==Pokemon.species_id,
|
||||||
|
|
55
scripts/set_pokemon_order_columns.sql
Normal file
55
scripts/set_pokemon_order_columns.sql
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
Pokémon species order: National dex order, except that families are grouped
|
||||||
|
together around whichever member has the lowest National ID, with babies first.
|
||||||
|
|
||||||
|
Technically, the idea is to sort each evolutionary tree topologically, but
|
||||||
|
National ID with babies first does the right thing. The id column happens to
|
||||||
|
match Nat'l order, and the evolutionary chain IDs are in the right order too.
|
||||||
|
*/
|
||||||
|
|
||||||
|
UPDATE pokemon_species ps
|
||||||
|
SET "order" = ps_order."order"
|
||||||
|
FROM (
|
||||||
|
SELECT ps_sub.id, ROW_NUMBER() OVER (ORDER BY ps_sub.evolution_chain_id,
|
||||||
|
ps_sub.is_baby DESC, ps_sub.id) "order"
|
||||||
|
FROM pokemon_species ps_sub
|
||||||
|
) ps_order
|
||||||
|
WHERE ps.id = ps_order.id;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Pokémon form order: Same as species order, with a species' forms ordered as
|
||||||
|
specified by pokemon_forms.form_order. Since form_order can have duplicate
|
||||||
|
orders to indicate that they should fall back on ordering by name, so can
|
||||||
|
pokemon_forms.order.
|
||||||
|
*/
|
||||||
|
|
||||||
|
UPDATE pokemon_forms pf
|
||||||
|
SET "order" = pf_order."order"
|
||||||
|
FROM (
|
||||||
|
SELECT pf_sub.id, DENSE_RANK() OVER (ORDER BY ps."order",
|
||||||
|
pf_sub.form_order) "order"
|
||||||
|
FROM pokemon_forms pf_sub
|
||||||
|
JOIN pokemon p ON pf_sub.pokemon_id = p.id
|
||||||
|
JOIN pokemon_species ps ON p.species_id = ps.id
|
||||||
|
) pf_order
|
||||||
|
WHERE pf.id = pf_order.id;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
[Functional] Pokémon order: Same as form order, except not all forms have their
|
||||||
|
own functional Pokémon, so we need to close the gaps.
|
||||||
|
|
||||||
|
These aren't supposed to have duplicate orders, but this query will give them
|
||||||
|
duplicate orders where applicable anyway so that the unique constraint can
|
||||||
|
complain if needed instead of the query silently ordering things arbitrarily.
|
||||||
|
*/
|
||||||
|
|
||||||
|
UPDATE pokemon p
|
||||||
|
SET "order" = p_order."order"
|
||||||
|
FROM (
|
||||||
|
SELECT p_sub.id, DENSE_RANK() OVER (ORDER BY pf."order") "order"
|
||||||
|
FROM pokemon p_sub
|
||||||
|
JOIN pokemon_forms pf ON p_sub.id = pf.pokemon_id AND pf.is_default = True
|
||||||
|
) p_order
|
||||||
|
WHERE p.id = p_order.id;
|
Loading…
Reference in a new issue