📜 ⬆️ ⬇️

Algorithm rating sheet.

Kind time of the day, dear habroskoobschestvo.
In the process of creating a single project, I ran into the problem of implementing user ratings. In principle, it is possible to draw an analogy with Habr. The fact is that the user is ranked according to an unknown algorithm and gets some kind of indicator (habrasila, we will call it a rank). After that, a sheet is formed, ordered by decrease of this indicator. It seems to be all simple.It seems that everything looks, there is no place easier. But here there are several problems. The second problem, in theory, depends on the first. After all, knowing the user's position and the number of displayed on the page, we can calculate exactly which part of the rating it is.
_ = ___( / __ )
But then the question arises, how to calculate the position? It should be relevant to all other users.
One of the solutions is a separate script, run once in a certain period of time, which will make a huge selection from the database with order by rank (meaning that it is always relevant). Then we assign a sequence number to each record and save it to the database. The option is working, but has significant drawbacks.The thought comes to mind that the calculation of the position should occur at the time of opening the user profile. At the same time, he should not make complex database queries. This would solve all the tasks, but how to implement this, I do not know. The topic was posted in order to deal with the task along with Habrazhiteli. There are a lot of people who can help and no less that it will be interesting to know. So we are waiting for comments. The text will be updated as something becomes clearer.

UPD. Eyes proposed a solution for determining position on the fly. Since we already have a field in the user table with the rank parameter, to determine the user's position, we just need to make select count (*) ... where ... and rank> user_rank.

UPD 2 With the solution found, a new problem has appeared. How to separate users with the same rating? After all, the number of users with a higher rating is the same for them.
You can just not pay attention to it and give them the same place. This is done on Habré. For example, you can look at the profiles of these users: NooL and Zada . I do not know how long they will hold out on an equal footing, but the point is that they are both in the 983th ranking.
In theory, it is even more correct, there is no discrimination between users with the same rating, but how then to refer to the middle of the list without knowing the exact position?
')
PS I know that Habr is not a forum, but I am very much interested in resolving the task, which makes the carmorisk justified.

Source: https://habr.com/ru/post/46355/


All Articles