chg: [decaying:simulation] Alert user if base_score has not been

configured yet
pull/5032/head
mokaddem 2019-07-18 09:58:11 +02:00
parent 5bdf48981c
commit c73547f89f
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 31 additions and 11 deletions

View File

@ -239,6 +239,9 @@ class DecayingModel extends AppModel
{
$ratioScore = array();
$taxonomy_base_ratio = $model['DecayingModel']['parameters']['base_score_config'];
if (empty($taxonomy_base_ratio)) {
return array();
}
$total_score = 0.0;
foreach ($tags as $tag) {
$namespace_predicate = explode(':', $tag['Tag']['name'])[0];
@ -283,10 +286,12 @@ class DecayingModel extends AppModel
$tags = $temp['tags'];
$overridden_tags = $temp['overridden'];
$taxonomy_effective_ratios = $this->_getRatioScore($model, $tags);
$base_score = 0;
foreach ($tags as $k => $tag) {
$taxonomy = explode(':', $tag['Tag']['name'])[0];
$base_score += $taxonomy_effective_ratios[$taxonomy] * $tag['Tag']['numerical_value'];
$base_score = isset($model['DecayingModel']['parameters']['base_score_config']['base_score_default_value']) ? $model['DecayingModel']['parameters']['base_score_config']['base_score_default_value'] : 0 ;
if (!empty($taxonomy_effective_ratios)) {
foreach ($tags as $k => $tag) {
$taxonomy = explode(':', $tag['Tag']['name'])[0];
$base_score += $taxonomy_effective_ratios[$taxonomy] * $tag['Tag']['numerical_value'];
}
}
return array('base_score' => $base_score, 'overridden' => $overridden_tags, 'tags' => $tags, 'taxonomy_effective_ratios' => $taxonomy_effective_ratios);
}

View File

@ -56,7 +56,10 @@
<div style="width: 80%; display: flex;">
<div class="panel-container" style="flex-grow: 1; display: flex;">
<div id="basescore-simulation-container" style="width: 30%; height: 100%;">
<h5><?php echo __('Basescore') ?></h5>
<h5 style="display: inline-block;"><?php echo __('Base score') ?></h5>
<div id="alert-basescore-not-set" class="alert alert-warning" style="display: inline-block; margin-bottom: auto; margin-left: 5px; padding: 4px 8px;">
<strong><?php echo __('Base score configuration'); ?></strong> <?php echo __('not set') ?>
</div>
<div style="overflow: auto; position: relative;">
<?php echo $this->element('DecayingModels/View/basescore_computation_steps'); ?>
</div>
@ -148,10 +151,10 @@ function doSimulation(clicked, attribute_id) {
$(clicked).addClass('success');
var model_id = $('#select_model_to_simulate').val();
var simulation_chart = $('#simulation_chart').data('DecayingSimulation');
var simulation_table = $('#basescore-simulation-container #computation_help_container_body ').data('BasescoreComputationTable');
var simulation_table = $('#basescore-simulation-container #computation_help_container_body').data('BasescoreComputationTable');
if (simulation_chart === undefined) {
simulation_chart = $('#simulation_chart').decayingSimulation({});
simulation_table = $('#basescore-simulation-container #computation_help_container_body ').basescoreComputationTable({});
simulation_table = $('#basescore-simulation-container #computation_help_container_body').basescoreComputationTable({});
}
$.ajax({
beforeSend:function() {
@ -161,6 +164,13 @@ function doSimulation(clicked, attribute_id) {
success:function (data, textStatus) {
simulation_chart.update(data, models[model_id]);
simulation_table.update(data, models[model_id]);
if (Object.keys(data.base_score_config.taxonomy_effective_ratios).length > 0) { // show alert base_score not set
$('#alert-basescore-not-set').hide('fade', {}, 250);
$('#basescore-simulation-container #computation_help_container_body tr').removeClass('warning');
} else {
$('#alert-basescore-not-set').show('fade', {}, 250);
$('#basescore-simulation-container #computation_help_container_body tr').addClass('warning');
}
$('#simulation-sighting')
.text(
d3.time.format("%c")(new Date(parseInt(data.last_sighting.Sighting.date_sighting)*1000))

View File

@ -397,8 +397,8 @@
_create_tag_html: function(tag) {
if (tag !== false) {
return '<span class="tag" style="background-color:' + tag.Tag.colour + '; color: ' + getTextColour(tag.Tag.colour) + '">' + tag.Tag.name + '</span>';
} else {
return '';
} else { // last row
return '<span style="border-radius: 4px; border: 1px solid #ccc; background-color: #eeeeee; padding: 4px 5px;">base_score</span>';
}
},
@ -408,10 +408,15 @@
}
var namespace = tag.Tag.name.split(':')[0];
var html1 = this.base_score_config.taxonomy_effective_ratios[namespace].toFixed(2);
if (this.base_score_config.taxonomy_effective_ratios[namespace] !== undefined) {
var html1 = this.base_score_config.taxonomy_effective_ratios[namespace].toFixed(2);
var html4 = (parseFloat(tag.Tag.numerical_value) * this.base_score_config.taxonomy_effective_ratios[namespace]).toFixed(2);
} else {
var html1 = '0';
var html4 = '0';
}
var html2 = '*';
var html3 = parseFloat(tag.Tag.numerical_value).toFixed(2);
var html4 = (parseFloat(tag.Tag.numerical_value) * this.base_score_config.taxonomy_effective_ratios[namespace]).toFixed(2);
return [html1, html2, html3, html4];
},