2009-12-23 Ramon Novoa <rnovoa@artica.es>
* include/functions_db.php: Fixed avg. calculation in custom reports. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2238 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
e154d0613f
commit
a89ab56552
|
@ -1,3 +1,7 @@
|
||||||
|
2009-12-23 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* include/functions_db.php: Fixed avg. calculation in custom reports.
|
||||||
|
|
||||||
2009-12-23 Miguel de Dios <miguel.dedios@artica.es>
|
2009-12-23 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
* godmode/agentes/planned_downtime.php: fixes bug in several fields of
|
* godmode/agentes/planned_downtime.php: fixes bug in several fields of
|
||||||
|
|
|
@ -2487,27 +2487,44 @@ function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
|
||||||
|
|
||||||
$datelimit = $date - $period;
|
$datelimit = $date - $period;
|
||||||
|
|
||||||
$sql = sprintf ("SELECT SUM(datos), COUNT(*) FROM tagente_datos
|
$sql = sprintf ("SELECT * FROM tagente_datos
|
||||||
WHERE id_agente_modulo = %d
|
WHERE id_agente_modulo = %d
|
||||||
AND utimestamp > %d AND utimestamp <= %d
|
AND utimestamp > %d AND utimestamp <= %d
|
||||||
ORDER BY utimestamp ASC",
|
ORDER BY utimestamp ASC",
|
||||||
$id_agent_module, $datelimit, $date);
|
$id_agent_module, $datelimit, $date);
|
||||||
|
|
||||||
$values = get_db_row_sql ($sql, true);
|
$values = get_db_all_rows_sql ($sql, true);
|
||||||
|
if ($values === false) {
|
||||||
$sum = (float) $values[0];
|
$values = array ();
|
||||||
$total = (int) $values[1];
|
|
||||||
|
|
||||||
/* Get also the previous data before the selected interval. */
|
|
||||||
$previous_data = get_previous_data ($id_agent_module, $datelimit);
|
|
||||||
|
|
||||||
if ($previous_data) {
|
|
||||||
return ($previous_data['datos'] + $sum) / ($total + 1);
|
|
||||||
} elseif ($total > 0) {
|
|
||||||
return $sum / $total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* Get also the previous data before the selected interval. */
|
||||||
|
$sum = 0;
|
||||||
|
$total = 0;
|
||||||
|
$module_interval = get_module_interval ($id_agent_module);
|
||||||
|
$previous_data = get_previous_data ($id_agent_module, $datelimit);
|
||||||
|
if ($previous_data !== false) {
|
||||||
|
$values = array_merge (array ($previous_data), $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($values as $data) {
|
||||||
|
$interval_total = 1;
|
||||||
|
$interval_sum = $data['datos'];
|
||||||
|
if ($previous_data !== false && $data['utimestamp'] - $previous_data['utimestamp'] > $module_interval) {
|
||||||
|
$interval_total = round (($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval, 0);
|
||||||
|
$interval_sum *= $interval_total;
|
||||||
|
|
||||||
|
}
|
||||||
|
$total += $interval_total;
|
||||||
|
$sum += $interval_sum;
|
||||||
|
$previous_data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($total == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sum / $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue