From e6e925cbf68b105508b703d674434ee5d8053249 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 8 Nov 2017 18:57:37 +0100 Subject: [PATCH] fixed errors in TIP --- pandora_console/include/functions_db.php | 73 +++++++++++++++++------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index a156538b9a..eac5299982 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -481,9 +481,6 @@ function db_get_all_rows_sql($sql, $search_history_db = false, $cache = true, $d } } - - - /** * * Returns the time the module is in unknown status (by events) @@ -514,7 +511,6 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend return false; } - // Retrieve going unknown events in range $query = "SELECT utimestamp,event_type FROM tevento WHERE id_agentmodule = " . $id_agente_modulo; $query .= " AND event_type like 'going_%' "; @@ -527,7 +523,7 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend return false; } - $last_status = 0; // normal + $last_status = $events[0]["event_type"] != "going_unknown" ? 1:0; $return = array(); $i=0; foreach ($events as $event) { @@ -555,6 +551,9 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend } } } + if(!isset($return[0])){ + return false; + } return $return; } @@ -573,6 +572,16 @@ function db_get_module_ranges_unknown($id_agente_modulo, $tstart = false, $tend * * Note: All "unknown" data are marked as NULL * Warning: Be careful with the amount of data, check your RAM size available + * We'll return a bidimensional array + * Structure returned: schema: + * + * uncompressed_data => + * pool_id (int) + * utimestamp (start of current slice) + * data + * array + * datos + * utimestamp * */ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = false) { @@ -619,6 +628,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f $query .= " AND utimestamp=" . $first_utimestamp; $data = db_get_all_rows_sql($query,$search_historydb); + if ($data === false) { // first utimestamp not found in active database // SEARCH HISTORY DB @@ -643,7 +653,9 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f // Retrieve all data from module in given range $raw_data = db_get_all_rows_sql($query, $search_historydb); - if (($raw_data === false) && ($first_utimestamp === $tstart)) { + $module_interval = modules_get_interval ($id_agente_modulo); + + if (($raw_data === false) && ( ($first_utimestamp < $tstart - (SECONDS_1DAY + 2*$module_interval)) ) ) { // No data return false; } @@ -651,28 +663,45 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f // Retrieve going unknown events in range $unknown_events = db_get_module_ranges_unknown($id_agente_modulo, $tstart, $tend, $search_historydb); - // Retrieve module_interval to build the template - $module_interval = modules_get_interval ($id_agente_modulo); - $slice_size = $module_interval; + $previous_unknown_events = db_get_module_ranges_unknown( + $id_agente_modulo, + $tstart - (SECONDS_1DAY + 2*$module_interval), + $tstart, + $search_historydb + ); - // We'll return a bidimensional array - // Structure returned: schema: - // - // uncompressed_data => - // pool_id (int) - // utimestamp (start of current slice) - // data - // array - // utimestamp - // datos + //don't show graph if graph is inside unknown + if( $previous_unknown_events && + !isset($previous_unknown_events[count($previous_unknown_events) -1]['time_to']) && + $unknown_events === false && $raw_data === false){ + return false; + } + + //if time to is missing in last event force time to outside range time + if( $unknown_events && !isset($unknown_events[count($unknown_events) -1]['time_to']) ){ + $unknown_events[count($unknown_events) -1]['time_to'] = $tend + $module_interval; + } + + //if time to is missing in first event force time to outside range time + if ($first_data["datos"] === false) { + $last_inserted_value = false; + }elseif( $unknown_events && !isset($unknown_events[0]['time_from']) || + $first_utimestamp < $tstart - (SECONDS_1DAY + 2*$module_interval) ){ + $last_inserted_value = null; + } + else{ + $last_inserted_value = $first_data["datos"]; + } + + // Retrieve module_interval to build the template + $slice_size = $module_interval; $return = array(); // Point current_timestamp to begin of the set and initialize flags $current_timestamp = $tstart; - $last_inserted_value = $first_data["datos"]; $last_timestamp = $first_data["utimestamp"]; - $last_value = $first_data["datos"]; + $last_value = $first_data["datos"]; // Build template $pool_id = 0; @@ -732,7 +761,7 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f ($current_timestamp_end >= $current_unknown['time_from']) ) || ($current_timestamp_end >= $current_unknown['time_to']) ) ) { - if( ( $current_timestamp < $current_unknown['time_from']) && + if( ( $current_timestamp <= $current_unknown['time_from']) && ( $current_timestamp_end >= $current_unknown['time_from'] ) ){ // Add unknown state detected $tmp_data["utimestamp"] = $current_unknown["time_from"];