# Thread: Algorithm for most viewed records

1. ## 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.

2. ## 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 $\displaystyle N$ = number of viewing of a particular site, $\displaystyle T_i$ = time (in days) elapsed since the $\displaystyle i^{th}$ viewing (i= 1 for today, i=2 for yesterday, etc), then the score $\displaystyle P$ for that listing would be:

$\displaystyle 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.

3. ## Re: Algorithm for most viewed records

Thank you ebaines,

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

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.

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.