Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created October 21, 2009 13:59
Show Gist options
  • Save hugowetterberg/215123 to your computer and use it in GitHub Desktop.
Save hugowetterberg/215123 to your computer and use it in GitHub Desktop.
Computing score changes based on half-life
<?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