# Help writing a simple algorithm

Hi,
I really need some help implementing an algorithm into my app!
I am trying to work out the popularity of books digg style which users
can vote on. To do this I was think this algorithm might work for the
time being :
Popularity = [ (V1/A1) + (V2/A2) + … + (Vn/An) ] / Book entry Age
Vn is a vote, and An is the age of that vote (for example, in minutes)
and then finally divided by the total time the entry has been on the
website.
What I therefore need help with is the implementation. Firstly will
the code belong in the model or should I create a library and call
that? I need the code to loop through the books votes (self.votes) and
substitute it in the algorithm.
Here's where I got to:
def popularity
res.each do |item|
vote = Hash.new

vote[:date] = item.created_at

end

end
I have no idea how I should move on from here? Any suggestions would
really be appreciated!
Thanks
Ollie

Hi,
I really need some help implementing an algorithm into my app!
I am trying to work out the popularity of books digg style which users
can vote on. To do this I was think this algorithm might work for the
time being :
Popularity = [ (V1/A1) + (V2/A2) + … + (Vn/An) ] / Book entry Age
Vn is a vote, and An is the age of that vote (for example, in minutes)
and then finally divided by the total time the entry has been on the
website.
What I therefore need help with is the implementation. Firstly will
the code belong in the model or should I create a library and call
that?

The code belongs in the Book model.

I need the code to loop through the books votes (self.votes) and
substitute it in the algorithm.
Here's where I got to:
def popularity
res.each do |item|
vote = Hash.new

vote[:date] = item.created_at

end