From 5b884e714b1aebe716f89938868fbec95d8a729d Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Thu, 2 Jul 2020 17:00:19 +0200 Subject: [PATCH] Implemented all-in-row data for grouped general report --- .../include/functions_reporting.php | 287 ++++++++++++------ .../include/functions_reporting_html.php | 10 +- 2 files changed, 198 insertions(+), 99 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 65724000f2..366f4e1dfa 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -7506,40 +7506,57 @@ function reporting_general($report, $content) if ($content['period'] == 0) { $data_res[$index] = modules_get_last_value($row['id_agent_module']); } else { - if (is_numeric($type_mod) && !$is_string[$index]) { - switch ($row['operation']) { - case 'sum': - $data_res[$index] = reporting_get_agentmodule_data_sum( - $row['id_agent_module'], - $content['period'], - $report['datetime'] - ); - break; + $data_sum = reporting_get_agentmodule_data_sum( + $row['id_agent_module'], + $content['period'], + $report['datetime'] + ); - case 'max': - $data_res[$index] = reporting_get_agentmodule_data_max( - $row['id_agent_module'], - $content['period'] - ); - break; + $data_max = reporting_get_agentmodule_data_max( + $row['id_agent_module'], + $content['period'] + ); - case 'min': - $data_res[$index] = reporting_get_agentmodule_data_min( - $row['id_agent_module'], - $content['period'] - ); - break; + $data_min = reporting_get_agentmodule_data_min( + $row['id_agent_module'], + $content['period'] + ); - case 'avg': - default: - $data_res[$index] = reporting_get_agentmodule_data_average( - $row['id_agent_module'], - $content['period'] - ); - break; - } + $data_avg = reporting_get_agentmodule_data_average( + $row['id_agent_module'], + $content['period'] + ); + + if ($content['style']['show_in_same_row'] && $content['group_by_agent'] == REPORT_GENERAL_NOT_GROUP_BY_AGENT) { + $data_res[$index] = [ + $data_avg, + $data_max, + $data_min, + $data_sum, + ]; } else { - $data_res[$index] = $type_mod; + if (is_numeric($type_mod) && !$is_string[$index]) { + switch ($row['operation']) { + case 'sum': + $data_res[$index] = $data_sum; + break; + + case 'max': + $data_res[$index] = $data_max; + break; + + case 'min': + $data_res[$index] = $data_min; + break; + + case 'avg': + default: + $data_res[$index] = $data_avg; + break; + } + } else { + $data_res[$index] = $type_mod; + } } } @@ -7581,44 +7598,89 @@ function reporting_general($report, $content) break; } - // Calculate the avg, min and max - if (is_numeric($data_res[$index]) && !$is_string[$index]) { - $change_min = false; - if (is_null($return['min']['value'])) { - $change_min = true; - } else { - if ($return['min']['value'] > $data_res[$index]) { + if ($content['style']['show_in_same_row']) { + foreach ($data_res[$index] as $val) { + // Calculate the avg, min and max + if (is_numeric($val)) { + $change_min = false; + if (is_null($return['min']['value'])) { + $change_min = true; + } else { + if ($return['min']['value'] > $val) { + $change_min = true; + } + } + + if ($change_min) { + $return['min']['value'] = $val; + $return['min']['formated_value'] = format_for_graph($val, 2, '.', ',', $divisor, $unit); + $return['min']['agent'] = $ag_name; + $return['min']['module'] = $mod_name; + } + + $change_max = false; + if (is_null($return['max']['value'])) { + $change_max = true; + } else { + if ($return['max']['value'] < $val) { + $change_max = true; + } + } + + if ($change_max) { + $return['max']['value'] = $val; + $return['max']['formated_value'] = format_for_graph($val, 2, '.', ',', $divisor, $unit); + $return['max']['agent'] = $ag_name; + $return['max']['module'] = $mod_name; + } + + if ($i == 0) { + $return['avg_value'] = $val; + } else { + $return['avg_value'] = ((($return['avg_value'] * $i) / ($i + 1)) + ($val / ($i + 1))); + } + } + } + } else { + // Calculate the avg, min and max + if (is_numeric($data_res[$index]) && !$is_string[$index]) { + $change_min = false; + if (is_null($return['min']['value'])) { $change_min = true; + } else { + if ($return['min']['value'] > $data_res[$index]) { + $change_min = true; + } } - } - if ($change_min) { - $return['min']['value'] = $data_res[$index]; - $return['min']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); - $return['min']['agent'] = $ag_name; - $return['min']['module'] = $mod_name; - } + if ($change_min) { + $return['min']['value'] = $data_res[$index]; + $return['min']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); + $return['min']['agent'] = $ag_name; + $return['min']['module'] = $mod_name; + } - $change_max = false; - if (is_null($return['max']['value'])) { - $change_max = true; - } else { - if ($return['max']['value'] < $data_res[$index]) { + $change_max = false; + if (is_null($return['max']['value'])) { $change_max = true; + } else { + if ($return['max']['value'] < $data_res[$index]) { + $change_max = true; + } } - } - if ($change_max) { - $return['max']['value'] = $data_res[$index]; - $return['max']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); - $return['max']['agent'] = $ag_name; - $return['max']['module'] = $mod_name; - } + if ($change_max) { + $return['max']['value'] = $data_res[$index]; + $return['max']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); + $return['max']['agent'] = $ag_name; + $return['max']['module'] = $mod_name; + } - if ($i == 0) { - $return['avg_value'] = $data_res[$index]; - } else { - $return['avg_value'] = ((($return['avg_value'] * $i) / ($i + 1)) + ($data_res[$index] / ($i + 1))); + if ($i == 0) { + $return['avg_value'] = $data_res[$index]; + } else { + $return['avg_value'] = ((($return['avg_value'] * $i) / ($i + 1)) + ($data_res[$index] / ($i + 1))); + } } } @@ -7693,50 +7755,87 @@ function reporting_general($report, $content) $data['id_module_type'] = $id_module_types[$i]; $data['operator'] = ''; if ($content['period'] != 0) { - switch ($operations[$i]) { - case 'sum': - $data['operator'] = __('Summatory'); - break; + if ($content['style']['show_in_same_row']) { + $data['operator'] = 'all'; + } else { + switch ($operations[$i]) { + case 'sum': + $data['operator'] = __('Summatory'); + break; - case 'min': - $data['operator'] = __('Minimum'); - break; + case 'min': + $data['operator'] = __('Minimum'); + break; - case 'max': - $data['operator'] = __('Maximum'); - break; + case 'max': + $data['operator'] = __('Maximum'); + break; - case 'avg': - default: - $data['operator'] = __('Rate'); - break; + case 'avg': + default: + $data['operator'] = __('Rate'); + break; + } } } - if ($d === false) { - $data['value'] = null; - } else { - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - break; + if ($content['style']['show_in_same_row']) { + foreach ($d as $val) { + if ($val === false) { + $data['value'][] = null; + } else { + switch ($config['dbtype']) { + case 'mysql': + case 'postgresql': + break; - case 'oracle': - if (preg_match('/[0-9]+,[0-9]E+[+-][0-9]+/', $d)) { - $d = oracle_format_float_to_php($d); + case 'oracle': + if (preg_match('/[0-9]+,[0-9]E+[+-][0-9]+/', $val)) { + $val = oracle_format_float_to_php($val); + } + break; } - break; + + $divisor = get_data_multiplier($units[$i]); + + if (!is_numeric($val) || $is_string[$i]) { + $data['value'][] = $val; + + // to see the chains on the table + $data['formated_value'][] = $val; + } else { + $data['value'][] = $val; + $data['formated_value'][] = format_for_graph($val, 2, '.', ',', $divisor, $units[$i]); + } + } } - - $divisor = get_data_multiplier($units[$i]); - - if (!is_numeric($d) || $is_string[$i]) { - $data['value'] = $d; - // to see the chains on the table - $data['formated_value'] = $d; + } else { + if ($d === false) { + $data['value'] = null; } else { - $data['value'] = $d; - $data['formated_value'] = format_for_graph($d, 2, '.', ',', $divisor, $units[$i]); + switch ($config['dbtype']) { + case 'mysql': + case 'postgresql': + break; + + case 'oracle': + if (preg_match('/[0-9]+,[0-9]E+[+-][0-9]+/', $d)) { + $d = oracle_format_float_to_php($d); + } + break; + } + + $divisor = get_data_multiplier($units[$i]); + + if (!is_numeric($d) || $is_string[$i]) { + $data['value'] = $d; + + // to see the chains on the table + $data['formated_value'] = $d; + } else { + $data['value'] = $d; + $data['formated_value'] = format_for_graph($d, 2, '.', ',', $divisor, $units[$i]); + } } } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 2ef9586f12..2e556b30b8 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -3928,10 +3928,10 @@ function reporting_html_general($table, $item, $pdf=0) $table1->data[] = [ agents_get_alias($id_agent), modules_get_agentmodule_name($id_module), - $row2['Rate'], - $row2['Maximum'], - $row2['Minimum'], - $row2['Summatory'], + $row2['all'][0], + $row2['all'][1], + $row2['all'][2], + $row2['all'][3], ]; } } @@ -4014,7 +4014,7 @@ function reporting_html_general($table, $item, $pdf=0) $table_summary->data[0][0] = $item['min']['agent'].' - '.$item['min']['module'].str_repeat(' ', 20).$item['min']['formated_value']; $table_summary->data[0][1] = ''; - $table_summary->data[0][2] = format_for_graph($item['avg_value'], 2); + $table_summary->data[0][2] = $item['avg_value']; $table_summary->data[0][3] = $item['max']['agent'].' - '.$item['max']['module'].str_repeat(' ', 20).$item['max']['formated_value']; $table_summary->data[0][4] = '';