lundi 26 janvier 2015

Selecting, ranking and applying a point score based on rank


I am writing an MVP system based on votes from users. The table will look like



vote | game | year
--------- ------ ------
player 1 | 2 | 2015
player 1 | 2 | 2015
player 2 | 2 | 2015
player 2 | 2 | 2015
player 2 | 2 | 2015
player 3 | 2 | 2015
player 1 | 2 | 2015
player 3 | 2 | 2015
player 4 | 2 | 2015


An entry here equates to a vote. So out of this we would group and get a count of



Player 1 = 3
Player 2 = 3
Player 3 = 2
Player 4 = 1

The MVP system is a "3-2-1" score system. So points are awarded to the players in reverse order. So it should only apply winning scores to the top 3 positions. i.e.



1st gets 3 points
2nd gets 2 points
3rd gets 1 point

This gets really complicated when there is a tie but top 3 should get MVP points.


In the case above the point spread would be


Player 1 = 2.5 points Player 2 = 2.5 points Player 3 = 1 point


This is worked out because the top 2 players are effectively 1st and 2nd, there is no second so the next person gets 1 point for placing 3rd.


Effectively (points = points_available / players_in_rank)


however that equation is wrong. It gets extra complicated if we have a tie for 3rd, where you could possibly end up with lots of people in 3rd spot and therefore they get 1 point divided by them.


It is really complicated when you have ties in 1st or second. I have worked around this poorly in PHP code but would like to be able to do this in SQL and do away with PHP.


Just wondering if anyone has any simple methods for this?


These scores points are then later added to an overall standings table


Regards Dan





Aucun commentaire:

Enregistrer un commentaire