Skip to content

Instantly share code, notes, and snippets.

@satwikkansal
Last active March 22, 2016 20:01
Show Gist options
  • Save satwikkansal/d6570e2c6d75fb5b4ac0 to your computer and use it in GitHub Desktop.
Save satwikkansal/d6570e2c6d75fb5b4ac0 to your computer and use it in GitHub Desktop.
Ranking of exploration request for oppia
from datetime import datetime, timedelta
from math import log
epoch = datetime(1970, 1, 1)
def epoch_seconds(date):
td = date - epoch
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000)
def rank(ups, downs, date):
#downs denote the no. of users who marked it inappropriate/incomplete.
score = ups
ups_order = log(max(abs(score), 1), 10)
# downs should scale more than ups
downs_order = log(max(abs(downs), 1), 5)
order = ups_order - downs_order
#Duration since the request has been posted
seconds = epoch_seconds(date) - 1134028003
seconds_order = 10*log(max(seconds, 1), 2)
return round(order + seconds_order, 7)
""" Test run
def input_date() :
dd = int(raw_input("\n Enter day"))
mm = int(raw_input("\n Enter month"))
yyyy = int(raw_input("\n Enter year"))
return datetime(yyyy,mm,dd)
def test():
date = input_date()
ups = int(raw_input("\n Upvotes"))
downs = int(raw_input("\n Downs"))
print rank(ups, downs, date)
while(True):
test()
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment