From a23663a7818fa7ee807a6cd79a859546fb8e0525 Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Thu, 27 Oct 2011 11:27:49 +0000 Subject: [PATCH] 2011-10-27 Juan Manuel Ramon * godmode/reporting/reporting_builder.item_editor.php: Added 1 week interval for SLA reports. Fixes: #3426516 * include/functions_forecast.php include/functions_reporting.php godmode/reporting/reporting_builder.php godmode/reporting/reporting_builder.item_editor.php: Changed precission to float of max and min intervals on prediction date report. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5086 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 14 ++ .../reporting_builder.item_editor.php | 19 +-- .../godmode/reporting/reporting_builder.php | 123 +++++++++++------- .../include/functions_forecast.php | 6 +- .../include/functions_reporting.php | 5 +- 5 files changed, 111 insertions(+), 56 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 0b7d661229..1f9db346de 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,17 @@ +2011-10-27 Juan Manuel Ramon + + * godmode/reporting/reporting_builder.item_editor.php: Added 1 week + interval for SLA reports. + + Fixes: #3426516 + + * include/functions_forecast.php + include/functions_reporting.php + godmode/reporting/reporting_builder.php + godmode/reporting/reporting_builder.item_editor.php: Changed + precission to float of max and min intervals on prediction date + report. + 2011-10-27 Juan Manuel Ramon * godmode/agentes/agent_manager.php: Added confirmation at delete diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index b807ce3466..dd8d08947f 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -56,8 +56,8 @@ $period_pg = 432000; $projection_period = 432000; $only_display_wrong = 0; // Added support for prediction date report -$min_interval = 0; -$max_interval = 0; +$min_interval = '0.00'; +$max_interval = '0.00'; $monday = true; $tuesday = true; $wednesday = true; @@ -123,8 +123,12 @@ switch ($action) { $idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $idAgentModule)); // 'top_n' field will be reused for prediction_date report $max_interval = $item['top_n']; - // 'top_n_value' field will be reused for prediction_date report $min_interval = $item['top_n_value']; + $intervals_text = $item['text']; + // Parse intervals text field + $max_interval = substr($intervals_text, 0, strpos($intervals_text, ';')); + $min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1); + // 'top_n_value' field will be reused for prediction_date report $period_pg = $item['period']; break; case 'custom_graph': @@ -317,15 +321,14 @@ $intervals[300] = human_time_description_raw (300); $intervals[600] = human_time_description_raw (600); $intervals[86400] = human_time_description_raw (86400); $intervals[432000] = human_time_description_raw (432000); +$intervals[604800] = human_time_description_raw (604800); $intervals[1296000] = human_time_description_raw (1296000); $intervals[2592000] = human_time_description_raw (2592000); // Intervals for projection graph $intervals_1 = array (); -/*$intervals_1[300] = human_time_description_raw (300); -$intervals_1[600] = human_time_description_raw (600); -$intervals_1[86400] = human_time_description_raw (86400);*/ $intervals_1[432000] = human_time_description_raw (432000); +$intervals_1[604800] = human_time_description_raw (604800); $intervals_1[1296000] = human_time_description_raw (1296000); $intervals_1[2592000] = human_time_description_raw (2592000); $intervals_1[5184000] = human_time_description_raw (5184000); @@ -374,9 +377,9 @@ html_print_input_hidden('id_item', $idItem); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index ca3021ebbb..821382ccbc 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -184,6 +184,7 @@ switch ($action) { $reportName = $report['name']; $idGroupReport = $report['id_group']; $description = $report['description']; + $good_format = false; switch ($action) { case 'update': $values = array(); @@ -191,22 +192,33 @@ switch ($action) { $values['description'] = get_parameter('description'); $values['type'] = get_parameter('type', null); // Added support for projection graphs and prediction_date reports - // 'top_n_value' and 'top_n' fields will be reused for these types of report + // 'top_n_value','top_n' and 'text' fields will be reused for these types of report if ($values['type'] == 'projection_graph'){ $values['period'] = get_parameter('period1'); $values['top_n_value'] = get_parameter('period2'); + $values['text'] = get_parameter('text'); + $good_format = true; }else if($values['type'] == 'prediction_date'){ $values['period'] = get_parameter('period1'); - $values['top_n'] = get_parameter('max_interval'); - $values['top_n_value'] = get_parameter('min_interval'); + $values['top_n'] = get_parameter('radiobutton_max_min_avg'); + $values['top_n_value'] = get_parameter('quantity'); + $interval_max = get_parameter('max_interval'); + $interval_min = get_parameter('min_interval'); + // Checks intervals fields + if (preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_max) and preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_min)){ + $good_format = true; + } + $intervals = get_parameter('max_interval') . ';' . get_parameter('min_interval'); + $values['text'] = $intervals; }else{ $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg'); $values['top_n_value'] = get_parameter('quantity'); + $values['text'] = get_parameter('text'); + $good_format = true; } $values['id_agent'] = get_parameter('id_agent'); $values['id_gs'] = get_parameter('id_custom_graph'); - $values['text'] = get_parameter('text'); $values['id_agent_module'] = get_parameter('id_agent_module'); $values['only_display_wrong'] = get_parameter('checkbox_only_display_wrong'); $values['monday'] = get_parameter('monday', 0); @@ -263,8 +275,13 @@ switch ($action) { $style['show_in_two_columns'] = get_parameter('show_in_two_columns', 0); $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); $values['style'] = io_safe_input(json_encode($style)); - - $resultOperationDB = db_process_sql_update('treport_content', $values, array('id_rc' => $idItem)); + + if ($good_format){ + $resultOperationDB = db_process_sql_update('treport_content', $values, array('id_rc' => $idItem)); + } + else{ + $resultOperationDB = false; + } break; case 'save': $values = array(); @@ -272,22 +289,33 @@ switch ($action) { $values['type'] = get_parameter('type', null); $values['description'] = get_parameter('description'); // Support for projection graph and prediction_date reports - // 'top_n_value' and 'top_n' fields will be reused for these types of report + // 'top_n_value', 'top_n' and 'text' fields will be reused for these types of report if ($values['type'] == 'projection_graph'){ $values['period'] = get_parameter('period1'); $values['top_n_value'] = get_parameter('period2'); + $values['text'] = get_parameter('text'); + $good_format = true; }else if ($values['type'] == 'prediction_date'){ - $values['period'] = get_parameter('period1'); - $values['top_n'] = get_parameter('max_interval'); - $values['top_n_value'] = get_parameter('min_interval'); + $values['period'] = get_parameter('period1'); + $values['top_n'] = get_parameter('radiobutton_max_min_avg'); + $values['top_n_value'] = get_parameter('quantity'); + $interval_max = get_parameter('max_interval'); + $interval_min = get_parameter('min_interval'); + // Checks intervals fields + if (preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_max) and preg_match('/^(\-)*[0-9]*\.?[0-9]+$/', $interval_min)){ + $good_format = true; + } + $intervals = get_parameter('max_interval') . ';' . get_parameter('min_interval'); + $values['text'] = $intervals; }else{ $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); $values['top_n_value'] = get_parameter('quantity'); + $values['text'] = get_parameter('text'); + $good_format = true; } $values['id_agent'] = get_parameter('id_agent'); $values['id_gs'] = get_parameter('id_custom_graph'); - $values['text'] = get_parameter('text'); $values['id_agent_module'] = get_parameter('id_agent_module'); switch ($config['dbtype']){ case "mysql": @@ -367,45 +395,50 @@ switch ($action) { $style['show_in_two_columns'] = get_parameter('show_in_two_columns', 0); $style['show_in_landscape'] = get_parameter('show_in_landscape', 0); $values['style'] = io_safe_input(json_encode($style)); - - $result = db_process_sql_insert('treport_content', $values); - - if ($result === false) { - $resultOperationDB = false; - } - else { - $idItem = $result; + + if ($good_format){ + $result = db_process_sql_insert('treport_content', $values); - switch ($config["dbtype"]) { - case "mysql": - $max = db_get_all_rows_sql('SELECT max(`order`) AS max - FROM treport_content WHERE id_report = ' . $idReport . ';'); - break; - case "postgresql": - case "oracle": - $max = db_get_all_rows_sql('SELECT max("order") AS max - FROM treport_content WHERE id_report = ' . $idReport); - break; - } - if ($max === false) { - $max = 0; + if ($result === false) { + $resultOperationDB = false; } else { - $max = $max[0]['max']; + $idItem = $result; + + switch ($config["dbtype"]) { + case "mysql": + $max = db_get_all_rows_sql('SELECT max(`order`) AS max + FROM treport_content WHERE id_report = ' . $idReport . ';'); + break; + case "postgresql": + case "oracle": + $max = db_get_all_rows_sql('SELECT max("order") AS max + FROM treport_content WHERE id_report = ' . $idReport); + break; + } + if ($max === false) { + $max = 0; + } + else { + $max = $max[0]['max']; + } + switch ($config["dbtype"]) { + case "mysql": + db_process_sql_update('treport_content', array('`order`' => $max + 1), array('id_rc' => $idItem)); + break; + case "postgresql": + case "oracle": + db_process_sql_update('treport_content', array('"order"' => $max + 1), array('id_rc' => $idItem)); + break; + } + $resultOperationDB = true; } - switch ($config["dbtype"]) { - case "mysql": - db_process_sql_update('treport_content', array('`order`' => $max + 1), array('id_rc' => $idItem)); - break; - case "postgresql": - case "oracle": - db_process_sql_update('treport_content', array('"order"' => $max + 1), array('id_rc' => $idItem)); - break; - } - - $resultOperationDB = true; + break; + } + // If fields dont have good format + else { + $resultOperationDB = false; } - break; } break; default: diff --git a/pandora_console/include/functions_forecast.php b/pandora_console/include/functions_forecast.php index 5948bb1224..2182143132 100644 --- a/pandora_console/include/functions_forecast.php +++ b/pandora_console/include/functions_forecast.php @@ -174,6 +174,7 @@ function forecast_projection_graph($module_id, $period = 5184000, $prediction_pe if ($current_ts - $last_timestamp >= 126144000){ return false; } + //html_debug_print(" Date " . $timestamp_f . " data: " . $output_data[$timestamp_f]); // Found it if ($max_value >= $output_data[$timestamp_f] and $min_value <= $output_data[$timestamp_f]){ return $current_ts; @@ -191,16 +192,17 @@ function forecast_projection_graph($module_id, $period = 5184000, $prediction_pe * Return a date when the date interval is reached * * @param int Module id. + * @param int Given data period to make the prediction * @param int Max value in the interval. * @param int Min value in the interval. * * @return mixed timestamp with the prediction date or false */ -function forecast_prediction_date ($module_id, $max_value = 0, $min_value = 0){ +function forecast_prediction_date ($module_id, $period = 5184000, $max_value = 0, $min_value = 0){ // Checks interval if ($min_value > $max_value){ return false; } - return forecast_projection_graph($module_id, 5184000, false, $max_value, $min_value); + return forecast_projection_graph($module_id, $period, false, $max_value, $min_value); } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 41fd1202ae..9d341b8f90 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2120,7 +2120,10 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $data = array (); $table->colspan[2][0] = 3; - $value = forecast_prediction_date ($content['id_agent_module'], $content['top_n'], $content['top_n_value']); + $intervals_text = $content['text']; + $max_interval = substr($intervals_text, 0, strpos($intervals_text, ';')); + $min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1); + $value = forecast_prediction_date ($content['id_agent_module'], $content['period'], $max_interval, $min_interval); if ($value === false) { $value = __('Unknown');