From 46f6b92360b7544b5e4cf76a4d066b3a2e2b305f Mon Sep 17 00:00:00 2001 From: mokaddem Date: Thu, 22 Aug 2019 15:56:32 +0200 Subject: [PATCH] chg: [decaying] Better Inheritance and comments --- app/Model/DecayingModelsFormulas/Base.php | 8 +++++--- .../DecayingModelsFormulas/PolynomialExtended.php | 10 ++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/Model/DecayingModelsFormulas/Base.php b/app/Model/DecayingModelsFormulas/Base.php index 8a44fe986..79145fb24 100644 --- a/app/Model/DecayingModelsFormulas/Base.php +++ b/app/Model/DecayingModelsFormulas/Base.php @@ -11,7 +11,8 @@ abstract class DecayingModelBase return 'BONFIRE LIT'; } - // get effective taxonomy ratio based on taxonomies attached to the attribute + // Get effective taxonomy ratio based on taxonomies attached to the attribute + // Basically, it adapts the ratio defined in the model to fit the actual attached tags protected function __getRatioScore($model, $tags) { $ratioScore = array(); @@ -89,7 +90,7 @@ abstract class DecayingModelBase return array('base_score' => $base_score, 'overridden' => $overridden_tags, 'tags' => $tags, 'taxonomy_effective_ratios' => $taxonomy_effective_ratios, 'default_base_score' => $default_base_score); } - // compute the current score for the provided attribute according to the last sighting with the provided model + // Compute the current score for the provided attribute according to the last sighting with the provided model final public function computeCurrentScore($user, $model, $attribute, $base_score = false, $last_sighting_timestamp = false) { if ($base_score === false) { @@ -111,8 +112,9 @@ abstract class DecayingModelBase return $this->computeScore($model, $attribute, $base_score, $timestamp - $last_sighting_timestamp); } - // compute the score for the provided attribute according to the elapsed time with the provided model + // Compute the score for the provided attribute according to the elapsed time with the provided model abstract public function computeScore($model, $attribute, $base_score, $elapsed_time); + // Return a True if the attribute should be marked as decayed abstract public function isDecayed($model, $attribute, $score); } diff --git a/app/Model/DecayingModelsFormulas/PolynomialExtended.php b/app/Model/DecayingModelsFormulas/PolynomialExtended.php index 7f0e547a7..cc4aa5f30 100644 --- a/app/Model/DecayingModelsFormulas/PolynomialExtended.php +++ b/app/Model/DecayingModelsFormulas/PolynomialExtended.php @@ -27,12 +27,7 @@ class PolynomialExtended extends Polynomial public function computeScore($model, $attribute, $base_score, $elapsed_time) { - if ($elapsed_time < 0) { - return 0; - } - $decay_speed = $model['DecayingModel']['parameters']['decay_speed']; - $lifetime = $model['DecayingModel']['parameters']['lifetime']*24*60*60; - $score = $base_score * (1 - pow($elapsed_time / $lifetime, 1 / $decay_speed)); + $score = parent::computeScore($model, $attribute, $base_score, $elapsed_time); // handle `retention` taxonomy tags $temp = $this->__getPrioritizedTag($attribute); @@ -53,8 +48,7 @@ class PolynomialExtended extends Polynomial public function isDecayed($model, $attribute, $score) { - $threshold = $model['DecayingModel']['parameters']['threshold']; - return $threshold > $score; + return parent::isDecayed($model, $attribute, $score); } } ?>