2019-08-13 14:21:58 +02:00
< ? php
2019-08-13 15:27:11 +02:00
include_once 'Polynomial.php' ;
2019-08-13 14:21:58 +02:00
2019-08-13 15:27:11 +02:00
class PolynomialExtended extends Polynomial
2019-08-13 14:21:58 +02:00
{
2019-08-13 15:27:11 +02:00
function __construct () {
2019-09-12 16:33:19 +02:00
$this -> description = __ ( 'The implementation of the decaying formula from the paper `An indicator scoring method for MISP platforms` with support of the `Retention` taxonomy which overrides the final score.' );
2019-09-12 11:28:32 +02:00
2019-08-13 15:27:11 +02:00
// 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' ];
}
2022-09-25 19:48:11 +02:00
$taxonomy = $this -> Taxonomy -> getTaxonomy ( $retention_taxonomy_id );
2019-08-13 15:27:11 +02:00
$this -> retention_taxonomy = array ();
foreach ( $taxonomy [ 'entries' ] as $k => $entry ) {
$this -> retention_taxonomy [ $entry [ 'tag' ]] = $entry [ 'numerical_value' ];
}
}
2019-08-13 14:21:58 +02:00
public function computeScore ( $model , $attribute , $base_score , $elapsed_time )
{
2019-08-22 15:56:32 +02:00
$score = parent :: computeScore ( $model , $attribute , $base_score , $elapsed_time );
2019-08-13 15:27:11 +02:00
// handle `retention` taxonomy tags
2019-09-12 11:46:12 +02:00
$temp = $this -> __getPrioritisedTag ( $attribute );
2019-08-13 15:27:11 +02:00
$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 ;
}
}
}
2019-08-13 14:21:58 +02:00
return $score < 0 ? 0 : $score ;
}
public function isDecayed ( $model , $attribute , $score )
{
2019-08-22 15:56:32 +02:00
return parent :: isDecayed ( $model , $attribute , $score );
2019-08-13 14:21:58 +02:00
}
}