fixed graphs

This commit is contained in:
daniel 2018-05-30 17:45:17 +02:00
parent dd57ddbd3c
commit a8b8f309e6
10 changed files with 220 additions and 273 deletions

View File

@ -251,20 +251,29 @@ switch ($action) {
continue;
}
}
if ($id_custom_graph != 0) {
$img = custom_graphs_print(
$id_custom_graph, $height, $width, $period,
null, true, 0, true, $background_color);
}
else {
$img = grafico_modulo_sparse($id_agent_module,
$period, 0, $width, $height, '', null, false, 1,
0, 0, '', 0, 0, true, true, '', 1, false, '',
false, false, true, $background_color,
false, false, false, $config['type_module_charts']);
$params =array(
'agent_module_id' => $id_agent_module,
'period' => $period,
'show_events' => false,
'width' => $width,
'height' => $height,
//'only_image' => true,
//'homeurl' => '',
'menu' => false,
'backgroundColor' => $background_color,
'vconsole' => true,
'type_graph' => $config['type_module_charts']
);
$img = grafico_modulo_sparse($params);
}
//Restore db connection
if (!empty($id_metaconsole)) {
metaconsole_restore_db();

View File

@ -3104,6 +3104,10 @@ function series_type_graph_array($data, $show_elements_graph){
) . ' ' . $series_suffix_str;
}
}
elseif(strpos($key, 'projection') !== false){
$data_return['series_type'][$key] = 'area';
$data_return['legend'][$key] = __('Projection') . ' ' . $series_suffix_str;
}
else{
$data_return['series_type'][$key] = 'area';
}
@ -3116,15 +3120,23 @@ function series_type_graph_array($data, $show_elements_graph){
function generator_chart_to_pdf($params){
global $config;
$params_encode_json = urlencode(json_encode($params));
$file_js = "/var/www/html/pandora_console/include/web2image.js";
$url = "http://localhost/pandora_console/include/chart_generator.php";
$img_destination = "/var/www/html/pandora_console/attachment/imagen_". $params['agent_module_id'] .".png";
$width_img = 1048;
$height_img = 568;
html_debug_print("entra con: " . $params['agent_module_id'] ." en el tiempo " . date("Y-m-d H:i:s"), true);
exec("phantomjs " . $file_js . " " . $url . " '" . $params_encode_json . "' " . $img_destination . " " . $width_img . " " . $height_img);
html_debug_print("sale con: " . $params['agent_module_id'] ." en el tiempo " . date("Y-m-d H:i:s"), true);
return "<img src='/var/www/html/pandora_console/attachment/imagen_". $params['agent_module_id'] .".png' alt='la imagen bonica'>";
$file_js = $config["homedir"] . "/include/web2image.js";
$url = $config["homeurl"] . "/include/chart_generator.php";
$img_file = "img_". uniqid() . $params['agent_module_id'] .".png";
$img_path = $config["homedir"] . "/attachment/" . $img_file;
$img_url = $config["homeurl"] . "/attachment/" . $img_file;
error_log($img_url);
$width_img = 500;
$height_img = 450;
//html_debug_print('entrando en llamada a phantom.js.......', true);
$result = exec("phantomjs " . $file_js . " " . $url . " '" . $params_encode_json . "' " . $img_path . " " . $width_img . " " . $height_img);
return '<img src="' . $img_url . '" />';
//header('Content-Type: image/png;');
//return '<img src="data:image/jpg;base64, '.$result.'" />';
//return "<img src='/var/www/html/pandora_console/attachment/imagen_". $params['agent_module_id'] .".png' alt='la imagen bonica'>";
}
/**

View File

@ -10041,25 +10041,13 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) {
// returnError('error_module_graph', __(''));
return;
}
$id_module_type = modules_get_agentmodule_type ($id_module);
$module_type = modules_get_moduletype_name ($id_module_type);
$string_type = strpos($module_type,'string');
// Get the html item
if ($string_type === false) {
$graph_html = grafico_modulo_sparse(
$id_module, $graph_seconds, false, 600, 300, '',
'', false, false, true, time(), '', 0, 0, true, true,
ui_get_full_url(false) . '/', 1, false, '', false, true,
true, 'white', null, false, false, $config['type_module_charts'],
false, false);
} else {
$graph_html = grafico_modulo_string(
$id_module, $graph_seconds, false, 600, 300, '',
'', false, false, true, time(), true, ui_get_full_url(false) . '/',
'', 1, true);
}
$graph_html = grafico_modulo_sparse(
$id_module, $graph_seconds, false, 600, 300, '',
'', false, false, true, time(), '', 0, 0, true, true,
ui_get_full_url(false) . '/', 1, false, '', false, true,
true, 'white', null, false, false, $config['type_module_charts'],
false, false);
$graph_image_file_encoded = false;
if (preg_match("/<img src='(.+)'./", $graph_html, $matches)) {

View File

@ -46,12 +46,15 @@ function forecast_projection_graph($module_id,
}
$begin_time = time();
$module_data=grafico_modulo_sparse ($module_id, $period, 0,
300, 300 , '', null,
false, 0, false,
0, '', 0, 1, false,
true, '', 1, true);
$params =array(
'agent_module_id' => $module_id,
'period' => $period,
'return_data' => 1,
'projection' => true
);
$module_data = grafico_modulo_sparse ($params);
if (empty($module_data)) {
return array();
@ -62,55 +65,57 @@ function forecast_projection_graph($module_id,
}
// Data initialization
$sum_obs = 0;
$sum_xi = 0;
$sum_yi = 0;
$sum_xi_yi = 0;
$sum_xi2 = 0;
$sum_yi2 = 0;
$sum_obs = 0;
$sum_xi = 0;
$sum_yi = 0;
$sum_xi_yi = 0;
$sum_xi2 = 0;
$sum_yi2 = 0;
$sum_diff_dates = 0;
$last_timestamp = get_system_time();
$agent_interval = SECONDS_5MINUTES;
$cont = 1;
$data = array();
$cont = 1;
$data = array();
//$table->data = array();
// Creates data for calculation
if (is_array($module_data) || is_object($module_data)) {
foreach ($module_data as $utimestamp => $row) {
if ($utimestamp == '') {
foreach ($module_data['sum1']['data'] as $key => $row) {
if ($row[0] == '') {
continue;
}
$row[0] = $row[0] / 1000;
$data[0] = '';
$data[1] = $cont;
$data[2] = date($config["date_format"], $utimestamp);
$data[3] = $utimestamp;
$data[4] = $row['sum'];
$data[5] = $utimestamp * $row['sum'];
$data[6] = $utimestamp * $utimestamp;
$data[7] = $row['sum'] * $row['sum'];
$data[2] = date($config["date_format"], $row[0]);
$data[3] = $row[0];
$data[4] = $row[1];
$data[5] = $row[0] * $row[1];
$data[6] = $row[0] * $row[0];
$data[7] = $row[1] * $row[1];
if ($cont == 1) {
$data[8] = 0;
}
else {
$data[8] = $utimestamp - $last_timestamp;
$data[8] = $row[0] - $last_timestamp;
}
$sum_obs = $sum_obs + $cont;
$sum_xi = $sum_xi + $utimestamp;
$sum_yi = $sum_yi + $row['sum'];
$sum_xi_yi = $sum_xi_yi + $data[5];
$sum_xi2 = $sum_xi2 + $data[6];
$sum_yi2 = $sum_yi2 + $data[7];
$sum_obs = $sum_obs + $cont;
$sum_xi = $sum_xi + $row[0];
$sum_yi = $sum_yi + $row[1];
$sum_xi_yi = $sum_xi_yi + $data[5];
$sum_xi2 = $sum_xi2 + $data[6];
$sum_yi2 = $sum_yi2 + $data[7];
$sum_diff_dates = $sum_diff_dates + $data[8];
$last_timestamp = $utimestamp;
$last_timestamp = $row[0];
$cont++;
}
}
$cont--;
// Calculation over data above:
// 1. Calculation of linear correlation coefficient...
@ -121,15 +126,6 @@ function forecast_projection_graph($module_id,
// 3.2 Standard deviation for Y: sqrt((Sum(Yi²)/Obs) - (avg Y)²)
// Linear correlation coefficient:
if ($sum_xi != 0) {
$avg_x = $cont/$sum_xi;
} else {
$avg_x = 0;
}
if ($sum_yi != 0)
$avg_y = $cont/$sum_yi;
else
$avg_y = 0;
/*
if ($cont != 0) {
@ -229,18 +225,17 @@ function forecast_projection_graph($module_id,
}
}
$timestamp_f = date($time_format, $current_ts);
//$timestamp_f = date($time_format, $current_ts);
$timestamp_f = graph_get_formatted_date($current_ts, $time_format, $time_format_2);
$timestamp_f = $current_ts * 1000;
if ($csv) {
$output_data[$idx]['date'] = $current_ts;
$output_data[$idx]['data'] = ($a + ($b * $current_ts));
}
else {
$output_data[$timestamp_f] = ($a + ($b * $current_ts));
$output_data[$idx][0] = $timestamp_f;
$output_data[$idx][1] = ($a + ($b * $current_ts));
}
// Using this function for prediction_date
if ($prediction_period == false) {
// These statements stop the prediction when interval is greater than 2 years
@ -249,7 +244,7 @@ function forecast_projection_graph($module_id,
}
// Found it
if ($max_value >= $output_data[$timestamp_f] and $min_value <= $output_data[$timestamp_f]) {
if ($max_value >= $output_data[$idx][0] and $min_value <= $output_data[$idx][0]) {
return $current_ts;
}
}
@ -259,7 +254,7 @@ function forecast_projection_graph($module_id,
$current_ts = $current_ts + $agent_interval;
$idx++;
}
return $output_data;
}

View File

@ -234,16 +234,45 @@ function grafico_modulo_sparse_data_chart (
global $config;
$data = db_get_all_rows_filter (
'tagente_datos',
array ('id_agente_modulo' => (int)$agent_module_id,
"utimestamp > '". $date_array['start_date']. "'",
"utimestamp < '". $date_array['final_date'] . "'",
'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'),
'AND',
$data_module_graph['history_db']
);
if( $data_module_graph['id_module_type'] == 23 ||
$data_module_graph['id_module_type'] == 3 ||
$data_module_graph['id_module_type'] == 17 ||
$data_module_graph['id_module_type'] == 10 ||
$data_module_graph['id_module_type'] == 33 ){
//XXXXXXXXXXX
/*
"SELECT count(*) as data, min(utimestamp) as utimestamp
FROM tagente_datos_string
WHERE id_agente_modulo = 227
AND utimestamp > 1527584831
AND utimestamp < 1527671231
GROUP by ROUND(utimestamp / 300);"
*/
$data = db_get_all_rows_filter (
'tagente_datos_string',
array ('id_agente_modulo' => (int)$agent_module_id,
"utimestamp > '". $date_array['start_date']. "'",
"utimestamp < '". $date_array['final_date'] . "'",
'group' => "ROUND(utimestamp / 300)",
'order' => 'utimestamp ASC'),
array ('count(*) as datos', 'min(utimestamp) as utimestamp'),
'AND',
$data_module_graph['history_db']
);
}
else{
$data = db_get_all_rows_filter (
'tagente_datos',
array ('id_agente_modulo' => (int)$agent_module_id,
"utimestamp > '". $date_array['start_date']. "'",
"utimestamp < '". $date_array['final_date'] . "'",
'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'),
'AND',
$data_module_graph['history_db']
);
}
if($data === false){
$data = array();
@ -665,7 +694,6 @@ function grafico_modulo_sparse_data(
);
*/
function grafico_modulo_sparse ($params) {
html_debug_print('entra por este sitio', true);
global $config;
/*XXXXXXXXXXXX Documnetar
@ -691,8 +719,6 @@ function grafico_modulo_sparse ($params) {
$params['show_events'] = false;
}
// ATTENTION: The min size is in constants.php
// It's not the same minsize for all graphs, but we are choosed a prudent minsize for all
if(!isset($params['width'])){
$params['width'] = '90%';
}
@ -821,7 +847,7 @@ function grafico_modulo_sparse ($params) {
//XXXXXXXXXXXX se devuelve phantom.js
if($params['only_image']){
return generator_chart_to_pdf($params);
return generator_chart_to_pdf($params);
}
global $graphic_type;
@ -1251,6 +1277,10 @@ function graphic_combined_module (
$i++;
}
if($projection && is_array($projection)){
$array_data['projection']['data']= $projection;
}
//summatory and average series
if($stacked == CUSTOM_GRAPH_AREA || $stacked == CUSTOM_GRAPH_LINE) {
if($summatory || $average) {

View File

@ -6478,10 +6478,6 @@ function reporting_simple_graph($report, $content, $type = 'dinamic',
$fullscale = (bool) $content['style']['fullscale'];
}
$moduletype_name = modules_get_moduletype_name(
modules_get_agentmodule_type(
$content['id_agent_module']));
$return['chart'] = '';
// Get chart
@ -6498,54 +6494,30 @@ function reporting_simple_graph($report, $content, $type = 'dinamic',
switch ($type) {
case 'dinamic':
case 'static':
if (preg_match ("/string/", $moduletype_name)) {
$urlImage = ui_get_full_url(false, false, false, false);
/*
$return['chart'] = grafico_modulo_string(
$content['id_agent_module'],
$content['period'],
false,
$width,
$height,
$label,
'',
false,
$only_avg,
false,
$report["datetime"],
$only_image,
$urlImage,
"",
$ttl);
*/
$return['chart'] = 'arreglar la grafica de string de una vez por todassssssssss';
// HACK it is saved in show_graph field.
$time_compare_overlapped = false;
if ($content['show_graph']) {
$time_compare_overlapped = 'overlapped';
}
else {
// HACK it is saved in show_graph field.
$time_compare_overlapped = false;
if ($content['show_graph']) {
$time_compare_overlapped = 'overlapped';
}
$params =array(
'agent_module_id' => $content['id_agent_module'],
'period' => $content['period'],
'title' => $label,
'avg_only' => $only_avg,
'pure' => false, //XXX
'date' => $report["datetime"],
'only_image' => $only_image,
'homeurl' => ui_get_full_url(false, false, false, false),
'ttl' => $ttl,
'compare' => $time_compare_overlapped,
'show_unknown' => true,
'percentil' => ($content['style']['percentil'] == 1) ? $config['percentil'] : null,
'fullscale' => $fullscale
);
$params =array(
'agent_module_id' => $content['id_agent_module'],
'period' => $content['period'],
'title' => $label,
'avg_only' => $only_avg,
'pure' => false, //XXX
'date' => $report["datetime"],
'only_image' => $only_image,
'homeurl' => ui_get_full_url(false, false, false, false),
'ttl' => $ttl,
'compare' => $time_compare_overlapped,
'show_unknown' => true,
'percentil' => ($content['style']['percentil'] == 1) ? $config['percentil'] : null,
'fullscale' => $fullscale
);
$return['chart'] = grafico_modulo_sparse($params);
$return['chart'] = grafico_modulo_sparse($params);
}
break;
case 'data':
$data = modules_get_agentmodule_data(

View File

@ -1034,85 +1034,61 @@ function visual_map_print_item($mode = "read", $layoutData,
else{
$img = '<img src="images/console/signes/module_graph.png" style="width:'.$width.'px;height:'. $height.'px;'.$imgpos.'">';
}
}
}
else {
if ($width == 0 || $height == 0) {
if ($layoutData['label_position']=='left') {
$img = '<div style="z-index:'.$show_on_top_index.';float:right;height:'.$himg.'px;">'.
grafico_modulo_sparse($id_module, $period,
0, 300, 180, modules_get_agentmodule_name($id_module),null, false, 1, false, 0,
modules_get_unit($id_module), 0, 0, true, $only_image, '', 1, false, '',
false, false, false, $layoutData['image'],
null, true, false, $type_graph) . '</div>';
}
elseif($layoutData['label_position']=='right') {
$img = '<div style="z-index:'.$show_on_top_index.';float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module,
$period, 0, 300, 180, modules_get_agentmodule_name($id_module),null, false,
1, false, 0, modules_get_unit($id_module), 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
else {
$img = grafico_modulo_sparse($id_module,
$period, 0, 300, 180, modules_get_agentmodule_name($id_module),null, false, 1,
false, 0, modules_get_unit($id_module), 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true, false, $type_graph);
}
}
else{
if ($layoutData['label_position']=='left') {
$img = '<div style="z-index:'.$show_on_top_index.';float:right;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module, $period,
0, $width, $height, modules_get_agentmodule_name($id_module), null, false, 1,
false, 0, modules_get_unit($id_module), 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
elseif ($layoutData['label_position']=='right') {
$img = '<div style="z-index:'.$show_on_top_index.';float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module, $period,
0, $width, $height, modules_get_agentmodule_name($id_module), null, false, 1,
false, 0, modules_get_unit($id_module), 0, 0, true, $only_image,
'', 1, false, modules_get_unit($id_module), false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
else {
$img = grafico_modulo_sparse($id_module,
$period, 0, $width, $height, modules_get_agentmodule_name($id_module), null,
false, 1, false, 0, modules_get_unit($id_module), 0, 0, true,
$only_image, '', 1, false, '', false,
false, false, $layoutData['image'],
null, false, true, $type_graph);
}
}
}
}
else {
if ($width == 0 || $height == 0) {
$width = 300;
$height = 180;
}
$params =array(
'agent_module_id' => $id_module,
'period' => $period,
'show_events' => false,
'width' => $width,
'height' => $height,
'title' => modules_get_agentmodule_name($id_module),
'unit' => modules_get_unit($id_module),
'only_image' => $only_image,
'menu' => false,
'backgroundColor' => $layoutData['image'],
'type_graph' => $type_graph
);
if ($layoutData['label_position']=='left') {
$img = '<div style="z-index:'.$show_on_top_index.';float:right;height:'.$himg.'px;">'.
grafico_modulo_sparse($params) . '</div>';
}
elseif($layoutData['label_position']=='right') {
$img = '<div style="z-index:'.$show_on_top_index.';float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($params) . '</div>';
}
else {
$img = grafico_modulo_sparse($params);
}
}
}
//Restore db connection
if ($layoutData['id_metaconsole'] != 0) {
metaconsole_restore_db();
}
break;
case BARS_GRAPH:
$imgpos = '';
if($layoutData['label_position']=='left'){
$imgpos = 'float:right';
}
else if($layoutData['label_position']=='right'){
$imgpos = 'float:left';
}
if (!empty($proportion)) {
$width =
((integer)($proportion['proportion_width'] * $width));

View File

@ -1,7 +1,6 @@
var system = require('system');
if (system.args.length < 2 || system.args.length > 6) {
//console.log('Usage web2image.js url url_parameters output_filename width height');
phantom.exit(1);
}
@ -22,12 +21,15 @@ if (!_height) {
}
page.viewportSize = { width: _width, height: _height };
//page.zoomFactor = 1.75;
//console.log("Pagina: " + url);
//console.log("parametros: " + url_params);
//console.log("Archivo salida: " + output_filename);
page.open(url + "?" + "data=" + url_params, function start(status) {
page.render(output_filename, {format: 'png'}); //, 'quality': 100});
page.render(output_filename, {format: 'png'});
//var base64 = page.renderBase64('JPG');
//console.log(base64);
phantom.exit();
});

View File

@ -136,6 +136,7 @@ class ModuleGraph {
switch ($this->graph_type) {
case 'boolean':
case 'sparse':
case 'string':
$params =array(
'agent_module_id' => $this->id,
'period' => $this->period,
@ -164,32 +165,6 @@ class ModuleGraph {
$this->zoom, 'adapted_'.$this->graph_type, $date);
}
break;
case 'string':
$graph = grafico_modulo_string(
$this->id,
$this->period,
$this->draw_events,
$this->width,
$this->height,
false,
null,
$this->draw_alerts,
1,
false,
$date,
false,
$urlImage,
'adapter_' . $this->graph_type,
1,
false);
if ($this->draw_events) {
$graph .= '<br>';
$graph .= graphic_module_events($this->id,
$this->width, $this->height,
$this->period, $config['homeurl'],
$this->zoom, 'adapted_' . $this->graph_type, $date);
}
break;
default:
$graph .= fs_error_image ('../images');
break;

View File

@ -235,26 +235,26 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent);
switch ($graph_type) {
case 'boolean':
case 'sparse':
$params =array(
'agent_module_id' => $id,
'period' => $period,
'show_events' => $draw_events,
'title' => $label_graph,
'unit_name' => $unit,
'show_alerts' => $draw_alerts,
'avg_only' => $avg_only,
'date' => $date,
'unit' => $unit,
'baseline' => $baseline,
'homeurl' => $urlImage,
'adapt_key' => 'adapter_' . $graph_type,
'compare' => $time_compare,
'show_unknown' => $unknown_graph,
'percentil' => (($show_percentil)? $config['percentil'] : null),
'type_graph' => $config['type_module_charts'],
'fullscale' => $fullscale
);
case 'string':
$params =array(
'agent_module_id' => $id,
'period' => $period,
'show_events' => $draw_events,
'title' => $label_graph,
'unit_name' => $unit,
'show_alerts' => $draw_alerts,
'avg_only' => $avg_only,
'date' => $date,
'unit' => $unit,
'baseline' => $baseline,
'homeurl' => $urlImage,
'adapt_key' => 'adapter_' . $graph_type,
'compare' => $time_compare,
'show_unknown' => $unknown_graph,
'percentil' => (($show_percentil)? $config['percentil'] : null),
'type_graph' => $config['type_module_charts'],
'fullscale' => $fullscale
);
echo grafico_modulo_sparse ($params);
echo '<br>';
if ($show_events_graph){
@ -264,18 +264,6 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent);
'adapted_' . $graph_type, $date, true);
}
break;
case 'string':
html_debug_print('entra x stats win hay que rehacer esta funcion');
echo grafico_modulo_string ($id, $period, $draw_events,
$width, $height, $label_graph, null, $draw_alerts, 1,
false, $date, false, $urlImage,
'adapter_' . $graph_type);
echo '<br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height,
$period, $config['homeurl'], $zoom,
'adapted_' . $graph_type, $date, true);
break;
default:
echo fs_error_image ('../images');
break;