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 Jul 7, 2017
1 parent 507378a commit 9253892
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
12 changes: 10 additions & 2 deletions monocle/db.py
Original file line number Diff line number Diff line change
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=pokemon.get('level')
)
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=pokemon.get('level')
)
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 @@ -789,6 +789,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
2 changes: 2 additions & 0 deletions monocle/web_utils.py
Original file line number Diff line number Diff line change
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
4 changes: 3 additions & 1 deletion monocle/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pogeo import get_distance

from .db import FORT_CACHE, MYSTERY_CACHE, SIGHTING_CACHE
from .utils import round_coords, load_pickle, get_device_info, get_start_coords, Units, randomize_point
from .utils import round_coords, load_pickle, get_device_info, get_start_coords, Units, randomize_point, calc_pokemon_level
from .shared import get_logger, LOOP, SessionManager, run_threaded, ACCOUNTS
from . import altitudes, avatar, bounds, db_proc, spawns, sanitized as conf

Expand Down Expand Up @@ -991,6 +991,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'] = calc_pokemon_level(pdata.cp_multiplier)
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 9253892

Please sign in to comment.