Skip to content

Commit

Permalink
Add costume to Pokemon and costume/form to GymPokemon. (#2461)
Browse files Browse the repository at this point in the history
* Introduced Costume to Pokemon & GymPokemon, Introduced Form to GymPokemon

* Switched DB changes to migrate()

* Updated Form to always check, not just for 201.
Fixed call for Costume & Form in Gym lookup

* Removing 'pokemon_data' from string
  • Loading branch information
billyjbryant authored and sebastienvercammen committed Feb 1, 2018
1 parent 3a116fb commit 74d1888
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/extras/webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ A `pokemon` event is sent every time RocketMap detects that a Pok茅mon has spawn
| `gender` | The Pok茅mon's gender<sup>1</sup> | `2` |
| `cp` | The Pok茅mon's CP<sup>2</sup> | `""` |
| `form` | The Pok茅mon's form<sup>2</sup> | `""` |
| `costume` | The Pok茅mon's costume id<sup>2</sup> | `""` |
| `individual_attack` | The Pok茅mon's attack IV<sup>2</sup> | `""` |
| `individual_defense` | The Pok茅mon's defence IV<sup>2</sup> | `""` |
| `individual_stamina` | The Pok茅mon's stamina IV<sup>2</sup> | `""` |
Expand Down Expand Up @@ -338,6 +339,7 @@ A `gym-info` event is sent whenever RocketMap fetches a gym's details.
| `height` | The Pok茅mon's height | `1.746612787246704` |
| `weight` | The Pok茅mon's weight | `51.84344482421875` |
| `form` | The Pok茅mon's form | `0` |
| `costume` | The Pok茅mon's costume | `0` |
| `iv_attack` | The Pok茅mon's attack IV | `12` |
| `iv_defense` | The Pok茅mon's defense IV | `14` |
| `iv_stamina` | The Pok茅mon's stamina IV | `14` |
Expand Down
32 changes: 24 additions & 8 deletions pogom/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
args = get_args()
flaskDb = FlaskDB()
cache = TTLCache(maxsize=100, ttl=60 * 5)

db_schema_version = 24
db_schema_version = 25


class MyRetryDB(RetryOperationalError, PooledMySQLDatabase):
Expand Down Expand Up @@ -122,6 +121,7 @@ class Pokemon(LatLongModel):
weight = FloatField(null=True)
height = FloatField(null=True)
gender = SmallIntegerField(null=True)
costume = SmallIntegerField(null=True)
form = SmallIntegerField(null=True)
last_modified = DateTimeField(
null=True, index=True, default=datetime.utcnow)
Expand Down Expand Up @@ -502,6 +502,8 @@ def get_gyms(swLat, swLng, neLat, neLng, timestamp=0, oSwLat=None,
GymMember.deployment_time,
GymMember.last_scanned,
GymPokemon.pokemon_id,
GymPokemon.costume,
GymPokemon.form,
Trainer.name.alias('trainer_name'),
Trainer.level.alias('trainer_level'))
.join(Gym, on=(GymMember.gym_id == Gym.gym_id))
Expand Down Expand Up @@ -584,6 +586,8 @@ def get_gym(id):
GymPokemon.iv_attack,
GymPokemon.iv_defense,
GymPokemon.iv_stamina,
GymPokemon.costume,
GymPokemon.form,
Trainer.name.alias('trainer_name'),
Trainer.level.alias('trainer_level'))
.join(Gym, on=(GymMember.gym_id == Gym.gym_id))
Expand Down Expand Up @@ -1698,6 +1702,8 @@ class GymPokemon(BaseModel):
iv_defense = SmallIntegerField(null=True)
iv_stamina = SmallIntegerField(null=True)
iv_attack = SmallIntegerField(null=True)
costume = SmallIntegerField(null=True)
form = SmallIntegerField(null=True)
last_seen = DateTimeField(default=datetime.utcnow)


Expand Down Expand Up @@ -2005,14 +2011,10 @@ def parse_map(args, map_dict, scan_coords, scan_location, db_update_queue,
'height': None,
'weight': None,
'gender': p.pokemon_data.pokemon_display.gender,
'form': None
'costume': p.pokemon_data.pokemon_display.costume,
'form': p.pokemon_data.pokemon_display.form
}

# Check for Unown's alphabetic character.
if pokemon_id == 201:
pokemon[p.encounter_id]['form'] = (p.pokemon_data
.pokemon_display.form)

# We need to check if exist and is not false due to a request error
if pokemon_info:
pokemon[p.encounter_id].update({
Expand Down Expand Up @@ -2517,6 +2519,8 @@ def parse_gyms(args, gym_responses, wh_update_queue, db_update_queue):
'iv_defense': pokemon.individual_defense,
'iv_stamina': pokemon.individual_stamina,
'iv_attack': pokemon.individual_attack,
'costume': pokemon.pokemon_display.costume,
'form': pokemon.pokemon_display.form,
'last_seen': datetime.utcnow(),
}

Expand Down Expand Up @@ -3226,6 +3230,18 @@ def database_migrate(db, old_ver):
('disappear_time', 'pokemon_id'), False)
)

if old_ver < 25:
migrate(
# Add `costume` column to `pokemon`
migrator.add_column('pokemon', 'costume',
SmallIntegerField(null=True)),
# Add `form` column to `gympokemon`
migrator.add_column('gympokemon', 'form',
SmallIntegerField(null=True)),
# Add `costume` column to `gympokemon`
migrator.add_column('gympokemon', 'costume',
SmallIntegerField(null=True)))

# Always log that we're done.
log.info('Schema upgrade complete.')
return True

0 comments on commit 74d1888

Please sign in to comment.