From 0af82fd69dba62c28c213d9290cfcf8214d4f511 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 12 Jun 2017 17:48:42 +0200 Subject: [PATCH] Added some code to manage timestamps in chart data --- pandora_console/include/functions_graph.php | 93 ++++++++------------- 1 file changed, 35 insertions(+), 58 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index c456373746..a735860542 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -255,7 +255,11 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i for ($i = 0; $i <= $resolution; $i++) { $timestamp = $datelimit + ($interval * $i); - + + if ($fullscale) { + $timestamp = $data[$i]['utimestamp']; + } + $total = 0; $count = 0; @@ -263,24 +267,26 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i $interval_min = false; $interval_max = false; - while (isset ($data[$data_i]) && $data[$data_i]['utimestamp'] >= $timestamp && $data[$data_i]['utimestamp'] < ($timestamp + $interval)) { - if ($interval_min === false) { - $interval_min = $data[$data_i]['datos']; + if (!$fullscale) { + while (isset ($data[$data_i]) && $data[$data_i]['utimestamp'] >= $timestamp && $data[$data_i]['utimestamp'] < ($timestamp + $interval)) { + if ($interval_min === false) { + $interval_min = $data[$data_i]['datos']; + } + if ($interval_max === false) { + $interval_max = $data[$data_i]['datos']; + } + + if ($data[$data_i]['datos'] > $interval_max) { + $interval_max = $data[$data_i]['datos']; + } + else if ($data[$data_i]['datos'] < $interval_min) { + $interval_min = $data[$data_i]['datos']; + } + $total += $data[$data_i]['datos']; + $last_known = $data[$data_i]['datos']; + $count++; + $data_i++; } - if ($interval_max === false) { - $interval_max = $data[$data_i]['datos']; - } - - if ($data[$data_i]['datos'] > $interval_max) { - $interval_max = $data[$data_i]['datos']; - } - else if ($data[$data_i]['datos'] < $interval_min) { - $interval_min = $data[$data_i]['datos']; - } - $total += $data[$data_i]['datos']; - $last_known = $data[$data_i]['datos']; - $count++; - $data_i++; } if ($max_value < $interval_max) { @@ -692,7 +698,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, foreach ($chart as $c_timestamp => $c_data) { $timestamp_short = date($time_format, $c_timestamp); $new_long_index[$timestamp_short] = date( - html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $c_timestamp); + html_entity_decode($time_format, ENT_QUOTES, "UTF-8"), $c_timestamp); $new_chart[$timestamp_short] = $c_data; } @@ -3771,6 +3777,10 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events, $last_known = $previous_data; for ($i = 0; $i <= $resolution; $i++) { $timestamp = $datelimit + ($interval * $i); + + if ($fullscale) { + $timestamp = $data[$i]['utimestamp']; + } $zero = 0; $total = 0; @@ -4078,55 +4088,22 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events, if ($fullscale) { if (!$flash_chart) { - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = "M \nd H:i"; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = "M \nd H\h"; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M \nd H\h"; - } - else { - $time_format = "M Y"; - } + $time_format = "Y M \nd H:i:s"; } else { - // Set the title and time format - if ($period <= SECONDS_6HOURS) { - $time_format = 'H:i:s'; - } - elseif ($period < SECONDS_1DAY) { - $time_format = 'H:i'; - } - elseif ($period < SECONDS_15DAYS) { - $time_format = "M d H:i"; - } - elseif ($period < SECONDS_1MONTH) { - $time_format = "M d H\h"; - } - elseif ($period < SECONDS_6MONTHS) { - $time_format = "M d H\h"; - } - else { - $time_format = "M Y"; - } + $time_format = "Y M d H:i:s"; } $new_chart = array(); + $new_long_index = array(); foreach ($chart as $c_timestamp => $c_data) { $timestamp_short = date($time_format, $c_timestamp); - + $new_long_index[$timestamp_short] = date( + html_entity_decode($time_format, ENT_QUOTES, "UTF-8"), $c_timestamp); $new_chart[$timestamp_short] = $c_data; } + $long_index = $new_long_index; $chart = $new_chart; }