From 2981baf36c5f395f0379f5ac71e7e4a77b2941d5 Mon Sep 17 00:00:00 2001 From: tallypokemap Date: Wed, 31 May 2017 17:25:39 -0400 Subject: [PATCH] add CP and lvl information to db, wh, and frontend --- monocle/db.py | 14 +++++++++++--- monocle/notification.py | 2 ++ monocle/static/js/main.js | 3 ++- monocle/utils.py | 9 +++++++++ monocle/web_utils.py | 4 +++- monocle/worker.py | 2 ++ web_sanic.py | 4 +++- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/monocle/db.py b/monocle/db.py index f1d1eeb2..67b3f650 100644 --- a/monocle/db.py +++ b/monocle/db.py @@ -10,7 +10,7 @@ from sqlalchemy.ext.declarative import declarative_base from . import bounds, spawns, db_proc, sanitized as conf -from .utils import time_until_time, dump_pickle, load_pickle +from .utils import time_until_time, dump_pickle, load_pickle, calc_pokemon_level from .shared import call_at, get_logger try: @@ -225,6 +225,8 @@ class Sighting(Base): sta_iv = Column(TINY_TYPE) move_1 = Column(SmallInteger) move_2 = Column(SmallInteger) + cp = Column(SmallInteger) + level = Column(SmallInteger) __table_args__ = ( UniqueConstraint( @@ -253,6 +255,8 @@ class Mystery(Base): sta_iv = Column(TINY_TYPE) move_1 = Column(SmallInteger) move_2 = Column(SmallInteger) + cp = Column(SmallInteger) + level = Column(SmallInteger) __table_args__ = ( UniqueConstraint( @@ -354,7 +358,9 @@ def add_sighting(session, pokemon): def_iv=pokemon.get('individual_defense'), sta_iv=pokemon.get('individual_stamina'), move_1=pokemon.get('move_1'), - move_2=pokemon.get('move_2') + move_2=pokemon.get('move_2'), + cp=pokemon.get('cp'), + level=calc_pokemon_level(pokemon.get('cp_multiplier')) ) session.add(obj) SIGHTING_CACHE.add(pokemon) @@ -453,7 +459,9 @@ def add_mystery(session, pokemon): def_iv=pokemon.get('individual_defense'), sta_iv=pokemon.get('individual_stamina'), move_1=pokemon.get('move_1'), - move_2=pokemon.get('move_2') + move_2=pokemon.get('move_2'), + cp=pokemon.get('cp'), + level=calc_pokemon_level(pokemon.get('cp_multiplier')) ) session.add(obj) MYSTERY_CACHE.add(pokemon) diff --git a/monocle/notification.py b/monocle/notification.py index 9bb2a77b..be105572 100755 --- a/monocle/notification.py +++ b/monocle/notification.py @@ -787,6 +787,8 @@ async def webhook(self, pokemon): data['message']['height'] = pokemon['height'] data['message']['weight'] = pokemon['weight'] data['message']['gender'] = pokemon['gender'] + data['message']['cp'] = pokemon['cp'] + data['message']['pokemon_level'] = pokemon['level'] except KeyError: pass diff --git a/monocle/static/js/main.js b/monocle/static/js/main.js index b83c147c..ad8d8fcc 100644 --- a/monocle/static/js/main.js +++ b/monocle/static/js/main.js @@ -84,7 +84,8 @@ function getPopupContent (item) { content += 'Disappears in: ' + expires_at + '
'; content += 'Move 1: ' + item.move1 + ' ( ' + item.damage1 + ' dps )
'; content += 'Move 2: ' + item.move2 + ' ( ' + item.damage2 + ' dps )
'; - content += 'IV: ' + item.atk + ' atk, ' + item.def + ' def, ' + item.sta + ' sta
' + content += 'IV: ' + item.atk + ' atk, ' + item.def + ' def, ' + item.sta + ' sta
'; + content += 'CP: ' + item.cp + ' | Lvl: ' + item.level + '
'; } else { content += '
Disappears in: ' + expires_at + '
'; } diff --git a/monocle/utils.py b/monocle/utils.py index fd5dcb1d..e20628c5 100644 --- a/monocle/utils.py +++ b/monocle/utils.py @@ -321,3 +321,12 @@ def randomize_point(point, amount=0.0003, randomize=uniform): randomize(lat - amount, lat + amount), randomize(lon - amount, lon + amount) ) + + +def calc_pokemon_level(cp_multiplier): + if cp_multiplier < 0.734: + pokemon_level = (58.35178527 * cp_multiplier * cp_multiplier - 2.838007664 * cp_multiplier + 0.8539209906) + else: + pokemon_level = 171.0112688 * cp_multiplier - 95.20425243 + pokemon_level = int((round(pokemon_level) * 2) / 2) + return pokemon_level diff --git a/monocle/web_utils.py b/monocle/web_utils.py index 684b548d..879da744 100644 --- a/monocle/web_utils.py +++ b/monocle/web_utils.py @@ -5,7 +5,7 @@ from monocle import sanitized as conf from monocle.db import get_forts, Pokestop, session_scope, Sighting, Spawnpoint -from monocle.utils import Units, get_address +from monocle.utils import Units, get_address, calc_pokemon_level from monocle.names import DAMAGE, MOVES, POKEMON if conf.MAP_WORKERS: @@ -105,6 +105,8 @@ def sighting_to_marker(pokemon, names=POKEMON, moves=MOVES, damage=DAMAGE): marker['move2'] = moves[move2] marker['damage1'] = damage[move1] marker['damage2'] = damage[move2] + marker['cp'] = pokemon.cp + marker['level'] = pokemon.level return marker diff --git a/monocle/worker.py b/monocle/worker.py index 971e6696..1850edb7 100644 --- a/monocle/worker.py +++ b/monocle/worker.py @@ -994,6 +994,8 @@ async def encounter(self, pokemon, spawn_id): pokemon['height'] = pdata.height_m pokemon['weight'] = pdata.weight_kg pokemon['gender'] = pdata.pokemon_display.gender + pokemon['cp'] = pdata.cp + pokemon['level'] = pdata.level except KeyError: self.log.error('Missing encounter response.') self.error_code = '!' diff --git a/web_sanic.py b/web_sanic.py index fba1c6ea..92d99809 100755 --- a/web_sanic.py +++ b/web_sanic.py @@ -97,7 +97,7 @@ async def pokemon_data(request, _time=time): last_id = request.args.get('last_id', 0) async with app.pool.acquire() as conn: results = await conn.fetch(''' - SELECT id, pokemon_id, expire_timestamp, lat, lon, atk_iv, def_iv, sta_iv, move_1, move_2 + SELECT id, pokemon_id, expire_timestamp, lat, lon, atk_iv, def_iv, sta_iv, move_1, move_2, cp, level FROM sightings WHERE expire_timestamp > {} AND id > {} '''.format(_time(), last_id)) @@ -177,6 +177,8 @@ def sighting_to_marker(pokemon, names=POKEMON, moves=MOVES, damage=DAMAGE, trash marker['move2'] = moves[move2] marker['damage1'] = damage[move1] marker['damage2'] = damage[move2] + marker['cp'] = pokemon['cp'] + marker['level'] = pokemon['level'] return marker