Jump to content

Recommended Posts

Lets say I have may different images on my website, how could I list them in order of popularity, what would the database structure look like? what make an image popular? Is it the total amount of views? Views per day? Ratio between time and views? Just general ideas and help of this guys :) anything that comes into your mind.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/220988-how-to-calculate-popularity/
Share on other sites

In the simplest form a simple INT field on your image database table to store a count of the number of times an image is viewed. You may want to check the users IP before incrementing the value as you do not want the same user to keep clicking and incrementing the counter.

I would record the IP addresses and images clicked in another table and probably purge once a day as it will quickly fill up with  lots of entries.

You can then select images with the highest count as the most popular.

 

If you want to do clicks per day then you could have another INT field to record this and have a cron job reset it to 0 at midnight.

Most viewed doesn't necessarily mean most popular. 

 

In order to rank by popularity, you need to implement a rating system, a way for users to rate the pictures.  You would have them rate a picture 1-5 stars (or 1-10 scale or however  you want it, doesn't really matter). 

 

What your database structure will look like largely depends on the details of how your db is setup for current data, details of how you want the rating system to work, and how much data you expect to be getting.  But as an example to illustrate the principle, you would have a table in your database that looks something like this:

 

[pre]

pic_ratings

pic_id user_id rating

1        1          4

1        2          3

1        3          4

2        1          2

2        2          5

2        3          3

[/pre]

 

So basically for example when user1 rates picture1 4 stars, a row is added to the table.  If you want the users to only vote once per picture, you would first check this table to see if there is an entry where pic_id = current pic and user_id = current user.  To get a top ten by rating, you would do a query like so:

 

select round(avg(rating)) as rating,pic_id from pic_ratings group by pic_id order by rating desc limit 10

 

This will return a list of the picture ids and their average rating. 

 

 

 

 

The problem with doing that, is that it is statistically inaccurate for small data sets. Which is more likely to be the most popular item? Item A, which has a score of 4.8 with 100 votes, or item B with a score of 5.0, but only 2 votes?

 

So the question you want to ask is, if item B had as many votes as item A, how would their ratings compare?

 

Simply using the arithmetic mean is not sufficient for determining relative popularity amongst multiple items. When using a rating scale like this, you can use the Bayesian average instead.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.