mirror of https://github.com/MISP/MISP
chg: [decaying:base_score_config] Simulation at predicate level in the user interface
parent
41e4c9eca4
commit
15ce397e54
|
@ -277,6 +277,8 @@ class DecayingModel extends AppModel
|
||||||
}
|
}
|
||||||
if (empty($taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'])) {
|
if (empty($taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'])) {
|
||||||
unset($taxonomies[$namespace]['TaxonomyPredicate'][$p]);
|
unset($taxonomies[$namespace]['TaxonomyPredicate'][$p]);
|
||||||
|
} else {
|
||||||
|
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry'] = array_values($taxonomies[$namespace]['TaxonomyPredicate'][$p]['TaxonomyEntry']);
|
||||||
}
|
}
|
||||||
} else { // accept predicates that have a numerical value
|
} else { // accept predicates that have a numerical value
|
||||||
if (!is_numeric($predicate['numerical_value'])) {
|
if (!is_numeric($predicate['numerical_value'])) {
|
||||||
|
@ -288,6 +290,7 @@ class DecayingModel extends AppModel
|
||||||
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['numerical_predicate'] = true;
|
$taxonomies[$namespace]['TaxonomyPredicate'][$p]['numerical_predicate'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (empty($taxonomies[$namespace]['TaxonomyPredicate'])) {
|
if (empty($taxonomies[$namespace]['TaxonomyPredicate'])) {
|
||||||
$excluded_taxonomies[$namespace] = array('taxonomy' => $taxonomies[$namespace], 'reason' => __('No tags nor predicates with `numerical_value`'));
|
$excluded_taxonomies[$namespace] = array('taxonomy' => $taxonomies[$namespace], 'reason' => __('No tags nor predicates with `numerical_value`'));
|
||||||
|
|
|
@ -22,13 +22,13 @@ abstract class DecayingModelBase
|
||||||
}
|
}
|
||||||
$total_score = 0.0;
|
$total_score = 0.0;
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$namespace_predicate = explode(':', $tag['Tag']['name'])[0];
|
$namespace_predicate = explode('=', $tag['Tag']['name'])[0];
|
||||||
if (isset($taxonomy_base_ratio[$namespace_predicate]) && is_numeric($tag['Tag']['numerical_value'])) {
|
if (isset($taxonomy_base_ratio[$namespace_predicate]) && is_numeric($tag['Tag']['numerical_value'])) {
|
||||||
$total_score += floatval($taxonomy_base_ratio[$namespace_predicate]);
|
$total_score += floatval($taxonomy_base_ratio[$namespace_predicate]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($tags as $i => $tag) {
|
foreach ($tags as $i => $tag) {
|
||||||
$namespace_predicate = explode(':', $tag['Tag']['name'])[0];
|
$namespace_predicate = explode('=', $tag['Tag']['name'])[0];
|
||||||
if (isset($taxonomy_base_ratio[$namespace_predicate]) && is_numeric($tag['Tag']['numerical_value'])) {
|
if (isset($taxonomy_base_ratio[$namespace_predicate]) && is_numeric($tag['Tag']['numerical_value'])) {
|
||||||
$ratioScore[$namespace_predicate] = floatval($taxonomy_base_ratio[$namespace_predicate]) / $total_score;
|
$ratioScore[$namespace_predicate] = floatval($taxonomy_base_ratio[$namespace_predicate]) / $total_score;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ abstract class DecayingModelBase
|
||||||
$flag_contain_matching_taxonomy = false;
|
$flag_contain_matching_taxonomy = false;
|
||||||
if (!empty($taxonomy_effective_ratios)) {
|
if (!empty($taxonomy_effective_ratios)) {
|
||||||
foreach ($tags as $k => $tag) {
|
foreach ($tags as $k => $tag) {
|
||||||
$taxonomy = explode(':', $tag['Tag']['name'])[0];
|
$taxonomy = explode('=', $tag['Tag']['name'])[0];
|
||||||
if (isset($taxonomy_effective_ratios[$taxonomy])) {
|
if (isset($taxonomy_effective_ratios[$taxonomy])) {
|
||||||
$flag_contain_matching_taxonomy = true;
|
$flag_contain_matching_taxonomy = true;
|
||||||
$base_score += $taxonomy_effective_ratios[$taxonomy] * $tag['Tag']['numerical_value'];
|
$base_score += $taxonomy_effective_ratios[$taxonomy] * $tag['Tag']['numerical_value'];
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<?php
|
<?php
|
||||||
$registered_taxonomies = array_keys($decaying_model['DecayingModel']['parameters']['base_score_config']);
|
$registered_taxonomies = array_keys($decaying_model['DecayingModel']['parameters']['base_score_config']);
|
||||||
foreach ($registered_taxonomies as $i => &$taxonomy_name) {
|
foreach ($registered_taxonomies as $i => &$taxonomy_name) {
|
||||||
$taxonomy_name = $taxonomy_name . ':%' ;
|
$taxonomy_name = $taxonomy_name . '%' ;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<textarea id="restSearchTextarea">
|
<textarea id="restSearchTextarea">
|
||||||
|
|
|
@ -540,7 +540,7 @@
|
||||||
if (tag === false) {
|
if (tag === false) {
|
||||||
return ['', '', '', this.base_score.toFixed(2)];
|
return ['', '', '', this.base_score.toFixed(2)];
|
||||||
}
|
}
|
||||||
var namespace = tag.Tag.name.split(':')[0];
|
var namespace = tag.Tag.name.split('=')[0];
|
||||||
|
|
||||||
if (this.base_score_config.taxonomy_effective_ratios[namespace] !== undefined) {
|
if (this.base_score_config.taxonomy_effective_ratios[namespace] !== undefined) {
|
||||||
var html1 = this.base_score_config.taxonomy_effective_ratios[namespace].toFixed(2);
|
var html1 = this.base_score_config.taxonomy_effective_ratios[namespace].toFixed(2);
|
||||||
|
|
|
@ -20,7 +20,7 @@ function addPickedTags(clicked) {
|
||||||
var $select = $('#basescore-example-tag-picker');
|
var $select = $('#basescore-example-tag-picker');
|
||||||
var $previous_tags = $('#basescore-example-customtag-container span.decayingExampleTags');
|
var $previous_tags = $('#basescore-example-customtag-container span.decayingExampleTags');
|
||||||
$previous_tags.each(function() {
|
$previous_tags.each(function() {
|
||||||
numerical_values.push({name: $(this).text().split(':')[0], value: parseInt($(this).data('numerical_value'))});
|
numerical_values.push({name: getPrefixTagName($(this).text()), value: parseInt($(this).data('numerical_value'))});
|
||||||
});
|
});
|
||||||
$select.val().forEach(function(tag_id) {
|
$select.val().forEach(function(tag_id) {
|
||||||
var tag = mapping_tag_name_to_tag[tag_id];
|
var tag = mapping_tag_name_to_tag[tag_id];
|
||||||
|
@ -28,7 +28,8 @@ function addPickedTags(clicked) {
|
||||||
var tag_html = '<div style="display: inline-block;" title="numerical_value=' + tag.numerical_value + '"><span class="tagFirstHalf decayingExampleTags" style="background-color: ' + tag.colour + '; color: ' + getTextColour(tag.colour) + ';" data-numerical_value="' + tag.numerical_value + '">' + tag.name + '</span>'
|
var tag_html = '<div style="display: inline-block;" title="numerical_value=' + tag.numerical_value + '"><span class="tagFirstHalf decayingExampleTags" style="background-color: ' + tag.colour + '; color: ' + getTextColour(tag.colour) + ';" data-numerical_value="' + tag.numerical_value + '">' + tag.name + '</span>'
|
||||||
+ '<span class="tagSecondHalf useCursorPointer" onclick="removeCustomTag(this);">×</span></div> '
|
+ '<span class="tagSecondHalf useCursorPointer" onclick="removeCustomTag(this);">×</span></div> '
|
||||||
$('#basescore-example-customtag-container').append(tag_html);
|
$('#basescore-example-customtag-container').append(tag_html);
|
||||||
numerical_values.push({name: tag.name.split(':')[0], value: tag['numerical_value']});
|
var tag_name = getPrefixTagName(tag.name);
|
||||||
|
numerical_values.push({name: tag_name, value: tag['numerical_value']});
|
||||||
});
|
});
|
||||||
base_score_computation[0] = compute_base_score(numerical_values);
|
base_score_computation[0] = compute_base_score(numerical_values);
|
||||||
var base_score = base_score_computation[0].score.toFixed(1);
|
var base_score = base_score_computation[0].score.toFixed(1);
|
||||||
|
@ -45,7 +46,7 @@ function removeCustomTag(clicked) {
|
||||||
var numerical_values = [];
|
var numerical_values = [];
|
||||||
var $previous_tags = $('#basescore-example-customtag-container span.decayingExampleTags');
|
var $previous_tags = $('#basescore-example-customtag-container span.decayingExampleTags');
|
||||||
$previous_tags.each(function() {
|
$previous_tags.each(function() {
|
||||||
numerical_values.push({name: $(this).text().split(':')[0], value: parseInt($(this).data('numerical_value'))});
|
numerical_values.push({name: getPrefixTagName($(this).text()), value: parseInt($(this).data('numerical_value'))});
|
||||||
});
|
});
|
||||||
base_score_computation[0] = compute_base_score(numerical_values);
|
base_score_computation[0] = compute_base_score(numerical_values);
|
||||||
var base_score = base_score_computation[0].score.toFixed(1);
|
var base_score = base_score_computation[0].score.toFixed(1);
|
||||||
|
@ -58,14 +59,24 @@ function regenerateValidTags() {
|
||||||
var $select = $('<select id="basescore-example-tag-picker" multiple="multiple"/>');
|
var $select = $('<select id="basescore-example-tag-picker" multiple="multiple"/>');
|
||||||
Object.keys(taxonomies_with_num_value).forEach(function(taxonomy_name) {
|
Object.keys(taxonomies_with_num_value).forEach(function(taxonomy_name) {
|
||||||
var taxonomy = taxonomies_with_num_value[taxonomy_name];
|
var taxonomy = taxonomies_with_num_value[taxonomy_name];
|
||||||
var $optgroup = $('<optgroup label="' + taxonomy_name + '"></optgroup>');
|
var $optgroup = $('<optgroup></optgroup>').attr('label', taxonomy_name);
|
||||||
taxonomy['TaxonomyPredicate'].forEach(function(predicate) {
|
taxonomy['TaxonomyPredicate'].forEach(function(predicate) {
|
||||||
|
if (predicate['numerical_predicate'] !== undefined && predicate['numerical_predicate']) {
|
||||||
|
mapping_tag_name_to_tag[predicate['Tag']['id']] = predicate['Tag'];
|
||||||
|
var $option = $('<option></option>')
|
||||||
|
.val(predicate['Tag']['id'])
|
||||||
|
.text(predicate['Tag']['name'] + ' [' + predicate['Tag']['numerical_value'] + ']');
|
||||||
|
$optgroup.append($option);
|
||||||
|
} else {
|
||||||
predicate['TaxonomyEntry'].forEach(function(entry) {
|
predicate['TaxonomyEntry'].forEach(function(entry) {
|
||||||
mapping_tag_name_to_tag[entry['Tag']['id']] = entry['Tag'];
|
mapping_tag_name_to_tag[entry['Tag']['id']] = entry['Tag'];
|
||||||
var $option = $('<option value="' + entry['Tag']['id'] + '">' + entry['Tag']['name'] + ' [' + entry['Tag']['numerical_value'] + ']</option>');
|
var $option = $('<option></option>')
|
||||||
|
.val(entry['Tag']['id'])
|
||||||
|
.text(entry['Tag']['name'] + ' [' + entry['Tag']['numerical_value'] + ']');
|
||||||
$optgroup.append($option);
|
$optgroup.append($option);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
$select.append($optgroup);
|
$select.append($optgroup);
|
||||||
});
|
});
|
||||||
return $select;
|
return $select;
|
||||||
|
@ -98,14 +109,27 @@ function getRatioScore(taxonomies_name) {
|
||||||
}
|
}
|
||||||
var ratioScore = {};
|
var ratioScore = {};
|
||||||
total_score = taxonomies_name.reduce(function(acc, name) {
|
total_score = taxonomies_name.reduce(function(acc, name) {
|
||||||
return acc + config[name];
|
var inc = 0;
|
||||||
|
if (config[name] !== undefined) {
|
||||||
|
inc = config[name];
|
||||||
|
}
|
||||||
|
return acc + inc;
|
||||||
}, 0)
|
}, 0)
|
||||||
taxonomies_name.forEach(function(name) {
|
taxonomies_name.forEach(function(name) {
|
||||||
ratioScore[name] = config[name] / total_score;
|
if (config[name] !== undefined) {
|
||||||
|
ratioScore[name] = config[name] / total_score;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return ratioScore;
|
return ratioScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return namespace:predicate for 3-components tagnames and namespace for 2-components tagnames
|
||||||
|
function getPrefixTagName(tag_name) {
|
||||||
|
var temp_tag_name = tag_name.split('='); // split on value
|
||||||
|
var prefix = temp_tag_name.length == 1 ? temp_tag_name[0].split(':')[0] : temp_tag_name[0];
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
function pickRandomTags() {
|
function pickRandomTags() {
|
||||||
var taxonomies_name = Object.keys(fetchTaxonomyConfig());
|
var taxonomies_name = Object.keys(fetchTaxonomyConfig());
|
||||||
var tags = [];
|
var tags = [];
|
||||||
|
@ -224,8 +248,7 @@ function refreshExamples() {
|
||||||
var tags = pickRandomTags();
|
var tags = pickRandomTags();
|
||||||
var tags_html = '<div style="display: flex; flex-flow: wrap;">';
|
var tags_html = '<div style="display: flex; flex-flow: wrap;">';
|
||||||
tags.forEach(function(tag) {
|
tags.forEach(function(tag) {
|
||||||
var temp_tag_name = tag.name.split('=');
|
var tag_name = getPrefixTagName(tag.name);
|
||||||
var tag_name = temp_tag_name.length == 1 ? temp_tag_name[0].split(':')[0] : temp_tag_name[0];
|
|
||||||
numerical_values.push({name: tag_name, value: tag['numerical_value']});
|
numerical_values.push({name: tag_name, value: tag['numerical_value']});
|
||||||
var text_color = getTextColour(tag.colour);
|
var text_color = getTextColour(tag.colour);
|
||||||
tags_html += '<span class="tagComplete decayingExampleTags" style="background-color: ' + tag.colour + ';color:' + text_color + '" '
|
tags_html += '<span class="tagComplete decayingExampleTags" style="background-color: ' + tag.colour + ';color:' + text_color + '" '
|
||||||
|
@ -254,10 +277,12 @@ function compute_base_score(numerical_values) {
|
||||||
computation: []
|
computation: []
|
||||||
};
|
};
|
||||||
numerical_values.forEach(function(tag) {
|
numerical_values.forEach(function(tag) {
|
||||||
|
var coefficient = 0;
|
||||||
if (!isNaN(config[tag.name])) {
|
if (!isNaN(config[tag.name])) {
|
||||||
base_score += config[tag.name] * tag.value;
|
coefficient = config[tag.name];
|
||||||
steps.computation.push({ ratio: config[tag.name], tag_value: tag.value });
|
base_score += coefficient * tag.value;
|
||||||
}
|
}
|
||||||
|
steps.computation.push({ ratio: coefficient, tag_value: tag.value });
|
||||||
});
|
});
|
||||||
return { score: base_score, steps: steps };
|
return { score: base_score, steps: steps };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue