def _with_age(score, time): freshness = 1 if score > -1: age = timedelta2seconds(datetime.utcnow() - time) freshness = max(1, math.log10(max(1, max_age - age))) str_time = "%020d" % datetime2seconds(time) str_score_freshness = "%029.10f" % (freshness * score) return str_score_freshness + str_time
def _with_age(score, time, impact=0): if score > -1: age = timedelta2seconds(datetime.utcnow() - time) # freshness = 1 .. 5.2 if max_age == 2 days freshness = math.log10(max(10, max_age - age)) else: freshness = 1 # atan normalizes to -pi/2 .. +pi/2 base = math.atan(freshness * score) # add impact assert -10 <= impact <= 10 result = base + impact * math.pi str_time = "%020d" % datetime2seconds(time) str_score_freshness = "%029.10f" % (result) return str_score_freshness + str_time