API difficulties

Deepseek told me to find the highest and lowest rated players enter:
https://online-go.com/api/v1/players?ordering=rating&page_size=1
and
https://online-go.com/api/v1/players?ordering=-rating&page_size=1
But they both return the same player, with a 1500 rating and no games played. Deepseek said to contact OGS about it.

I think you should insist that Deepseek not invent API parameters that don’t exist.

Good luck persuading it about that though - I face the same challenge daily with ChatGPT and friends:

Me: “I thought I asked you not to invent parameters”?

AI: “Oh, I apologize, I should have checked if the parameter existed before giving that answer”

Note: this also returns the same result:

https://online-go.com/api/v1/players?ordering=crazyai&page_size=1

because the /player API doesn’t support client-specified ordering at all, it just ignores that parameter.

6 Likes

Bummer. I don’t know how to use API and was wanting to see more stats like this.

There’s some API help lying around here somewhere - maybe @shinuito ?

3 Likes

Some links in this thread :slight_smile:

3 Likes

The pagesize is the number of results to be displayed in each page. Since you said 1, you got just one player.

The “count” variable is the overall number of players.

You could write a script to download 100 players per page, get them all, then do your own statistics on them.
I think some sort of ordering should be available, since I used it a long time ago. I did that script but I was getting duplicates (the same player in different pages) and the order option was key to avoid that.

1 Like

^^ It’s hard to see how this can be the explanation.

As I said, ordering is not supported on that endpoint.

If it were, the solution is correct because the first or the last player from the ordered list would be the one that the OP wanted.

However, this is the implementation of that endpoint:

class PlayerList(generics.ListAPIView):
    view_name = "Player List"
    filter_fields = ("username", "professional", "country", "language", "is_bot", "is_moderator")
    ordering_fields = ("username", "upper_username")
    GET_throttle = "10/s"  # this is used for player name auto complete
    model = Player
    serializer_class = MinimalPlayerSerializer

    def get_queryset(self):
        return Player.objects.extra(select={"upper_username": "upper(username)"}).order_by("upper_username").all()

    def get(self, request: Request, *args, **kwargs):
        if "page" in request.query_params and int(request.query_params["page"]) > 100:
            return Response({"error": "Page size is too large"}, status=status.HTTP_400_BAD_REQUEST)
        return super().get(request, *args, **kwargs)

It is ordered by username. There is no processing of an “ordering” parameter.

A Player doesn’t even have a field called rating, it has an object called v5_ratings.

1 Like

Yep!
I found that old line. It was about games.
Same process but different matter.
I would’ve taken for granted that it would work also for players, but of course you’re right.

https://online-go.com/api/v1/players/<nnnnnn>/games?ordering=id&page_size=100

The ordering param does work for the player endpoint, but I think the source code @GreenAsJade shared tells us that only username and upper_username are supported. For example:

https://online-go.com/api/v1/players/?ordering=-username

1 Like