CookdIt.Com never featured a ranking algorithm that took into account a users participation in the site, so I decided to add one.

The logic behind the code calculator was as follows:

  1. Total Link contributions
  2. Total comment contributions
  3. Average naturalised T-Score of the votes for links submitted
  4. Total the above and get the log10()

This might not be the best way to go about it, but it produces nice, logarithmic slopes that go up in short units to increase a users score.

The code to produce the vote score looks like this:

def calculate_vote(user):
    uRecipes = Recipes.objects.filter(Owner=user)
    uComments = Reviews.objects.filter(Owner=user)
    numrec = len(uRecipes)
    numcomm = len(uComments)
    recTscore = calcT(uRecipes)
    tot = numrec + numcomm + recTscore
    voteweight = log10(tot)
    return voteweight

Then the T-Scores (normalised z-scores) were caluclated using:

def calcT(uRecipes):
    mylen = len(uRecipes)
    tot = 0
    for rec in uRecipes:
        tot += rec.VotesTotal
    mean = tot / mylen
    totssd = 0
    tempsd = 0
    for rec_sd in uRecipes:
        tempsd = (rec_sd.VotesTotal - mean)^2
        totssd += tempsd
    sd = totssd / mylen
    T = 0
    totT = 0
    for rec2 in uRecipes:
        T = 50 + (10*(rec.VotesTotal - mean))/sd
        totT += T
    avgT = totT / mylen
    return avgT


The overall algorithm is really inneficient because we need to loop through recipe’s 2 times! However, I think a modifcation to how the database is updated (to keep track of averages etc.) may be the solution to keeping track of scores and not have to re-iterate through entire object collections.

However, the other nifty thing here is that it’s all done using integer division, so essentially vote updates are always whole numbers and getting to a higher ‘plane’ means a user would need to contribute more each time.

I’m not a mathematician, and my statistics is pretty sloppy at best, so any recommendations on how ti improve this will be welcomed!