fixed bug in custom report's summatory
This commit is contained in:
parent
4b1649d5f8
commit
ef28abc460
|
@ -9309,57 +9309,27 @@ function reporting_get_agentmodule_data_sum ($id_agent_module,
|
|||
// Incremental modules are treated differently
|
||||
$module_inc = is_module_inc ($module_name);
|
||||
|
||||
// Get module data
|
||||
$interval_data = db_get_all_rows_sql('
|
||||
SELECT * FROM tagente_datos
|
||||
WHERE id_agente_modulo = ' . (int) $id_agent_module . '
|
||||
AND utimestamp > ' . (int) $datelimit . '
|
||||
AND utimestamp < ' . (int) $date . '
|
||||
ORDER BY utimestamp ASC', $search_in_history_db);
|
||||
if (!$uncompressed_module)
|
||||
$interval_data = db_uncompress_module_data((int) $id_agent_module, (int) $datelimit, (int) $date);
|
||||
|
||||
if ($interval_data === false) $interval_data = array ();
|
||||
|
||||
// Uncompressed module data
|
||||
if ($uncompressed_module) {
|
||||
$min_necessary = 1;
|
||||
|
||||
// Compressed module data
|
||||
}
|
||||
else {
|
||||
// Get previous data
|
||||
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
|
||||
if ($previous_data !== false) {
|
||||
$previous_data['utimestamp'] = $datelimit;
|
||||
array_unshift ($interval_data, $previous_data);
|
||||
}
|
||||
|
||||
// Get next data
|
||||
$next_data = modules_get_next_data ($id_agent_module, $date);
|
||||
if ($next_data !== false) {
|
||||
$next_data['utimestamp'] = $date;
|
||||
array_push ($interval_data, $next_data);
|
||||
}
|
||||
else if (count ($interval_data) > 0) {
|
||||
// Propagate the last known data to the end of the interval
|
||||
$next_data = array_pop ($interval_data);
|
||||
array_push ($interval_data, $next_data);
|
||||
$next_data['utimestamp'] = $date;
|
||||
array_push ($interval_data, $next_data);
|
||||
}
|
||||
|
||||
$min_necessary = 2;
|
||||
}
|
||||
|
||||
if (count ($interval_data) < $min_necessary) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set initial conditions
|
||||
$total = 0;
|
||||
if (! $uncompressed_module) {
|
||||
$previous_data = array_shift ($interval_data);
|
||||
}
|
||||
$partial_total = 0;
|
||||
$count_sum = 0;
|
||||
|
||||
foreach ($interval_data as $data) {
|
||||
|
||||
$partial_total = 0;
|
||||
$count_sum = 0;
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
case "postgresql":
|
||||
|
@ -9371,18 +9341,25 @@ function reporting_get_agentmodule_data_sum ($id_agent_module,
|
|||
break;
|
||||
}
|
||||
|
||||
if ($uncompressed_module) {
|
||||
$total += $data['datos'];
|
||||
if (!$module_inc) {
|
||||
foreach ($data['data'] as $val) {
|
||||
if (is_numeric($val['datos'])) {
|
||||
$partial_total += $val['datos'];
|
||||
$count_sum++;
|
||||
}
|
||||
else if ($module_inc) {
|
||||
$total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']);
|
||||
}
|
||||
|
||||
if ($count_sum===0) continue;
|
||||
|
||||
$total += $partial_total/$count_sum;
|
||||
}
|
||||
else {
|
||||
$total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval;
|
||||
$last = end($data['data']);
|
||||
$total += $last['datos'];
|
||||
}
|
||||
$previous_data = $data;
|
||||
}
|
||||
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue