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
Merged

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

merged 8 commits into from
Sep 22, 2016

Conversation

GhosterBot
Copy link
Contributor

  • A 'missing' only Pokemon (not on the catch_list, no VIP and with a bad IV) will now be keep on the list as a potential target if 'missing' is specified on the order option
  • The sorting of the target list is now cumulative.
    For example, if the order option is [missing, vip, priority], then the list will be ordered by 'missing' first, and then VIP's, and finally by Priority. Actually, the list is only ordered by the last order option specified on the config (only by priority on this example)

Screenshot example of a cumulative [missing, priority, iv, vip] order list

pgo_log

- A 'missing' only Pokemon (not on the catch_list, no VIP and with a bad
IV) will now be keep on the list as a potential target if 'missing' is
specified on the order option

- The sorting of the targer list is modified to be cumulative.
For example, if the `order` option is [`missing`, `vip`, `priority`],
then the list will be ordered by 'missing' first, and then VIP's, and
finally by Priority.
Snipe task: Keeping 'missing' Pokemon + sorting order correction
Import itemgetter
@mention-bot
Copy link

@GhosterBot, thanks for your PR! By analyzing the annotation information on this pull request, we identified @YvesHenri to be a potential reviewer

@GhosterBot GhosterBot changed the title Snipe task: Keeping 'missing' Pokemon + sorting order correction Sniper task: Keeping 'missing' Pokemon + sorting order correction Sep 22, 2016
@@ -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

@@ -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.

@@ -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.

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.

@solderzzc
Copy link
Contributor

solderzzc commented Sep 22, 2016

👍

Approved with PullApprove

@solderzzc solderzzc merged commit 66f2fe2 into PokemonGoF:dev Sep 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants