Created
October 21, 2009 13:59
-
-
Save hugowetterberg/215123 to your computer and use it in GitHub Desktop.
Computing score changes based on half-life
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$half_time_24h = pow(0.5, 1/24); | |
$total = 1000; | |
$score = 700; | |
$last_update = time() - (3600*1.5); // One and a half hour ago | |
$new_total = 1010; | |
$total_delta = $new_total - $total; | |
$hour_delta = (time() - $last_update) / 3600; | |
$score = add_and_decay($score, $half_time_24h, $hour_delta, $total_delta); | |
function add_and_decay($old_score, $hourly_decay, $hour_delta, $add) { | |
return $old_score * pow($hourly_decay, $hour_delta) + $add; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment