Skip to content

Commit

Permalink
add CP and lvl information to db, wh, and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tallypokemap committed Jun 16, 2017
1 parent bd2a935 commit 2981baf
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
14 changes: 11 additions & 3 deletions monocle/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions monocle/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion monocle/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function getPopupContent (item) {
content += 'Disappears in: ' + expires_at + '<br>';
content += 'Move 1: ' + item.move1 + ' ( ' + item.damage1 + ' dps )<br>';
content += 'Move 2: ' + item.move2 + ' ( ' + item.damage2 + ' dps )<br>';
content += 'IV: ' + item.atk + ' atk, ' + item.def + ' def, ' + item.sta + ' sta<br>'
content += 'IV: ' + item.atk + ' atk, ' + item.def + ' def, ' + item.sta + ' sta<br>';
content += 'CP: ' + item.cp + ' | Lvl: ' + item.level + '<br>';
} else {
content += '<br>Disappears in: ' + expires_at + '<br>';
}
Expand Down
9 changes: 9 additions & 0 deletions monocle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion monocle/web_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions monocle/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '!'
Expand Down
4 changes: 3 additions & 1 deletion web_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 2981baf

Please sign in to comment.