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

remove linear search in get_base_map_name and get_base_hero_name + all other data lists. #5

Merged
merged 3 commits into from
Sep 17, 2017

Conversation

CamDavidsonPilon
Copy link
Contributor

@CamDavidsonPilon CamDavidsonPilon commented Sep 17, 2017

While not the least-performant part of the codebase, I wanted to clean up get_base_hero_name and get_base_map_name. They were doing inefficient loops over lists, and these can be much faster by using dict lookups. I've created classes for these lookups too, as they can encapsulate all the translation logic we require.

Similarly, all the lists in data/__init__.py could be sets which offer better in performance.

I've also add a test folder, I can run it locally with:

$ pip install pytest
$ py.test tests/

I also tested these changes locally in my database, things look good there too.

I'm most concerned about not catching unicodes correctly in production.

data/__init__.py Outdated
u"\u0422\u0440\u0435\u0439\u0441\u0435\u0440", u"\u730e\u7a7a",
u"\u9583\u5149 /// Tracer"],
"Tychus": [u"Tychus", u"Tychus", u"Tychus /// Tychus", u"Tychus /// Tychus",
u
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I'm not recreating to inverse mapping each time a new HeroUnit or Player class is created.

u"\ub514\uc544\ube14\ub85c /// Diablo", u"Diablo /// Diablo",
u"\u0414\u0438\u0430\u0431\u043b\u043e /// Diablo",
u"\u8fea\u4e9a\u6ce2\u7f57 /// Diablo", u"\u8fea\u4e9e\u5e03\u7f85 /// Diablo"],
"Lunara": [u"Dryad", u"Lunara /// Lunara", u"Lunara /// Lunara", u"Lunara /// Lunara",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get why you replaced the key from Dryad to Lunara.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The keys are now the "canonical" name of the hero - so Lunara should be placed there. This is the same logic as previous code - if Dryad was the key and "Dryad" as inputted, we still would have outputted Lunara - see the previous code here: https://github.com/crorella/hots-parser/pull/5/files/ee572c1086ccffd6a211b41d2e3579db1608f621#diff-740b116474b5b8b4d5927ca113397b13L18

assert HeroTranslator.get_base_hero_name("Gazleu /// Gazlowe") == "Gazlowe"
assert HeroTranslator.get_base_hero_name(u"Thrall /// Thrall") == "Thrall"
assert HeroTranslator.get_base_hero_name("Thrall /// Thrall") == "Thrall"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add tests for Gul'dan, Brightwing and Lunara? The reason is the internal representation for these heroes are Guldan, FaerieDragon and Dryad respectively and I would like to test those cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - tests pass locally

@crorella
Copy link
Collaborator

Okay, I also tested locally and seems to be working fine, thanks @CamDavidsonPilon !!

@crorella crorella merged commit 73578e1 into hotsdata:master Sep 17, 2017
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.

None yet

2 participants