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

Sniper task: Keeping 'missing' Pokemon + sorting order correction #5613

Merged
merged 8 commits into from
Sep 22, 2016
11 changes: 7 additions & 4 deletions pokemongo_bot/cell_workers/sniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import calendar

from random import uniform
from operator import itemgetter, methodcaller
from datetime import datetime
from pokemongo_bot import inventory
from pokemongo_bot.item_list import Item
Expand Down Expand Up @@ -277,8 +278,11 @@ def is_snipeable(self, pokemon):
if pokemon.get('vip', False):
self._trace('{} is not catchable and bad IV (if any), however its a VIP!'.format(pokemon.get('pokemon_name')))
else:
self._trace('{} is not catachable, nor a VIP and bad IV (if any). Skipping...'.format(pokemon.get('pokemon_name')))
return False
if pokemon['missing']:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change it from if pokemon['missing']: to if pokemon.get('missing', False):.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ho I see, sorry. Thanks to have handle that

self._trace('{} is not catchable, not VIP and bad IV (if any), however its a missing one.'.format(pokemon.get('pokemon_name')))
else:
self._trace('{} is not catchable, nor a VIP or a missing one and bad IV (if any). Skipping...'.format(pokemon.get('pokemon_name')))
return False

return True

Expand Down Expand Up @@ -362,8 +366,7 @@ def work(self):

if targets:
# Order the targets (descending)
for attr in self.order:
targets.sort(key=lambda pokemon: pokemon[attr], reverse=True)
targets = sorted(targets, key=itemgetter(*self.order), reverse=True)
Copy link

@YvesHenri YvesHenri Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is and targets.sort(key=lambda pokemon: pokemon[attr], reverse=True) are the same thing (and requires less imports).

Copy link
Contributor Author

@GhosterBot GhosterBot Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YvesHenri
Not exactly, because this method is called as many times as there is attr in self.order: , and that's the problem.

So, at every call on the loop, the targets list will be sorted by loop's current pokemon[attr] only.
So if there is 4 orders specified (missing, priority, iv, vip), the targets.sort will be called 4 times, and everytimes the sorting will be on one attribute only. First missing only, then priority only, then iv only, and finally ordering by vip only. So finally the list will only be sorted by vip (in this example), regardless the others options.
I see it with my detailed logs .
So calling
targets = sorted(targets, key=itemgetter(*self.order), reverse=True
will do in one pass a cumulative ordering, thanks to the *self.order parameter where all the desired order will be handle at once (look at my screenshot for another example)

Please look at https://docs.python.org/2/library/operator.html :
-> Changed in version 2.5: Added support for multiple item extraction.
That's exactly what we are looking for

Copy link

@YvesHenri YvesHenri Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. Thats what I meant. Although, the final/merged list will have around 3050 items, and if you have a max of 5 ordering types, that should be an iteration of 150250 times, which is worthless. I'll accept it anyways.


shots = 0

Expand Down