mirror of https://github.com/MISP/MISP
chg: [decaying] Usage of classname instead of const, support of
`retention` taxonomy and small fixpull/5032/head
parent
beef5012f9
commit
8a6dbd033e
|
@ -277,7 +277,7 @@ class DecayingModel extends AppModel
|
|||
if ($model_class === false) {
|
||||
continue;
|
||||
}
|
||||
$available_formulas[get_class($model_class)] = $model_class::EXTENDS_FORMULA;
|
||||
$available_formulas[get_class($model_class)] = get_parent_class($model_class) == 'Polynomial' || get_class($model_class) == 'Polynomial' ? 'Polynomial' : get_class($model_class);
|
||||
}
|
||||
return $available_formulas;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ class DecayingModel extends AppModel
|
|||
$last_sighting = $this->round_timestamp_to_hour($sightings[$sighting_index]['Sighting']['date_sighting']);
|
||||
$sightings[$sighting_index]['Sighting']['rounded_timestamp'] = $last_sighting;
|
||||
$elapsed_time = $t - $last_sighting;
|
||||
$score_overtime[$t] = $this->Computation->computeScore($model, $attribute, $base_score, $elapsed_time);
|
||||
$score_overtime[$t] = $this->Computation->computeScore($model, $attribute['Attribute'], $base_score, $elapsed_time);
|
||||
}
|
||||
$csv = 'date,value' . PHP_EOL;
|
||||
foreach ($score_overtime as $t => $v) {
|
||||
|
@ -371,7 +371,7 @@ class DecayingModel extends AppModel
|
|||
'sightings' => $sightings,
|
||||
'base_score_config' => $base_score_config,
|
||||
'last_sighting' => $sightings[count($sightings)-1],
|
||||
'current_score' => $this->Computation->computeCurrentScore($user, $model, $attribute, $base_score, $sightings[count($sightings)-1]['Sighting']['date_sighting'])
|
||||
'current_score' => $this->Computation->computeCurrentScore($user, $model, $attribute['Attribute'], $base_score, $sightings[count($sightings)-1]['Sighting']['date_sighting'])
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<?php
|
||||
abstract class DecayingModelBase
|
||||
{
|
||||
public const EXTENDS_FORMULA = '';
|
||||
|
||||
public function checkLoading()
|
||||
{
|
||||
return 'BONFIRE LIT';
|
||||
|
|
|
@ -3,9 +3,6 @@ include_once 'Base.php';
|
|||
|
||||
class Polynomial extends DecayingModelBase
|
||||
{
|
||||
|
||||
public const EXTENDS_FORMULA = 'Polynomial';
|
||||
|
||||
public function computeScore($model, $attribute, $base_score, $elapsed_time)
|
||||
{
|
||||
if ($elapsed_time < 0) {
|
||||
|
|
|
@ -1,10 +1,27 @@
|
|||
<?php
|
||||
include_once 'Base.php';
|
||||
include_once 'Polynomial.php';
|
||||
|
||||
class PolynomialExtended extends DecayingModelBase
|
||||
class PolynomialExtended extends Polynomial
|
||||
{
|
||||
|
||||
public const EXTENDS_FORMULA = 'Polynomial';
|
||||
function __construct() {
|
||||
// setup `retention` taxonomy
|
||||
$this->Taxonomy = ClassRegistry::init('Taxonomy');
|
||||
$retention_taxonomy_id = $this->Taxonomy->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('LOWER(Taxonomy.namespace)' => 'retention'),
|
||||
'fields' => array('id')
|
||||
));
|
||||
if (empty($retention_taxonomy_id)) {
|
||||
throw new Exception(__('`Retention` taxonomy not available'));
|
||||
} else {
|
||||
$retention_taxonomy_id = $retention_taxonomy_id['Taxonomy']['id'];
|
||||
}
|
||||
$taxonomy = $this->Taxonomy->getTaxonomy($retention_taxonomy_id, array('full' => true));
|
||||
$this->retention_taxonomy = array();
|
||||
foreach ($taxonomy['entries'] as $k => $entry) {
|
||||
$this->retention_taxonomy[$entry['tag']] = $entry['numerical_value'];
|
||||
}
|
||||
}
|
||||
|
||||
public function computeScore($model, $attribute, $base_score, $elapsed_time)
|
||||
{
|
||||
|
@ -14,6 +31,21 @@ class PolynomialExtended extends DecayingModelBase
|
|||
$delta = $model['DecayingModel']['parameters']['delta'];
|
||||
$tau = $model['DecayingModel']['parameters']['tau']*24*60*60;
|
||||
$score = $base_score * (1 - pow($elapsed_time / $tau, 1 / $delta));
|
||||
|
||||
// handle `retention` taxonomy tags
|
||||
$temp = $this->__getPrioritizedTag($attribute);
|
||||
$tags = $temp['tags'];
|
||||
foreach ($tags as $tag) {
|
||||
$tagname = $tag['Tag']['name'];
|
||||
if (isset($this->retention_taxonomy[$tagname])) {
|
||||
$timestamp = intval($attribute['timestamp']);
|
||||
$now = time();
|
||||
$eol_time = $this->retention_taxonomy[$tagname] * 24 * 60 * 60; // `retention` taxonomy numerical_value are in seconds
|
||||
if (($now - $timestamp) > $eol_time) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $score < 0 ? 0 : $score;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue