mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
fixed forecast report
This commit is contained in:
parent
ed0d89ec73
commit
6312d2e38a
@ -40,9 +40,7 @@ function forecast_projection_graph($module_id,
|
|||||||
$max_exec_time = ini_get('max_execution_time');
|
$max_exec_time = ini_get('max_execution_time');
|
||||||
|
|
||||||
if ($max_exec_time !== false) {
|
if ($max_exec_time !== false) {
|
||||||
|
|
||||||
$max_exec_time = (int)$max_exec_time;
|
$max_exec_time = (int)$max_exec_time;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$begin_time = time();
|
$begin_time = time();
|
||||||
@ -54,7 +52,7 @@ function forecast_projection_graph($module_id,
|
|||||||
'projection' => true
|
'projection' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
$module_data = grafico_modulo_sparse ($params);
|
$module_data = grafico_modulo_sparse($params);
|
||||||
|
|
||||||
if (empty($module_data)) {
|
if (empty($module_data)) {
|
||||||
return array();
|
return array();
|
||||||
@ -113,35 +111,16 @@ function forecast_projection_graph($module_id,
|
|||||||
$cont++;
|
$cont++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cont--;
|
$cont--;
|
||||||
|
|
||||||
// Calculation over data above:
|
// Calculation over data above:
|
||||||
// 1. Calculation of linear correlation coefficient...
|
// 1. Calculation of linear correlation coefficient...
|
||||||
|
|
||||||
// 1.1 Average for X: Sum(Xi)/Obs
|
// 1.1 Average for X: Sum(Xi)/Obs
|
||||||
// 1.2 Average for Y: Sum(Yi)/Obs
|
// 1.2 Average for Y: Sum(Yi)/Obs
|
||||||
// 2. Covariance between vars
|
// 2. Covariance between vars
|
||||||
// 3.1 Standard deviation for X: sqrt((Sum(Xi²)/Obs) - (avg X)²)
|
// 3.1 Standard deviation for X: sqrt((Sum(Xi²)/Obs) - (avg X)²)
|
||||||
// 3.2 Standard deviation for Y: sqrt((Sum(Yi²)/Obs) - (avg Y)²)
|
// 3.2 Standard deviation for Y: sqrt((Sum(Yi²)/Obs) - (avg Y)²)
|
||||||
// Linear correlation coefficient:
|
// Linear correlation coefficient:
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
if ($cont != 0) {
|
|
||||||
$covariance = $sum_xi_yi/$cont;
|
|
||||||
$dev_x = sqrt(($sum_xi2/$cont) - ($avg_x*$avg_x));
|
|
||||||
$dev_y = sqrt(($sum_yi2/$cont) - ($avg_y*$avg_y));
|
|
||||||
} else {
|
|
||||||
$covariance = 0;
|
|
||||||
$dev_x = 0;
|
|
||||||
$dev_y = 0;
|
|
||||||
}
|
|
||||||
// Prevents division by zero
|
|
||||||
if ($dev_x != 0 and $dev_y != 0) {
|
|
||||||
$linear_coef = $covariance / ($dev_x * $dev_y);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// Agent interval could be zero, 300 is the predefined
|
// Agent interval could be zero, 300 is the predefined
|
||||||
if ($sum_obs == 0) {
|
if ($sum_obs == 0) {
|
||||||
$agent_interval = SECONDS_5MINUTES;
|
$agent_interval = SECONDS_5MINUTES;
|
||||||
@ -156,14 +135,12 @@ function forecast_projection_graph($module_id,
|
|||||||
// Function variables have an inverse linear relathionship!
|
// Function variables have an inverse linear relathionship!
|
||||||
// else
|
// else
|
||||||
// Function variables don't have an inverse linear relathionship!
|
// Function variables don't have an inverse linear relathionship!
|
||||||
|
|
||||||
// Could be a direct correlation coefficient
|
// Could be a direct correlation coefficient
|
||||||
// else
|
// else
|
||||||
// if ($linear_coef >= 0.8999 and $linear_coef <= 1.0) {
|
// if ($linear_coef >= 0.8999 and $linear_coef <= 1.0) {
|
||||||
// Function variables have a direct linear relathionship!
|
// Function variables have a direct linear relathionship!
|
||||||
// else
|
// else
|
||||||
// Function variables don't have a direct linear relathionship!
|
// Function variables don't have a direct linear relathionship!
|
||||||
|
|
||||||
// 2. Calculation of linear regresion...
|
// 2. Calculation of linear regresion...
|
||||||
|
|
||||||
$b_num = (($cont * $sum_xi_yi) - ($sum_xi * $sum_yi));
|
$b_num = (($cont * $sum_xi_yi) - ($sum_xi * $sum_yi));
|
||||||
@ -212,9 +189,9 @@ function forecast_projection_graph($module_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Aplying linear regression to module data in order to do the prediction
|
// Aplying linear regression to module data in order to do the prediction
|
||||||
$output_data = array();
|
|
||||||
$idx = 0;
|
$idx = 0;
|
||||||
// Create data in graph format like
|
// Create data in graph format like
|
||||||
|
|
||||||
while ($in_range) {
|
while ($in_range) {
|
||||||
$now = time();
|
$now = time();
|
||||||
|
|
||||||
@ -244,7 +221,8 @@ function forecast_projection_graph($module_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Found it
|
// Found it
|
||||||
if ($max_value >= $output_data[$idx][0] and $min_value <= $output_data[$idx][0]) {
|
if (($max_value >= $output_data[$idx][0]) &&
|
||||||
|
($min_value <= $output_data[$idx][0]) ) {
|
||||||
return $current_ts;
|
return $current_ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,7 +232,6 @@ function forecast_projection_graph($module_id,
|
|||||||
$current_ts = $current_ts + $agent_interval;
|
$current_ts = $current_ts + $agent_interval;
|
||||||
$idx++;
|
$idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output_data;
|
return $output_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +251,5 @@ function forecast_prediction_date ($module_id,
|
|||||||
if ($min_value > $max_value) {
|
if ($min_value > $max_value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return forecast_projection_graph($module_id, $period, false, $max_value, $min_value);
|
return forecast_projection_graph($module_id, $period, false, $max_value, $min_value);
|
||||||
}
|
}
|
||||||
|
@ -264,9 +264,7 @@ function grafico_modulo_sparse_data_chart (
|
|||||||
$data_module_graph['id_module_type'] == 18 ||
|
$data_module_graph['id_module_type'] == 18 ||
|
||||||
$data_module_graph['id_module_type'] == 9 ||
|
$data_module_graph['id_module_type'] == 9 ||
|
||||||
$data_module_graph['id_module_type'] == 31 ||
|
$data_module_graph['id_module_type'] == 31 ||
|
||||||
$data_module_graph['id_module_type'] == 100 ||
|
$data_module_graph['id_module_type'] == 100 ){
|
||||||
$params['projection']
|
|
||||||
){
|
|
||||||
|
|
||||||
$data = db_get_all_rows_filter (
|
$data = db_get_all_rows_filter (
|
||||||
'tagente_datos',
|
'tagente_datos',
|
||||||
@ -421,8 +419,7 @@ function grafico_modulo_sparse_data(
|
|||||||
$data_module_graph['id_module_type'] == 18 ||
|
$data_module_graph['id_module_type'] == 18 ||
|
||||||
$data_module_graph['id_module_type'] == 9 ||
|
$data_module_graph['id_module_type'] == 9 ||
|
||||||
$data_module_graph['id_module_type'] == 31 ||
|
$data_module_graph['id_module_type'] == 31 ||
|
||||||
$data_module_graph['id_module_type'] == 100 ||
|
$data_module_graph['id_module_type'] == 100 ){
|
||||||
$params['projection'] ){
|
|
||||||
$array_data = grafico_modulo_sparse_data_chart (
|
$array_data = grafico_modulo_sparse_data_chart (
|
||||||
$agent_module_id,
|
$agent_module_id,
|
||||||
$date_array,
|
$date_array,
|
||||||
@ -924,7 +921,6 @@ function grafico_modulo_sparse ($params) {
|
|||||||
$legend = array();
|
$legend = array();
|
||||||
$array_events_alerts = array();
|
$array_events_alerts = array();
|
||||||
|
|
||||||
|
|
||||||
$date_array = array();
|
$date_array = array();
|
||||||
$date_array["period"] = $params['period'];
|
$date_array["period"] = $params['period'];
|
||||||
$date_array["final_date"] = $params['date'];
|
$date_array["final_date"] = $params['date'];
|
||||||
@ -1226,7 +1222,7 @@ function graphic_combined_module (
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$params['stacked'] = 'area';
|
$params['stacked'] = 'area';
|
||||||
$params['projection'] = $params_combined['projection'];
|
$params['projection'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($params_combined['labels'])){
|
if(!isset($params_combined['labels'])){
|
||||||
@ -1519,6 +1515,14 @@ function graphic_combined_module (
|
|||||||
$date_array["final_date"] = $params['date'];
|
$date_array["final_date"] = $params['date'];
|
||||||
$date_array["start_date"] = $params['date'] - $params['period'];
|
$date_array["start_date"] = $params['date'] - $params['period'];
|
||||||
|
|
||||||
|
if($params_combined['projection']){
|
||||||
|
$output_projection = forecast_projection_graph(
|
||||||
|
$module_list[0],
|
||||||
|
$params['period'],
|
||||||
|
$params_combined['projection']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$i=0;
|
$i=0;
|
||||||
$array_data = array();
|
$array_data = array();
|
||||||
foreach ($module_list as $key => $agent_module_id) {
|
foreach ($module_list as $key => $agent_module_id) {
|
||||||
@ -1585,10 +1589,13 @@ function graphic_combined_module (
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($params_combined['projection'] && is_array($params_combined['projection'])){
|
if($params_combined['projection']){
|
||||||
$date_array_projection = max($params_combined['projection']);
|
// If projection doesn't have data then don't draw graph
|
||||||
$date_array['final_date'] = $date_array_projection[0] / 1000;
|
if ($output_projection != NULL) {
|
||||||
$array_data['projection']['data']= $params_combined['projection'];
|
$date_array_projection = max($output_projection);
|
||||||
|
$date_array['final_date'] = $date_array_projection[0] / 1000;
|
||||||
|
$array_data['projection']['data']= $output_projection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//summatory and average series
|
//summatory and average series
|
||||||
|
@ -3557,17 +3557,6 @@ function reporting_projection_graph($report, $content,
|
|||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'dinamic':
|
case 'dinamic':
|
||||||
case 'static':
|
case 'static':
|
||||||
$output_projection = forecast_projection_graph(
|
|
||||||
$content['id_agent_module'],
|
|
||||||
$content['period'],
|
|
||||||
$content['top_n_value']
|
|
||||||
);
|
|
||||||
|
|
||||||
// If projection doesn't have data then don't draw graph
|
|
||||||
if ($output_projection == NULL) {
|
|
||||||
$output_projection = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$params =array(
|
$params =array(
|
||||||
'period' => $content['period'],
|
'period' => $content['period'],
|
||||||
'width' => $width,
|
'width' => $width,
|
||||||
@ -3581,7 +3570,7 @@ function reporting_projection_graph($report, $content,
|
|||||||
);
|
);
|
||||||
|
|
||||||
$params_combined = array(
|
$params_combined = array(
|
||||||
'projection' => $output_projection
|
'projection' => $content['top_n_value'],
|
||||||
);
|
);
|
||||||
|
|
||||||
$return['chart'] = graphic_combined_module(
|
$return['chart'] = graphic_combined_module(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user