diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index e1861e70a3..c9afad51af 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -243,19 +243,25 @@ function format_numeric($number, $decimals=1) /** * Render numeric data for a graph. It adds magnitude suffix to the number - * (M for millions, K for thousands...) base-10 + * (M for millions, K for thousands...). Base can be modified with divider. * - * TODO: base-2 multiplication - * - * @param float $number Number to be rendered - * @param integer $decimals Numbers after comma. Default value: 1 - * @param dec_point Decimal separator character. Default value: . - * @param thousands_sep Thousands separator character. Default value: , + * @param float $number Number to be rendered. + * @param integer $decimals Numbers after comma (default 1). + * @param string $dec_point Decimal separator character (default .). + * @param string $thousands_sep Thousands separator character (default ,). + * @param integer $divider Number to divide the rendered number. + * @param string $sufix Units of the multiple. * * @return string A string with the number and the multiplier */ -function format_for_graph($number, $decimals=1, $dec_point='.', $thousands_sep=',') -{ +function format_for_graph( + $number, + $decimals=1, + $dec_point='.', + $thousands_sep=',', + $divider=1000, + $sufix='' +) { $shorts = [ '', 'K', @@ -268,15 +274,15 @@ function format_for_graph($number, $decimals=1, $dec_point='.', $thousands_sep=' 'Y', ]; $pos = 0; - while ($number >= 1000) { - // as long as the number can be divided by 1000 + while ($number >= $divider) { + // As long as the number can be divided by divider. $pos++; - // Position in array starting with 0 - $number = ($number / 1000); + // Position in array starting with 0. + $number = ($number / $divider); } - return remove_right_zeros(format_numeric($number, $decimals)).$shorts[$pos]; - // This will actually do the rounding and the decimals + // This will actually do the rounding and the decimals. + return remove_right_zeros(format_numeric($number, $decimals)).$shorts[$pos].$sufix; } diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php index 586023422a..c05eeeceb8 100644 --- a/pandora_console/operation/network/network_report.php +++ b/pandora_console/operation/network/network_report.php @@ -144,22 +144,30 @@ $table = new stdClass(); $table->styleTable = 'width: 100%'; // Print the header. $table->head = []; -$table->head[] = __('IP'); +$table->head['main'] = __('IP'); if (!$is_network) { - $table->head[] = __('Flows'); + $table->head['flows'] = __('Flows'); } -$table->head[] = __('Packets'); -$table->head[] = __('Bytes'); +$table->head['pkts'] = __('Packets'); +$table->head['bytes'] = __('Bytes'); // Print the data. $table->data = []; foreach ($data as $item) { - $table->data[] = [ - $item['host'], + $row = []; + $row['main'] = $item['host']; + $row['pkts'] = format_for_graph($item['sum_pkts'], 2); + $row['bytes'] = format_for_graph( $item['sum_bytes'], - $item['sum_pkts'], - ]; + 2, + '.', + ',', + 1024, + 'B' + ); + + $table->data[] = $row; } html_print_table($table);