Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CP and Level to db, webhook, and frontend #277

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -786,6 +786,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 @@ -325,3 +325,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