📜 ⬆️ ⬇️

The algorithm of the user's popularity on the site - “Non-standard approach to standard things”

Everyone has seen on the sites a system of rating articles and materials. Many even did it themselves, but not everyone made a rating of people on the site.
In this article I will tell you how to make a high-quality rating system for users of your resource.



First, I will draw a line for you of different rating algorithms:
I - Users receive only "+"
Main advantages:
Disadvantages:

II - Users get "+" and "-"
There are few big differences from the previous system. Added another field in the database.
Main advantages:
Disadvantages:
')
III - hyperbole from @ klim-danilovklim-danilov
Yes, this is a rather interesting idea but for the evaluation of the material. But not users.
Main advantages:
Disadvantages:

IV - statistical average
One of the most common systems. The basis is the total amount of voters and the total score divided by each other.
Main advantages:
Disadvantages:

V - floating system
The principle is based on the change of karma in the direction of plus or minus.
Main advantages:
Disadvantages:

Now I will do my bit.
Why reinvent the wheel was when there are already algorithms for assessing people?
- And the answer is simple, they are not correct when there is a conversation about the need to highlight the truly authoritative people in the resource.

The algorithm is based on the geometric shape of a "right triangle".
Yes, sometimes in geometry we can find quite unusual things.

Why was the triangle chosen?
The fact is that the height of the triangle can correspond to the rating of the user who puts the assessment.
The length of the triangle rated which is rated. And the hypotenuse is just that difference between user authorities.

Now we will start the most interesting.
$a = 254; //    $b = 47; //     /*   ,      */ if($b<=0){ $b=1; } /*         $b */ ###     * 2 ### $aInSquare = ($a * 2) * ($a * 2); /*   ,        2 ?   ,       $a    2 ,       */ ###    B ### $bInSquare = $b * $b; ###    ### $cInSquare = $bInSquare + $aInSquare; ###   ### $c = sqrt($cInSquare); $result = (int) round($c / $b); /*        $b             int */ if($result > $b / 2){ $result = (int) round($b / 2); } /*        .      ,      50% */ var_dump($result); /*       11,        . */ ?> 

Maybe someone will ask. And why did not use the formula $ result = ($ a * 2) / $ b ;?
This formula does not work adequately when $ a is less than $ b by more than 2 times.

Within a couple of months I will finish writing the project (I will write about this after a closed beta test).
The algorithm will be tested on a real project where it is critically necessary.

Total:

After thousands of tests with $ a = rand (0.99999); $ b = rand (0.99999);
I came to a couple of bugs:
1st - divide by 0.
Fixed if ($ b <= 0) {$ b = 1; }

2nd - when the receiving user has 1 point, and receives from the user with 1000, then the volume of the resulting one becomes 2000
Fixed if ($ result> $ b / 2) {$ result = (int) round ($ b / 2); } The maximum can be increased by 50%.

The Code-Igniter benchmark did not yield load results (0.0000).

Thanks to all. Look for inspiration in everything you see.

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


All Articles