Last active
August 29, 2015 13:56
-
-
Save bcole808/9280115 to your computer and use it in GitHub Desktop.
Increase a float and then slowly reduce the amount of the increase until there is no longer an increase applied.
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 | |
/*************************************************** | |
* This function takes in a float and returns a float that has been incrased based on the number of days elapsed since creation | |
* The purpose is to boost a number that is newer and slowly decrease that boost until it is no longer applied after the active period has ended. | |
***************************************************/ | |
// Number of days the boost is active - Bounded by 0 and the | |
// beginning of the sauce degradation phase. | |
define(ACTIVE_PERIOD, (float) 5); | |
// Function that controls the popularity of young posts | |
function score_boost($social_score, $days_elapsed){ | |
settype($social_score, "float"); | |
settype($days_elapsed, "float"); | |
// Does not allow the Active Period to overlap sauce's decay period | |
if(ACTIVE_PERIOD <= 0 || ACTIVE_PERIOD >= 7) | |
throw new Exception('Invalid Activity Length'); | |
// Does not allow boosting beyond the active period | |
if ($days_elapsed > ACTIVE_PERIOD) | |
throw new Exception('Boost no longer active.'); | |
$k = $social_score/(ACTIVE_PERIOD*ACTIVE_PERIOD); | |
return $k*($days_elapsed - ACTIVE_PERIOD)*($days_elapsed - ACTIVE_PERIOD) + $social_score; | |
} | |
// Example: | |
try { | |
echo score_boost(14.1, 1), "\n"; | |
} catch (Exception $e) { | |
echo 'Caught exception: ', $e->getMessage(), "\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment