Voting/Rating Algorithm

Discussion in 'Programming' started by sanaa-s-1971, Feb 26, 2009.

  1. #1
    Hey guys,

    Just looking for some advice on developing a voting/rating algorithm.

    What is the most effective way to develop this?

    Right now, I am using minimalistic/very simple algorithm, I have two columns: Num_Votes and Vote_Total, and the rating is Num_Votes/Vote_Total.

    Problem is, it can be easily skewed if their are a low number of votes (1 vote of 5 will boost them to a 5 star rating).

    Thanks guys!
     
    sanaa-s-1971, Feb 26, 2009 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    $total_stars_to_show = 5;
    
    $total_voters   = 16; #assumed
    $total_ratings  = 47; #assumed
    
    $average = ($total_ratings / $total_voters) * $total_stars_to_show;
    PHP:
    Now it also depends upton the width of the image you use tod display a star. For example width per star image is 10 pixels, then you will create a <span of $average * 10, which will be in code as:

    $positive = (int)($average * 10);
    PHP:
    and populating the two spans first for positive feedback and remaining the negative, thus:

    $total_width = 10 * $total_stars_to_show;
    $negative = $tota_width - $positive;
    PHP:
    $positive:$negative
    -------------------
    +++++++:---------
    -------------------

    CSS

    Assuming height of image too is 10 pixels.

    .Cpositive {
        background-color:blue;
        background-image:url("positive_star.gif");
        height:10px;
    }
    .Cnegative {
        background-color:gray;
        background-image:url("negative_star.gif");
        background-position:top right;
        height:10px;
    }
    HTML:

    PHP

    echo "<span class=\"Cpositive\" style=\"width:{$positive}px\">
    echo "<span class=\"Cnegative\" style=\"width:{$negative}px\">
    PHP:


    I hope it helps, if this is what you required.
     
    Vooler, Feb 27, 2009 IP
  3. sanaa-s-1971

    sanaa-s-1971 Peon

    Messages:
    213
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    so does it work better.
    for example. i had a video rated 4 times and it had 4 stars, and a video that hadnt had any ratings and i rated it a 5 star and it became the top rated video.. but it really wasnt due to 1 vote and the other video had 4 votes..

    i want to fix that problem... any way?
     
    sanaa-s-1971, Feb 27, 2009 IP
  4. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #4
    It is assumed that single vote might have rating 1-5.. Sorr for late reply.
     
    Vooler, Mar 3, 2009 IP
  5. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #5
    You need to remember voter ip address and do not allow him to vote again and again.
     
    it career, Mar 3, 2009 IP
  6. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    NeoCambell, Mar 10, 2010 IP
  7. rupaYa

    rupaYa Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks neo, you always help me.
     
    rupaYa, Mar 14, 2010 IP
  8. petergombos

    petergombos Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is exactly what I've been looking for too! Thanks man!
     
    petergombos, Nov 13, 2010 IP
  9. dansari

    dansari Well-Known Member

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    108
    #9
    That's a really good post - I should look into it for improving my own website!

    A simple alternative (but not as good) is to show the number of ratings along with the average rating, then the user will see which ratings are more reliable.
     
    dansari, Nov 16, 2010 IP