Merge branch 'ent-1957-Informe-agrupado-general' into 'develop'

Implemented all-in-row data for grouped general report

See merge request artica/pandorafms!3351
This commit is contained in:
Daniel Rodriguez 2020-07-10 10:11:57 +02:00
commit a83b10ff97
2 changed files with 198 additions and 99 deletions

View File

@ -7506,40 +7506,57 @@ function reporting_general($report, $content)
if ($content['period'] == 0) { if ($content['period'] == 0) {
$data_res[$index] = modules_get_last_value($row['id_agent_module']); $data_res[$index] = modules_get_last_value($row['id_agent_module']);
} else { } else {
if (is_numeric($type_mod) && !$is_string[$index]) { $data_sum = reporting_get_agentmodule_data_sum(
switch ($row['operation']) { $row['id_agent_module'],
case 'sum': $content['period'],
$data_res[$index] = reporting_get_agentmodule_data_sum( $report['datetime']
$row['id_agent_module'], );
$content['period'],
$report['datetime']
);
break;
case 'max': $data_max = reporting_get_agentmodule_data_max(
$data_res[$index] = reporting_get_agentmodule_data_max( $row['id_agent_module'],
$row['id_agent_module'], $content['period']
$content['period'] );
);
break;
case 'min': $data_min = reporting_get_agentmodule_data_min(
$data_res[$index] = reporting_get_agentmodule_data_min( $row['id_agent_module'],
$row['id_agent_module'], $content['period']
$content['period'] );
);
break;
case 'avg': $data_avg = reporting_get_agentmodule_data_average(
default: $row['id_agent_module'],
$data_res[$index] = reporting_get_agentmodule_data_average( $content['period']
$row['id_agent_module'], );
$content['period']
); if ($content['style']['show_in_same_row'] && $content['group_by_agent'] == REPORT_GENERAL_NOT_GROUP_BY_AGENT) {
break; $data_res[$index] = [
} $data_avg,
$data_max,
$data_min,
$data_sum,
];
} else { } 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; break;
} }
// Calculate the avg, min and max if ($content['style']['show_in_same_row']) {
if (is_numeric($data_res[$index]) && !$is_string[$index]) { foreach ($data_res[$index] as $val) {
$change_min = false; // Calculate the avg, min and max
if (is_null($return['min']['value'])) { if (is_numeric($val)) {
$change_min = true; $change_min = false;
} else { if (is_null($return['min']['value'])) {
if ($return['min']['value'] > $data_res[$index]) { $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; $change_min = true;
} else {
if ($return['min']['value'] > $data_res[$index]) {
$change_min = true;
}
} }
}
if ($change_min) { if ($change_min) {
$return['min']['value'] = $data_res[$index]; $return['min']['value'] = $data_res[$index];
$return['min']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); $return['min']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit);
$return['min']['agent'] = $ag_name; $return['min']['agent'] = $ag_name;
$return['min']['module'] = $mod_name; $return['min']['module'] = $mod_name;
} }
$change_max = false; $change_max = false;
if (is_null($return['max']['value'])) { if (is_null($return['max']['value'])) {
$change_max = true;
} else {
if ($return['max']['value'] < $data_res[$index]) {
$change_max = true; $change_max = true;
} else {
if ($return['max']['value'] < $data_res[$index]) {
$change_max = true;
}
} }
}
if ($change_max) { if ($change_max) {
$return['max']['value'] = $data_res[$index]; $return['max']['value'] = $data_res[$index];
$return['max']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit); $return['max']['formated_value'] = format_for_graph($data_res[$index], 2, '.', ',', $divisor, $unit);
$return['max']['agent'] = $ag_name; $return['max']['agent'] = $ag_name;
$return['max']['module'] = $mod_name; $return['max']['module'] = $mod_name;
} }
if ($i == 0) { if ($i == 0) {
$return['avg_value'] = $data_res[$index]; $return['avg_value'] = $data_res[$index];
} else { } else {
$return['avg_value'] = ((($return['avg_value'] * $i) / ($i + 1)) + ($data_res[$index] / ($i + 1))); $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['id_module_type'] = $id_module_types[$i];
$data['operator'] = ''; $data['operator'] = '';
if ($content['period'] != 0) { if ($content['period'] != 0) {
switch ($operations[$i]) { if ($content['style']['show_in_same_row']) {
case 'sum': $data['operator'] = 'all';
$data['operator'] = __('Summatory'); } else {
break; switch ($operations[$i]) {
case 'sum':
$data['operator'] = __('Summatory');
break;
case 'min': case 'min':
$data['operator'] = __('Minimum'); $data['operator'] = __('Minimum');
break; break;
case 'max': case 'max':
$data['operator'] = __('Maximum'); $data['operator'] = __('Maximum');
break; break;
case 'avg': case 'avg':
default: default:
$data['operator'] = __('Rate'); $data['operator'] = __('Rate');
break; break;
}
} }
} }
if ($d === false) { if ($content['style']['show_in_same_row']) {
$data['value'] = null; foreach ($d as $val) {
} else { if ($val === false) {
switch ($config['dbtype']) { $data['value'][] = null;
case 'mysql': } else {
case 'postgresql': switch ($config['dbtype']) {
break; case 'mysql':
case 'postgresql':
break;
case 'oracle': case 'oracle':
if (preg_match('/[0-9]+,[0-9]E+[+-][0-9]+/', $d)) { if (preg_match('/[0-9]+,[0-9]E+[+-][0-9]+/', $val)) {
$d = oracle_format_float_to_php($d); $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]);
}
}
} }
} else {
$divisor = get_data_multiplier($units[$i]); if ($d === false) {
$data['value'] = null;
if (!is_numeric($d) || $is_string[$i]) {
$data['value'] = $d;
// to see the chains on the table
$data['formated_value'] = $d;
} else { } else {
$data['value'] = $d; switch ($config['dbtype']) {
$data['formated_value'] = format_for_graph($d, 2, '.', ',', $divisor, $units[$i]); 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]);
}
} }
} }

View File

@ -3928,10 +3928,10 @@ function reporting_html_general($table, $item, $pdf=0)
$table1->data[] = [ $table1->data[] = [
agents_get_alias($id_agent), agents_get_alias($id_agent),
modules_get_agentmodule_name($id_module), modules_get_agentmodule_name($id_module),
$row2['Rate'], $row2['all'][0],
$row2['Maximum'], $row2['all'][1],
$row2['Minimum'], $row2['all'][2],
$row2['Summatory'], $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('&nbsp;', 20).$item['min']['formated_value']; $table_summary->data[0][0] = $item['min']['agent'].' - '.$item['min']['module'].str_repeat('&nbsp;', 20).$item['min']['formated_value'];
$table_summary->data[0][1] = ''; $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('&nbsp;', 20).$item['max']['formated_value']; $table_summary->data[0][3] = $item['max']['agent'].' - '.$item['max']['module'].str_repeat('&nbsp;', 20).$item['max']['formated_value'];
$table_summary->data[0][4] = ''; $table_summary->data[0][4] = '';