I’m trying to implement something in my app akin to 43things’ main
page, where more active topics are bigger than the less active topics.
The difference in my app is that I’m building a business-oriented app
and want to have a list of clients, where clients with recent activity
are larger than others.
My perhaps too-clever way of going about this is by feeding each job
belonging to a client through an equation that gives an exponentially
degrading score based on date of the job, then summing these scores
for a final score. The equation is y=[5/(x-4)]^2, where y is the score
and x is the number of weeks ago from today.
My question, then, is how best to implement this. I could, of course,
loop through every client, retrieve all of their jobs from the last X
months, run the equation on each of them and then sum that, but that
is a whole lotta database calls. Is there a way to do this with eager
loading or something database-side? Or is there an altogether simpler
way to achieve the same results?
I’m deploying in on a Linux machine I control, so I can use any
database I please so long as its free. My schema consists of a Clients
table with name, address, etc. and a Jobs table with a timestamp and
foreign key back to the client.