0

I would like to create a list of items that are 'trending'. By 'trending' I mean nodes (in my case, Watches) that have been highly rated within the last several days. Right now I have a block that displays the 4 highest rated Watches, and would like to create a similar block that displays the 4 highest rated Watches, but only using votes that have been cast within the last 3 days.

For the trending block, I have the following filter criteria (the content type for a watch is Watch Detail):

  • Content: Published (Yes)
  • Content: Type (= Watch Detail)
  • (Vote results) Vote results: Timestamp (>= -3 days)

The watches are sorted by highest rated using the following sort critera:

  • (Vote results) Vote results: Value (desc)

It's a fairly standard view, and I used the Relationship Content: Vote results to access the voting results for sorting and filtering.

The problem with what I've done is that while it is filtering by watches that have received votes within the last 3 days, it is not calculating the average value of the rating on votes that have been cast in the last 3 days. It is using the rating of the watch since the watch node was created. Hence, the Trending block and the Top Rated block essentially are identical, since the rating isn't limited to the last 3 days.

If anyone has done something like this I would very much appreciate some tips for how to limit the calculation the the average vote value to only votes cast within the last 3 days.

See http://ratemytimepiece.com/ for the exact website I'm working on if that helps you visualize this a little better.

3

Fivestar uses voting API. Voting API stores the individual votes and the total aggregates. You'll either have to create your own aggregates or calculate it "on the fly".

If you have lots of ratings in a week you'll be better off calculating your own aggregates. I would take a look how voting API does the calculation and copy that to your own module. Then modify it to only aggregate votes in the last week.

If you don't have a lot of ratings you can do it in views. Create a view of your type "watch detail". Add relationship "content: votes", require relationship, value type "percent", vote tag (whatever vote tag you are using for those fivestar ratings). Then add filter "votes: value" >= 80 (gives you all 4 + 5 star ratings), "votes: timestamp" > "-1 week". Check to make sure you'll see the correct ratings show up.

Now turn on aggregation, add "nid" and use "count distinct" to show the number of ratings for each node. Then sort by that value.

Turn on query caching to make sure the view renders quickly for future requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.