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] Fix cache, and name matching tweak #5674

Merged
merged 18 commits into from
Sep 26, 2016
Merged

[Sniper] Fix cache, and name matching tweak #5674

merged 18 commits into from
Sep 26, 2016

Conversation

Gobberwart
Copy link
Contributor

Short Description:

Two issues fixed here.

  1. Existing cache is not persistent, and gets reset every time the task runs, which results in repeated failed attempts to catch non-existent/otherwise failed pokemon. Even if cache hits, still generates an unnecessary log message. Changed to persistent cache, and check before attempting to snipe.
  2. Name matching can be flaky depending on sources. Added method to manually fix names we know about, or use difflib (as with pokemonoptimizer) to try and match any we haven't already caught. Note that difflib alone is not sufficient for this, eg. it thinks source name "mr-mime" is a Grimer. Close but no cigar.

Gobberwart and others added 17 commits September 24, 2016 14:33
Respond to possible name == None
Added Nidoran M/F
Respond to possible name == None
Added Nidoran M/F
Respond to possible name == None
Added Nidoran M/F
Previously using self.cache which gets reset every time this task is
called. Moved to self.bot.sniper_cache and added check in main snipe
thread to avoid unnecessary log spam.
Not required
Uses a list of uniqueid strings instead of list of dicts. Unique id is
an md5 hash of (pokemon_id, latitude, longitude and expiration)
@mention-bot
Copy link

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

self.bot.sniper_cache.pop(0)
self.bot.sniper_cache.append(uniqueid)

def _build_unique_id(self, pokemon):

Choose a reason for hiding this comment

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

This is totally unecessary. Use _hash instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How is it unnecessary? If there's an easy way to generate MD5 from string, then awesome. Please share your alternative code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless you're talking about the len(self.bot.sniper_cache) thing... which is your code so you tell me why it's necessary.

name = name.replace("mr-mime","mr. mime")
name = name.replace("farfetchd","farfetch'd")
name = name.replace("Nidoran\u2642","nidoran m")
name = name.replace("Nidoran\u2640","nidoran f")

Choose a reason for hiding this comment

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

Seriously? Are you going to handle every name combination possible?

Copy link
Contributor Author

@Gobberwart Gobberwart Sep 25, 2016

Choose a reason for hiding this comment

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

Read the description. Obviously not, but if we KNOW about something that's causing a problem (and difflib can't handle it), then why not replace it?

return name

def _get_closest_name(self, name):

Choose a reason for hiding this comment

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

What's this?

Copy link
Contributor Author

@Gobberwart Gobberwart Sep 25, 2016

Choose a reason for hiding this comment

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

@Again, read the description. Difflib is already used in pokemonoptimizer to TRY and get a real pokemon name from a supplied string. Eg. if source is "pigeot", it should return "pidgeot"... in many cases, it seems to work well. As per suggestion from @anakin5

@@ -210,13 +227,12 @@ class Sniper(BaseTask):
MIN_SECONDS_ALLOWED_FOR_CELL_CHECK = 10
MIN_SECONDS_ALLOWED_FOR_REQUESTING_DATA = 5
MIN_BALLS_FOR_CATCHING = 10
MAX_CACHE_LIST_SIZE = 200
MAX_CACHE_LIST_SIZE = 500

Choose a reason for hiding this comment

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

You do realize people bot on raspberry devices, right? Increasing this this high might not be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You do realise that replacing dict with an md5 string makes it take FARRRRR less memory to store.

Copy link
Contributor Author

@Gobberwart Gobberwart Sep 26, 2016

Choose a reason for hiding this comment

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

But OK, sure... I'll compromise at 300. See latest commit.

@@ -232,6 +248,9 @@ def initialize(self):
self.altitude = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.sources = [SniperSource(data) for data in self.config.get('sources', [])]

if not hasattr(self.bot,"sniper_cache"):
self.bot.sniper_cache = []

Choose a reason for hiding this comment

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

What's this and what's it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You had a "self.cache" which is nice but not persistent. Every time the task runs, it reset it to []. This creates a bot-global cache which will persist through task re-inits.


# Check if already in list of pokemon we've tried
uniqueid = self._build_unique_id(pokemon)
if self._is_cached(uniqueid):

Choose a reason for hiding this comment

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

is_snipeable should check whether its been cached or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need. It checks before it calls is_snipeable. Saves a wasted log message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is_snipeable currently lumps everything together as a general fail. I've removed one of those for clarity.

@Gobberwart
Copy link
Contributor Author

OK @YvesHenri I've answered all your questions. Talk to me in chat if something is still unclear.

@Gobberwart
Copy link
Contributor Author

Does anyone else have feedback for this?

@Gobberwart
Copy link
Contributor Author

No feedback received and YH's requested changes are irrelevant. Merging.

@Gobberwart Gobberwart merged commit f60a4b1 into PokemonGoF:dev Sep 26, 2016
@Gobberwart Gobberwart deleted the gobb_snipesource branch November 9, 2016 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants