mirror of https://github.com/MISP/MISP
chg: [decaying] Allow for model parameteres override
parent
6ba45b27f8
commit
05fe5e18e8
|
@ -1871,7 +1871,7 @@ class AttributesController extends AppController
|
|||
'timestamp', 'enforceWarninglist', 'to_ids', 'deleted', 'includeEventUuid', 'event_timestamp', 'threat_level_id', 'includeEventTags',
|
||||
'includeProposals', 'returnFormat', 'published', 'limit', 'page', 'requested_attributes', 'includeContext', 'headerless',
|
||||
'includeWarninglistHits', 'attackGalaxy', 'object_relation', 'includeSightings', 'includeCorrelations', 'includeDecayScore',
|
||||
'decayingModel', 'excludeDecayed'
|
||||
'decayingModel', 'excludeDecayed', 'modelOverrides'
|
||||
);
|
||||
$filterData = array(
|
||||
'request' => $this->request,
|
||||
|
|
|
@ -387,7 +387,7 @@ class DecayingModelController extends AppController
|
|||
'value' , 'type', 'category', 'org', 'tags', 'from', 'to', 'last', 'eventid', 'withAttachments', 'uuid', 'publish_timestamp',
|
||||
'timestamp', 'enforceWarninglist', 'to_ids', 'deleted', 'includeEventUuid', 'event_timestamp', 'threat_level_id', 'includeEventTags',
|
||||
'includeProposals', 'returnFormat', 'published', 'limit', 'page', 'requested_attributes', 'includeContext', 'headerless',
|
||||
'includeWarninglistHits', 'attackGalaxy', 'object_relation', 'id', 'includeDecayScore', 'decayingModel', 'excludeDecayed'
|
||||
'includeWarninglistHits', 'attackGalaxy', 'object_relation', 'id', 'includeDecayScore', 'decayingModel', 'excludeDecayed', 'modelOverrides'
|
||||
);
|
||||
$filterData = array(
|
||||
'request' => $this->request,
|
||||
|
@ -499,7 +499,8 @@ class DecayingModelController extends AppController
|
|||
if (empty($filters['decayingModel'])) {
|
||||
$filters['decayingModel'] = false;
|
||||
}
|
||||
$this->DecayingModel->attachScoresToAttribute($this->Auth->user(), $attributes[$k]['Attribute'], $filters['decayingModel']);
|
||||
$model_overrides = isset($filters['modelOverrides']) ? $filters['modelOverrides'] : array();
|
||||
$this->DecayingModel->attachScoresToAttribute($this->Auth->user(), $attributes[$k]['Attribute'], $filters['decayingModel'], $model_overrides);
|
||||
if ($filters['excludeDecayed']) { // filter out decayed attribute
|
||||
$decayed_flag = true;
|
||||
foreach ($attributes[$k]['Attribute']['decay_score'] as $decayResult) {
|
||||
|
@ -527,9 +528,16 @@ class DecayingModelController extends AppController
|
|||
if (!$this->request->is('ajax')) {
|
||||
throw new MethodNotAllowedException(__("This method is only accessible via AJAX."));
|
||||
}
|
||||
|
||||
$model_overrides = array();
|
||||
if (isset($this->params['named']['modelOverride'])) {
|
||||
$model_overrides = $this->params['named']['modelOverride'];
|
||||
$model_overrides = json_decode($model_overrides, true);
|
||||
if ($model_overrides === null) {
|
||||
$model_overrides = array();
|
||||
}
|
||||
}
|
||||
// contain score overtime, sightings, and base_score computation
|
||||
$results = $this->DecayingModel->getScoreOvertime($this->Auth->user(), $model_id, $attribute_id);
|
||||
$results = $this->DecayingModel->getScoreOvertime($this->Auth->user(), $model_id, $attribute_id, $model_overrides);
|
||||
return $this->RestResponse->viewData($results, $this->response->type());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3268,7 +3268,7 @@ class Attribute extends AppModel
|
|||
}
|
||||
if ($options['includeDecayScore']) {
|
||||
$this->DecayingModel = ClassRegistry::init('DecayingModel');
|
||||
$this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel']);
|
||||
$this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel'], $options['modelOverrides']);
|
||||
if ($options['excludeDecayed']) { // filter out decayed attribute
|
||||
$decayed_flag = true;
|
||||
foreach ($results[$key]['Attribute']['decay_score'] as $decayResult) {
|
||||
|
@ -4274,6 +4274,9 @@ class Attribute extends AppModel
|
|||
if (!empty($filters['decayingModel'])) {
|
||||
$params['decayingModel'] = $filters['decayingModel'];
|
||||
}
|
||||
if (!empty($filters['modelOverrides'])) {
|
||||
$params['modelOverrides'] = $filters['modelOverrides'];
|
||||
}
|
||||
if ($paramsOnly) {
|
||||
return $params;
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ class DecayingModel extends AppModel
|
|||
return $time - $offset;
|
||||
}
|
||||
|
||||
public function getScoreOvertime($user, $model_id, $attribute_id)
|
||||
public function getScoreOvertime($user, $model_id, $attribute_id, $model_overrides)
|
||||
{
|
||||
$this->Attribute = ClassRegistry::init('Attribute');
|
||||
$attribute = $this->Attribute->fetchAttributesSimple($user, array(
|
||||
|
@ -332,6 +332,9 @@ class DecayingModel extends AppModel
|
|||
if ($model === false) {
|
||||
throw new NotFoundException(__('Model not found'));
|
||||
}
|
||||
if (!empty($model_overrides)) {
|
||||
$this->overrideModelParameters($model, $model_overrides);
|
||||
}
|
||||
$this->Computation = $this->getModelClass($model);
|
||||
$this->Sighting = ClassRegistry::init('Sighting');
|
||||
$sightings = $this->Sighting->listSightings($user, $attribute_id, 'attribute', false, 0, false);
|
||||
|
@ -371,7 +374,8 @@ 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['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']),
|
||||
'Model' => $model['DecayingModel']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -393,11 +397,24 @@ class DecayingModel extends AppModel
|
|||
return $next_index-1;
|
||||
}
|
||||
|
||||
public function attachScoresToAttribute($user, &$attribute, $model_id=false)
|
||||
public function overrideModelParameters(&$model, $model_overrides)
|
||||
{
|
||||
$allowed_overrides = array('threshold' => 1);
|
||||
foreach ($model_overrides as $parameter => $value) {
|
||||
if (isset($allowed_overrides[$parameter])) {
|
||||
$model['DecayingModel']['parameters'][$parameter] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function attachScoresToAttribute($user, &$attribute, $model_id=false, $model_overrides=array())
|
||||
{
|
||||
if ($model_id !== false) {
|
||||
$model = $this->checkAuthorisation($user, $model_id, false);
|
||||
if ($model !== false) {
|
||||
if (!empty($model_overrides)) {
|
||||
$this->overrideModelParameters($model, $model_overrides);
|
||||
}
|
||||
$score = $this->getScore($attribute, $model, $user);
|
||||
$decayed = $this->isDecayed($attribute, $model, $score);
|
||||
$attribute['decay_score'][] = array('DecayingModel' => $model['DecayingModel'], 'score' => $score, 'decayed' => $decayed);
|
||||
|
|
|
@ -131,6 +131,13 @@ $(document).ready(function() {
|
|||
|
||||
function doRestSearch(clicked, query) {
|
||||
var data = query === undefined ? $(clicked).parent().find('textarea').val() : query;
|
||||
var json;
|
||||
try {
|
||||
json = JSON.parse(data);
|
||||
} catch (SyntaxError) {
|
||||
showMessage('fail', 'Invalid JSON syntax');
|
||||
return;
|
||||
}
|
||||
fetchFormDataAjax('/decayingModel/decayingToolRestSearch/', function(formData) {
|
||||
var $formData = $(formData);
|
||||
url = $formData.find('form').attr('action');
|
||||
|
@ -147,6 +154,10 @@ function doRestSearch(clicked, query) {
|
|||
if ($trs.length == 1) {
|
||||
$trs.click();
|
||||
}
|
||||
// pass potential model overrides
|
||||
if (json.modelOverrides !== undefined) {
|
||||
$trs.data('modelOverride', JSON.stringify(json.modelOverrides));
|
||||
}
|
||||
},
|
||||
error:function() {
|
||||
showMessage('fail', '<?php echo __('Failed to perform RestSearch') ?>');
|
||||
|
@ -185,14 +196,19 @@ function doSimulation(clicked, attribute_id) {
|
|||
if (simulation_table === undefined) {
|
||||
simulation_table = $('#basescore-simulation-container #computation_help_container_body').basescoreComputationTable({});
|
||||
}
|
||||
var url = '/decayingModel/decayingToolComputeSimulation/' + model_id + '/' + attribute_id;
|
||||
var model_override = $(clicked).data('modelOverride');
|
||||
if (model_override !== undefined) {
|
||||
url += '/modelOverride:' + model_override;
|
||||
}
|
||||
$.ajax({
|
||||
beforeSend:function() {
|
||||
simulation_chart.toggleLoading(true);
|
||||
simulation_table.toggleLoading(true);
|
||||
},
|
||||
success:function (data, textStatus) {
|
||||
simulation_chart.update(data, models[model_id]);
|
||||
simulation_table.update(data, models[model_id]);
|
||||
simulation_chart.update(data, data.Model);
|
||||
simulation_table.update(data, data.Model);
|
||||
if (Object.keys(data.base_score_config.taxonomy_effective_ratios).length > 0) { // show alert base_score not set
|
||||
$('#alert-basescore-not-set').hide();
|
||||
$('#alert-basescore-not-set.alert-error').hide();
|
||||
|
@ -231,7 +247,7 @@ function doSimulation(clicked, attribute_id) {
|
|||
type:'get',
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
url: '/decayingModel/decayingToolComputeSimulation/' + model_id + '/' + attribute_id,
|
||||
url: url,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,6 @@
|
|||
if (that.resize_timeout !== undefined) {
|
||||
clearTimeout(that.resize_timeout);
|
||||
}
|
||||
console.log(that.options.redraw_timeout);
|
||||
that.resize_timeout = setTimeout(function() { that.redraw_timeout_handler(that) }, that.options.redraw_timeout);
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue