Merge branch 'ent-6478-Bug-en-la-vista-HTML-y-PDF-de-los-items-AVG-MAX-MIN-Value-de-informes-y-templates' into 'develop'

fixed report avg-min-max

See merge request artica/pandorafms!3540
This commit is contained in:
Daniel Rodriguez 2020-10-28 15:19:32 +01:00
commit 318094d758
3 changed files with 189 additions and 32 deletions

View File

@ -4979,6 +4979,16 @@ function reporting_agent_configuration($report, $content)
}
/**
* Report Min, Max and Avg.
*
* @param array $report Info report.
* @param array $content Content report.
* @param string $type Type report.
* @param boolean $pdf Is pdf.
*
* @return array Data draw report.
*/
function reporting_value($report, $content, $type, $pdf=false)
{
global $config;
@ -4993,16 +5003,17 @@ function reporting_value($report, $content, $type, $pdf=false)
$return['type'] = 'min_value';
break;
case 'avg':
$return['type'] = 'avg_value';
break;
case 'sum':
$return['type'] = 'sumatory';
break;
case 'avg':
default:
$return['type'] = 'avg_value';
break;
}
if (empty($content['name'])) {
if (empty($content['name']) === true) {
switch ($type) {
case 'max':
$content['name'] = __('Max. Value');
@ -5012,17 +5023,18 @@ function reporting_value($report, $content, $type, $pdf=false)
$content['name'] = __('Min. Value');
break;
case 'avg':
$content['name'] = __('AVG. Value');
break;
case 'sum':
$content['name'] = __('Summatory');
break;
case 'avg':
default:
$content['name'] = __('AVG. Value');
break;
}
}
if ($config['metaconsole']) {
if (is_metaconsole() === true) {
$id_meta = metaconsole_get_id_server($content['server_name']);
$server = metaconsole_get_connection_by_id($id_meta);
@ -5060,14 +5072,15 @@ function reporting_value($report, $content, $type, $pdf=false)
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
$only_image = false;
if ($pdf) {
$only_image = 1;
$only_image = true;
}
$params = [
'agent_module_id' => $content['id_agent_module'],
'period' => $content['period'],
'width' => '600px',
'width' => '90%',
'pure' => false,
'date' => $report['datetime'],
'only_image' => $only_image,
@ -5086,6 +5099,7 @@ function reporting_value($report, $content, $type, $pdf=false)
case 'max':
case 'min':
case 'avg':
default:
$divisor = get_data_multiplier($unit);
if ($content['lapse_calc'] == 0) {
@ -5107,6 +5121,7 @@ function reporting_value($report, $content, $type, $pdf=false)
break;
case 'avg':
default:
$value = reporting_get_agentmodule_data_average(
$content['id_agent_module'],
$content['period'],
@ -5118,7 +5133,14 @@ function reporting_value($report, $content, $type, $pdf=false)
if (!$config['simple_module_value']) {
$formated_value = $value;
} else {
$formated_value = format_for_graph($value, $config['graph_precision'], '.', ',', $divisor, $unit);
$formated_value = format_for_graph(
$value,
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
}
} else {
$return['visual_format'] = $content['visual_format'];
@ -5126,17 +5148,51 @@ function reporting_value($report, $content, $type, $pdf=false)
switch ($type) {
case 'max':
$params['force_interval'] = 'max_only';
$value = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision'], '.', ',', $divisor, $unit);
$value = format_for_graph(
reporting_get_agentmodule_data_max(
$content['id_agent_module'],
$content['period'],
$report['datetime']
),
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
break;
case 'min':
$params['force_interval'] = 'min_only';
$value = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision'], '.', ',', $divisor, $unit);
$value = format_for_graph(
reporting_get_agentmodule_data_min(
$content['id_agent_module'],
$content['period'],
$report['datetime']
),
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
break;
case 'avg':
default:
$params['force_interval'] = 'avg_only';
$value = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision'], '.', ',', $divisor, $unit);
$value = format_for_graph(
reporting_get_agentmodule_data_average(
$content['id_agent_module'],
$content['period'],
$report['datetime']
),
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
break;
}
@ -5166,15 +5222,49 @@ function reporting_value($report, $content, $type, $pdf=false)
if ($i > $time_begin['utimestamp']) {
switch ($type) {
case 'max':
$row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['lapse'], ($i + $content['lapse'])), $config['graph_precision'], '.', ',', $divisor, $unit);
$row[__('Maximun')] = format_for_graph(
reporting_get_agentmodule_data_max(
$content['id_agent_module'],
$content['lapse'],
($i + $content['lapse'])
),
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
break;
case 'min':
$row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['lapse'], ($i + $content['lapse'])), $config['graph_precision'], '.', ',', $divisor, $unit);
$row[__('Maximun')] = format_for_graph(
reporting_get_agentmodule_data_min(
$content['id_agent_module'],
$content['lapse'],
($i + $content['lapse'])
),
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
break;
case 'avg':
$row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['lapse'], ($i + $content['lapse'])), $config['graph_precision'], '.', ',', $divisor, $unit);
default:
$row[__('Maximun')] = format_for_graph(
reporting_get_agentmodule_data_average(
$content['id_agent_module'],
$content['lapse'],
($i + $content['lapse'])
),
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
break;
}
} else {
@ -5185,7 +5275,7 @@ function reporting_value($report, $content, $type, $pdf=false)
}
}
if ($config['metaconsole']) {
if (is_metaconsole() === true) {
metaconsole_restore_db();
}
@ -5205,7 +5295,14 @@ function reporting_value($report, $content, $type, $pdf=false)
} else {
$divisor = get_data_multiplier($unit);
$formated_value = format_for_graph($value, $config['graph_precision'], '.', ',', $divisor, $unit);
$formated_value = format_for_graph(
$value,
$config['graph_precision'],
'.',
',',
$divisor,
$unit
);
}
break;
}
@ -5215,7 +5312,7 @@ function reporting_value($report, $content, $type, $pdf=false)
'formated_value' => $formated_value,
];
if ($config['metaconsole']) {
if (is_metaconsole() === true) {
metaconsole_restore_db();
}

View File

@ -2971,8 +2971,26 @@ function reporting_html_min_value(&$table, $item, $mini)
}
function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_empty=false)
{
/**
* Htlm report AVg, min, Max, Only.
*
* @param array $table Table.
* @param array $item Data.
* @param boolean $mini Is mini.
* @param boolean $only_value Only value.
* @param boolean $check_empty Empty.
* @param integer $pdf PDF Mode.
*
* @return string Html output.
*/
function reporting_html_value(
$table,
$item,
$mini,
$only_value=false,
$check_empty=false,
$pdf=0
) {
global $config;
if ($mini) {
@ -2981,8 +2999,12 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
$font_size = $config['font_size_item_report'].'em';
}
if (isset($item['visual_format']) && $item['visual_format'] != 0
&& ($item['type'] == 'max_value' || $item['type'] == 'min_value' || $item['type'] == 'avg_value')
$return_pdf = '';
if (isset($item['visual_format']) === true && $item['visual_format'] != 0
&& ($item['type'] == 'max_value'
|| $item['type'] == 'min_value'
|| $item['type'] == 'avg_value')
) {
$table2 = new stdClass();
$table2->width = '100%';
@ -3004,6 +3026,7 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
break;
case 'avg_value':
default:
$table2->head = [
__('Agent'),
__('Module'),
@ -3031,15 +3054,28 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
$table->colspan[2][0] = 3;
$table->colspan[3][0] = 3;
array_push($table->data, html_print_table($table2, true));
if ($pdf === 0) {
array_push($table->data, html_print_table($table2, true));
} else {
$return_pdf .= html_print_table($table2, true);
}
unset($item['data'][0]);
if ($item['visual_format'] != 1) {
$value = $item['data'][1]['value'];
array_push($table->data, $value);
unset($item['data'][1]);
if ($pdf === 0) {
array_push($table->data, $value);
} else {
$style_div_pdf = 'text-align:center;margin-bottom:20px;';
$return_pdf .= '<div style="'.$style_div_pdf.'">';
$return_pdf .= $value;
$return_pdf .= '</div>';
}
}
unset($item['data'][1]);
if ($item['visual_format'] != 2) {
$table1 = new stdClass();
$table1->width = '100%';
@ -3059,6 +3095,7 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
break;
case 'avg_value':
default:
$table1->head = [
__('Lapse'),
__('Average'),
@ -3067,8 +3104,9 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
}
$table1->data = [];
$row = [];
foreach ($item['data'] as $data) {
if (!is_numeric($data[__('Maximun')])) {
if (is_numeric($data[__('Maximun')]) === false) {
$row = [
$data[__('Lapse')],
$data[__('Maximun')],
@ -3076,7 +3114,12 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
} else {
$row = [
$data[__('Lapse')],
remove_right_zeros(number_format($data[__('Maximun')], $config['graph_precision'])),
remove_right_zeros(
number_format(
$data[__('Maximun')],
$config['graph_precision']
)
),
];
}
@ -3086,10 +3129,22 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
if ($pdf === 0) {
array_push($table->data, html_print_table($table1, true));
} else {
$return_pdf .= html_print_table($table1, true);
}
}
array_push($table->data, html_print_table($table1, true));
if ($pdf !== 0) {
return $return_pdf;
}
} else {
if ($pdf !== 0) {
$table = new stdClass();
$table->width = '100%';
}
$table->colspan['data']['cell'] = 3;
$table->cellstyle['data']['cell'] = 'text-align: left;';
@ -3104,6 +3159,10 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
}
$table->data['data']['cell'] .= '</p>';
if ($pdf !== 0) {
return html_print_table($table, true);
}
}
}

View File

@ -1480,6 +1480,7 @@ table.databox {
padding: 9px 7px;
font-weight: normal;
color: #fff;
text-align: justify;
}
.databox > th * {