GrafeasGroup / blossom

The website. The app. The everything.
6 stars 3 forks source link

Add submission/leaderboard endpoint #179

Closed TimJentzsch closed 2 years ago

TimJentzsch commented 3 years ago

Relevant issue: Closes #175

Description:

This adds an additional submission/leaderboard endpoint that can be used to get a users rank according to their gamma. This is the last big change needed to implement the rest of the important Buttercup commands.

The endpoints take the parameters user_id to specify the user that the leaderboard is centered on as wel as top_count, above_count and below_count to control how many ranks are returned.

The response looks like this:

{
  "top": [ ... ],
  "above": [ ... ],
  "user": { 
    "id": ...,
    "username": ...,
    "gamma": ...,
    "rank": ...,
  },
  "below": [ ... ]
}

Where every item in top, above and below looks like the user item.

The submissions that the ranks are calculated on can be filtered as usual.

Future Work

After a lot of research, I was not able to find an efficient implementation to model the leaderboard. This is mainly due to two reasons: (a) gamma is a computed property and cannot be accessed directly and (b) the DenseRank annotation gets destroyed when the queryset is filtered further.

The current implementation creates the rank and data of every user at some point, so it scales poorly the more users we get. I am assuming that we don't have enough users yet for this to be a problem, but it would be nice if we find a better implementation in the long run.

Checklist:

TimJentzsch commented 3 years ago

It might be possible to do this by putting the data in a dictionary first. https://stackoverflow.com/questions/52735708/proper-way-to-annotate-a-rank-field-for-a-queryset But this seems horribly inefficient to me

TimJentzsch commented 2 years ago

Apparently, window expressions are not supported by the test environment so I'll have to find an alternative.