# Algorithm for most viewed records

• Jul 31st 2012, 05:37 AM
NotionCommotion
Algorithm for most viewed records
I want to show the top 10 most viewed records on a per user basis. It also needs to be time biased where records viewed long ago carry little weight. The application consists of a user logging onto a private site and viewing real estate opportunities, and having their individual "popular" records displayed when they initially log on.

One thought was to associate a "rank" for each user/record pair. Every time the record is viewed, the current rank value is decreased based on the age of the rank value, but then increased because it was just viewed.

Any advise would be much appreciated.
• Jul 31st 2012, 07:54 AM
ebaines
Re: Algorithm for most viewed records
Personally I think the easiest and most intuitive for the user is to simply rank in order by when the most recent viewing was, and not worry about how many times the listing has been previously seen. Perhaps let the user flag particular listings as being of interest, so that they come to the top regardlesss of when it was last viewed. However, you asked for an algoithm that weighs the time since the most recent viewing together with the number of viewings to produce a score, then rank the listings by score. It all depends how you feel the relative weight of time versus frequency should be handled. For example - if I viewed one listing 4 times last week and not since, and I viewed a second listing just once yesterday, which should score higher? if I viewed a third listing 100 timnes last year but not since how should that be ranked?

Here's one approach - don't know if it matches what you're expecting, but if you keep track of all viewings by date for each user then you could produce a score for each listing that would be calculated as follows. Let $N$ = number of viewing of a particular site, $T_i$ = time (in days) elapsed since the $i^{th}$ viewing (i= 1 for today, i=2 for yesterday, etc), then the score $P$ for that listing would be:

$P = \sum _{i=1} ^{N} \frac 1 {T_i}$

In this systen one viewing today scores 1 point, which equals 2 viewings yesterday but is less than one viewing yesterday plus 2 viewing 2 days ago.
• Jul 31st 2012, 05:54 PM
NotionCommotion
Re: Algorithm for most viewed records
Thank you ebaines,

Quote:

let the user flag particular listings as being of interest
Nothing to do with math, but with humans! Would rather not add the complexity.

Quote:

It all depends how you feel the relative weight of time versus frequency should be handled
Yea, I know and didn't know how to deal with it.

Quote:

Here's one approach
Doesn't account for how many times viewed per day, but that can easily be added. I would also want to limit N to something reasonable so not to waste computer time on insignificant results. The big question is what are the constants that you eluded on your earlier point about how I/we/you feel the relative weight of time versus frequency should be handled. Don't know. Hoping someone has done research on this.