From 184b5e867326d2db907b2b0e6d1ea5909d2b09fa Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 17 Aug 2010 09:52:40 +0000 Subject: [PATCH] Updated rendering of the statisttics graph - We do not end up in endless loops while rendering the graph git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19402 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../generic/statistics/class_statistics.inc | 93 ++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc index 098292175..7bd547008 100644 --- a/gosa-core/plugins/generic/statistics/class_statistics.inc +++ b/gosa-core/plugins/generic/statistics/class_statistics.inc @@ -80,48 +80,53 @@ class statistics extends plugin // First try to retrieve values via RPC if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ - $interval = $this->graph1Interval; $start = strtotime($this->graph1DatePicker1); $stop = strtotime($this->graph1DatePicker2); // Request statistics now - $res = $this->rpcHandle->getInstanceStats($start,$stop,$interval); + $res = $this->rpcHandle->getInstanceStats($start,$stop); if(!$this->rpcHandle->success()){ msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); } if($res){ + // Include pChart new pChartInclude(); - // -------- - // Generate PIE chart of most used categories - // -------- - // Get most used categories, but only eight at once. - arsort($res['actionsPerCategory']); - $mostUsedCategories = array_slice($res['actionsPerCategory'],0,8); + if(count($res['actionsPerCategory']) && 0){ + + // -------- + // Generate PIE chart of most used categories + // -------- + + arsort($res['actionsPerCategory']); + $mostUsedCategories = array_slice($res['actionsPerCategory'],0,8); - // Dataset definition - $DataSet = new pData; - $this->graphID_1 = preg_replace("/[^0-9]/","",microtime(TRUE)); - $DataSet->AddPoint(array_values($mostUsedCategories),"Serie1"); - $DataSet->AddPoint(array_keys($mostUsedCategories),"Serie2"); - $DataSet->AddAllSeries(); - $DataSet->SetAbsciseLabelSerie("Serie2"); + // Dataset definition + $DataSet = new pData; + $this->graphID_1 = preg_replace("/[^0-9]/","",microtime(TRUE)); - // Initialise the graph - $Test = new pChart(400,200); - $Test->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10); - $Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),150,90,110,PIE_PERCENTAGE,TRUE,50,20,5); - $Test->drawPieLegend(310,15,$DataSet->GetData(),$DataSet->GetDataDescription(),200,255,200); + $DataSet->AddPoint(array_values($mostUsedCategories),"Serie1"); + $DataSet->AddPoint(array_keys($mostUsedCategories),"Serie2"); + $DataSet->AddAllSeries(); + $DataSet->SetAbsciseLabelSerie("Serie2"); - $file = '/tmp/graph_'.$this->graphID_1; - $Test->Render($file); - session::set('statistics::graphFile'.$this->graphID_1,$file); + // Initialise the graph + $Test = new pChart(400,200); + $Test->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10); + $Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),150,90,110,PIE_PERCENTAGE,TRUE,50,20,5); + $Test->drawPieLegend(310,15,$DataSet->GetData(),$DataSet->GetDataDescription(),200,255,200); + + $file = '/tmp/graph_'.$this->graphID_1; + $Test->Render($file); + session::set('statistics::graphFile'.$this->graphID_1,$file); + } + // -------- // Generate combined line and car chart of plugin usage, ldap execution time and errors // -------- @@ -134,23 +139,24 @@ class statistics extends plugin $dataArray = array(); $dates = array(); $DataSet2 = new pData; - $max = 0; + $max = 1; foreach($res['actionsPerInterval'] as $category => $entriesPerDate){ - // Only print the 8 most used categories, else we receive a lot of errors - // from the pChart classes, seems that it can only handle 8 data series at once. - if(!isset($mostUsedCategories[$category])) continue; - // Collect data per category and store used timestamps foreach($entriesPerDate as $dateStr => $count){ $date = strtotime($dateStr); - $dataArray[$category][$date] = log($count + 1); $dates[$date]=$date; + + // Do not append empty data + if(empty($category)) continue; + $dataArray[$category][$date] = log($count + 1); } - + + // Do not append empty data + if(empty($category)) continue; + // Sort results. ksort($dataArray[$category]); - ksort($dates); // Add results to our data set. $DataSet2->AddPoint($dataArray[$category], $category); @@ -160,6 +166,8 @@ class statistics extends plugin $tmpMax = max($dataArray[$category]); if($tmpMax > $max) $max = $tmpMax; } + ksort($dates); + $DataSet2->AddAllSeries(); // Prepare date strings for X-Axis, only print a given number of @@ -175,7 +183,7 @@ class statistics extends plugin } $cnt ++; } - + $DataSet2->AddPoint($tmp, 'date'); $DataSet2->SetAbsciseLabelSerie('date'); $DataSet2->RemoveSerie('date'); @@ -187,22 +195,19 @@ class statistics extends plugin $Test2->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240); $Test2->drawRoundedRectangle(5,5,695,225,5,230,230,230); $Test2->drawGraphArea(255,255,255,TRUE); - $Test2->drawScale($DataSet2->GetData(),$DataSet2->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); $Test2->drawGrid(4,TRUE,230,230,230,50); - - // Draw the 0 line $Test2->drawTreshold(0,143,55,72,TRUE,TRUE); + $Test2->drawTitle(50,22,"Plugin usage over time",50,50,50,585); - // Draw the cubic curve graph - #$Test2->drawBarGraph($DataSet2->GetData(),$DataSet2->GetDataDescription(),TRUE); - #$Test2->drawLineGraph($DataSet2->GetData(),$DataSet2->GetDataDescription(),TRUE); - #$Test2->drawFilledLineGraph($DataSet2->GetData(),$DataSet2->GetDataDescription(),50,TRUE); - $Test2->drawFilledCubicCurve($DataSet2->GetData(),$DataSet2->GetDataDescription(),.1,20); + if(count($dates)){ + $Test2->drawScale($DataSet2->GetData(),$DataSet2->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); + } - // Finish the graph - $DataSet2->RemoveSerie('date'); - $Test2->drawLegend(600,30,$DataSet2->GetDataDescription(),255,255,255); - $Test2->drawTitle(50,22,"Plugin usage over time",50,50,50,585); + // Draw the cubic curve graph + if(count($dataArray)){ + $Test2->drawFilledCubicCurve($DataSet2->GetData(),$DataSet2->GetDataDescription(),.1,20); + $Test2->drawLegend(600,30,$DataSet2->GetDataDescription(),255,255,255); + } $file = '/tmp/graph_'.$this->graphID_2; $Test2->Render($file); -- 2.30.2