[API] Retrieving player match history
I want to retrieve the history of a player (Byun, id=47 for instance). Since it is not explicitly said in the documentation, I did the following : http://aligulac.com/api/v1/match/?pla__in=47&order_by=-id&apikey=XXXXX&format=json
When I saw that there were missing matches, I understood that it was because in some match byun was player b
So I tried to do the following :
http://aligulac.com/api/v1/match/?plb__in=47&pla__in=47&order_by=-id&apikey=XXXX&format=json
But it returns : {"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 0}, "objects": []}
Is this a bug, or am I not consuming the api properly, maybe there is something like /player/47/match-history but I haven't found it yet. neither in /player/schema nor elsewhere. If it does not exist, it would be super nice !
Kind regards
Laurent `Bouh
Yout second URL there is searching for all matches where Byun is player A and player B, which is predictably empty.
As far as I know we don't support or-type requests, so you have to make two queries, one for player A and one for player B.
I agree it would be nice to support this.
Maybe it would be nice to integrate in the player api with something like /player/match-history.
Would you accept a pull request for it ? I am not a djangoist but I can try
2015-12-16 9:49 GMT+01:00 Eivind Fonn [email protected]:
Yout second URL there is searching for all matches where Byun is player A and player B, which is predictably empty.
As far as I know we don't support or-type requests, so you have to make two queries, one for player A and one for player B.
I agree it would be nice to support this.
— Reply to this email directly or view it on GitHub https://github.com/TheBB/aligulac/issues/277#issuecomment-165035562.
Sure I would!
Hm after having dived in the code, I see two approaches :
- The clean one (but requiring more work) : Adding a One to many relation between Player and matches. But I guess it would require data batch processing to add all matchs relations to players and updates views.
- The quick and dirty : Add a custom_filter "player" in MatchResource like in http://stackoverflow.com/a/10022244 I am not sure of the implementation, but based on my understanding of tastypie, we could update the build_filter method with something like :
if('player' in filters):
query = filters['player']
qset = (
Q(pla=query) |
Q(plb=query) |
)
orm_filters.update({'custom': qset})
Do you think that the second solution is doable and easy ?
I had in mind something like the second. I'm not keen on introducing new DB relations just for this.
I should note that I haven't looked at the code in detail for a good while so I can't comment on the precise implementation at the moment.
@lce-fr I have added a custom method to the Match queryset called symmetric_filter.
For instance, Match.objects.symmetric_filter(pla=<player>) == Match.objects.filter(Q(pla=<player>) | Q(plb=<player>))
Maybe you could map the GET query parameters pl, sc, rc, rt (don't exist now) to pla, sca, rca, rta in symmetric_filter?