Skip to content

Commit

Permalink
Added number of hatched eggs since the bot started (hatched_eggs) and…
Browse files Browse the repository at this point in the history
… distance (km) to next egg hatching (next_egg_hatching) in metrics/UpdateLiveStats PokemonGoF#4150
  • Loading branch information
ps1dr3x committed Aug 20, 2016
1 parent a1c9419 commit 0bff492
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def handle_sigint(*args):

def get_commit_hash():
try:
hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT)[:-1]
hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT)[:-1]

return hash if all(c in string.hexdigits for c in hash) else "not found"
except:
Expand Down Expand Up @@ -219,6 +219,9 @@ def report_summary(bot):
metrics.num_evolutions(), metrics.num_new_mons()))
logger.info('Threw {} pokeball{}'.format(metrics.num_throws(), '' if metrics.num_throws() == 1 else 's'))
logger.info('Earned {} Stardust'.format(metrics.earned_dust()))
logger.info('Hatched eggs {}'.format(metrics.hatched_eggs(0)))
if (metrics.next_hatching_km(0)):
logger.info('Next egg hatches in {:.2f} km'.format(metrics.next_hatching_km(0)))
logger.info('')
if metrics.highest_cp is not None:
logger.info('Highest CP Pokemon: {}'.format(metrics.highest_cp['desc']))
Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def work(self):
if km_left <= 0:
self._hatch_eggs()
else:
self.bot.metrics.next_hatching_km(km_left)
self.emit_event(
'next_egg_incubates',
formatted='Next egg ({km_needed} km) incubates in {distance_in_km:.2f} km (Total eggs: {eggs}, Incubating: {eggs_inc})',
Expand Down Expand Up @@ -200,6 +201,7 @@ def _hatch_eggs(self):
return
for i in range(len(pokemon_data)):
msg = "Egg hatched with a {pokemon} (CP {cp} - IV {iv}), {exp} exp, {stardust} stardust and {candy} candies."
self.bot.metrics.hatched_eggs(1)
self.emit_event(
'egg_hatched',
formatted=msg,
Expand Down
10 changes: 8 additions & 2 deletions pokemongo_bot/cell_workers/update_live_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class UpdateLiveStats(BaseTask):
- highest_cp_pokemon : The caught pokemon with the highest CP since the bot started.
- most_perfect_pokemon : The most perfect caught pokemon since the bot started.
- location : The location where the player is located.
- next_egg_hatching : The remaining distance to the next egg hatching (km).
- hatched_eggs : The number of hatched eggs since the bot started.
"""
SUPPORTED_TASK_API_VERSION = 1

Expand Down Expand Up @@ -164,10 +166,10 @@ def _update_title(self, title, platform):
self.emit_event(
'log_stats',
level = 'error',
formatted = "Unable to write window title"
formatted = "Unable to write window title"
)
self.terminal_title = False

self._compute_next_update()

def _get_stats_line(self, player_stats):
Expand Down Expand Up @@ -215,6 +217,8 @@ def _get_stats_line(self, player_stats):
most_perfect_pokemon = metrics.most_perfect['desc']
if not most_perfect_pokemon:
most_perfect_pokemon = "None"
next_egg_hatching = metrics.next_hatching_km(0)
hatched_eggs = metrics.hatched_eggs(0)

# Create stats strings.
available_stats = {
Expand Down Expand Up @@ -246,6 +250,8 @@ def _get_stats_line(self, player_stats):
'highest_cp_pokemon': 'Highest CP pokemon : {}'.format(highest_cp_pokemon),
'most_perfect_pokemon': 'Most perfect pokemon : {}'.format(most_perfect_pokemon),
'location': 'Location : ({}, {})'.format(self.bot.position[0], self.bot.position[1]),
'next_egg_hatching': 'Next egg hatches in : {:.2f} km'.format(next_egg_hatching),
'hatched_eggs': 'Hatched {} eggs.'.format(hatched_eggs)
}

def get_stat(stat):
Expand Down
12 changes: 12 additions & 0 deletions pokemongo_bot/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self, bot):
self.highest_cp = {'cp': 0, 'desc': ''}
self.most_perfect = {'potential': 0, 'desc': ''}

self.eggs = {'hatched': 0, 'next_hatching_km': 0}

def runtime(self):
return timedelta(seconds=round(time.time() - self.start_time))

Expand Down Expand Up @@ -62,6 +64,16 @@ def num_evolutions(self):
def earned_dust(self):
return self.dust['latest'] - self.dust['start']

def hatched_eggs(self, update):
if (update):
self.eggs['hatched'] += update
return self.eggs['hatched']

def next_hatching_km(self, update):
if (update):
self.eggs['next_hatching_km'] = update
return self.eggs['next_hatching_km']

def captured_pokemon(self, name, cp, iv_display, potential):
if cp > self.highest_cp['cp']:
self.highest_cp = \
Expand Down

0 comments on commit 0bff492

Please sign in to comment.