-
Notifications
You must be signed in to change notification settings - Fork 282
Unique strategy id and index #694
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
Conversation
|
This is my fault, I removed the encoding header line in my last cleanup PR. Just add |
| def strategy_id(strategy): | ||
| return strategy.name.lower().replace(' ', '_') | ||
|
|
||
| strategy_index = {strategy_id(s): s for s in all_strategies} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is index the right word? Makes me think of a number... Not terribly offended by index though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes me think of an index at the back of a book, or a database index - something where you look things up!!
Not too bothered myself, if there's a better suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I think now that you've said that I'm cool with index. Ignore me :)
|
This looks good to me.
|
Not sure I quite understand the use case - I don't have any great objection, just want to understand!! It would need to be a class attribute, if that makes any difference |
OK. I'll put something together |
|
I've added two tests for the strategy index:
|
|
Code to flush out the duplicates: which gives: |
gives |
|
the remaining 16 with an id of 'player' are those that use init_args to set the name. Since they only do so on instantiation, the class attribute still has 'Player' as its name' |
Class attribute would be fine. So at the moment @Nikoleta-v3 is dealing with a dataset of the following form (that's she's generating): where this dictionary becomes useful is if instead the data set was: So that if we were to read in the data set we could obtain the classes (EDIT: if we wanted to reproduce some of this) by going: So... to obtain the id in the first place we would need to write: This was what I was thinking you meant when wrote (#668):
Without the players themselves having the id I'm not sure I understand the use case for the index dictionary? (Been a long day and I've just had a walk in the sun so I might be missing something).
That's a pity. Perhaps if we indeed put the id as a class property, then we could override it for these tricky ones and change the generation of the index to just grab the id from the class itself? One other point (when we get there): could you add a brief line or two about this index to the docs: http://axelrod.readthedocs.io/en/latest/tutorials/advanced/classification_of_strategies.html |
|
Isn't the strategy name already a unique id at the class level? A new class attribute won't help with:
|
|
Good point. On Tue, 16 Aug 2016, 17:48 Marc Harper, notifications@github.com wrote:
|
The use case I described above could actually easily be taken care of using this dictionary: Perhaps, if what this PR is doing is creating a dictionary that maps lower case names with stripped white space (needed for the api right? for urls?) to classes, then this is better located in the api and doesn't add anything to the library? |
Possibly, but it's also adding the index - yes, we could do that with the name as the key, but then I'd just end up repeating virtually the same index in the api but using the unique_id instead. |
|
so, if the index is no use, then this should just be in the api. However, if the index is useful then both should be in the library to keep things DRY between it and the api. |
|
I agree, both here or both in the api. My current point of view is that as is the index is not useful. To use it, On Wed, 17 Aug 2016, 13:36 Owen Campbell, notifications@github.com wrote:
|
|
I think I'm coming round to that view myself. |
|
I suggest we close this PR? Looking through the commit messages it looks like you might have fished out a couple of things that were wrong with some |
|
Yep. I'll close this PR and submit a new one. I need the names fixing in order for the indexing to work properly in the api. |
closes #688