Created
May 1, 2014 19:52
-
-
Save ptte/5c191ae6f955aca7455a to your computer and use it in GitHub Desktop.
This file contains 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 | |
date_default_timezone_set('UTC'); | |
function rampupAlgo($x, $start) { | |
return floor(pow(1.47 * $x, 4) + ($x * $start)); | |
} | |
function rampupExponential($start_time, $end_time, $min, $max, $now) { | |
$diff = $max - $min; | |
$start_unix = strtotime($start_time); | |
$end_unix = strtotime($end_time); | |
$interval = $end_unix - $start_unix; | |
$days = floor($interval / 3600 / 24); | |
$current_day = floor(($now - $start_unix) / 3600 / 24); | |
if ($now > $end_unix) { | |
return $max; | |
} | |
if ($start_unix > $now) { | |
return $min; | |
} | |
// Calc our min / max values for this interval | |
$y_max = rampupAlgo($days, $min); | |
$y_min = rampupAlgo(0, $min); | |
$y_diff = $y_max - $y_min; | |
// What should we be at right now? | |
$y_cur = rampupAlgo($current_day, $min); | |
// try to spread these out over $start -> $end values | |
// we do this by trying to get a rampup "ratio" | |
$rampup = round($y_diff / $diff); | |
$weight = round($y_cur / $rampup); | |
return $weight; | |
} | |
$from_time = '2014-05-1'; | |
$to_time = '2014-05-21'; | |
$start = 0; | |
$end = 100000; | |
for ($y=0;$y<=21;$y++) { | |
$now = time() + 3600 * 24 * $y; // add days | |
echo rampupExponential($from_time, $to_time, $start, $end, $now) . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment