Code

Added a new chart which displays the amount of all used object categories
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Aug 2010 15:44:17 +0000 (15:44 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Aug 2010 15:44:17 +0000 (15:44 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19450 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/statistics/chartClasses/class_objectCountChart.inc [new file with mode: 0644]
gosa-core/plugins/generic/statistics/class_statistics.inc

diff --git a/gosa-core/plugins/generic/statistics/chartClasses/class_objectCountChart.inc b/gosa-core/plugins/generic/statistics/chartClasses/class_objectCountChart.inc
new file mode 100644 (file)
index 0000000..ce54302
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+class objectCountChart extends statChart
+{
+    protected $title = 'Object count';
+
+    function __construct(&$config)
+    {
+        parent::__construct($config);
+        $this->graphName = get_class();
+    }
+
+
+    /*! \brief  Generates the line-graph which displays the plugin usage over time.
+     */ 
+    function render()
+    {
+        $lineMax = 100;
+        $gData = $this->graphData;
+        $dataSet = new pData;  
+        $seriesCnt = 0;
+
+        foreach($gData['objectCountPerInterval'] as $category => $count){
+            if(empty($category) || in_array($category, $this->skipSeries)) continue;
+
+            // Add results to our data set.
+            $dataSet->AddPoint($count, $category);
+            $dataSet->SetSerieName($this->getCategoryTranslation($category), $category);
+            $dataSet->AddSerie($category);
+
+            // Detect maximum value, to adjust the Y-Axis
+            $tmpMax = max($count);
+            if($tmpMax > $lineMax) $lineMax = $tmpMax;
+            $seriesCnt ++;
+            if($seriesCnt>=8) break;
+        }
+
+        // Keep a list of all selecteable data-series, to allow the user to disable
+        //  or enable series on demand.
+        $this->seriesList = array();
+        foreach($gData['objectCountPerInterval'] as $key => $data){
+            $this->seriesList[$key] = $this->getCategoryTranslation($key); 
+        }
+
+        // Add timeline
+        $dataSet->AddPoint($gData['dates'], 'date');
+        $dataSet->SetAbsciseLabelSerie('date');  
+
+        // Read graph from cache?
+        $pCache = new pCache('/var/spool/gosa/');
+        if($this->enableCaching && $pCache->IsInCache(get_class(),$dataSet->GetData())){
+            $filename =  $pCache->GetHash(get_class(),$dataSet->GetData());
+            $filename = '/var/spool/gosa/'.$filename;    
+            if(file_exists($filename) && is_readable($filename)){
+                $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
+                session::set('statistics::graphFile'.$this->graphID,$filename);
+                return;
+            }
+        }
+
+        $chart = new pChart(900,230);  
+        $chart->setFixedScale(0.000,$lineMax);
+        $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);  
+        $chart->setGraphArea(50,28,630,200);  
+        $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);  
+        $chart->drawRoundedRectangle(5,5,695,225,5,230,230,230);  
+        $chart->drawGraphArea(255,255,255,TRUE);  
+        $chart->drawGrid(4,TRUE,200,200,200,50);  
+        $chart->drawTreshold(0,143,55,72,TRUE,TRUE);  
+        $chart->drawTitle(50,22,_($this->title),50,50,50,585);  
+        $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, TRUE);     
+
+        // Only draw this graph if we've at least one series to draw! 
+        if($seriesCnt){
+            $chart->drawFilledLineGraph($dataSet->GetData(),$dataSet->GetDataDescription(),50,TRUE);
+        }
+
+        $chart->drawLegend(720,0,$dataSet->GetDataDescription(),255,255,255);
+
+        // Generate new and unique graph id
+        $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
+        $file = '/tmp/graph_'.$this->graphID;
+        $chart->Render($file);
+        session::set('statistics::graphFile'.$this->graphID,$file);
+        $pCache->WriteToCache(get_class(),$dataSet->GetData(),$chart);   
+
+        return;
+    }
+
+}
+?>
index b7285e4577a5715ffe986bd10f81bb2c03630080..0fe4889d9c3518077d5a2732840828f20634e05f 100644 (file)
@@ -35,6 +35,7 @@ class statistics extends plugin
         $this->graphs[] = new cpuLoadChart($config); 
         $this->graphs[] = new renderTimeChart($config); 
         $this->graphs[] = new durationTimeChart($config); 
+        $this->graphs[] = new objectCountChart($config); 
         $this->staticChart1 = new pieChart1($config); 
         $this->staticChart2 = new pieChart2($config); 
 
@@ -203,7 +204,11 @@ class statistics extends plugin
      *               date strings.
      */
     function prepareGraphData($res)
-    {
+    {   
+        // Object categories which has to mapped to 'systems'
+        $mapSystems = array('server','terminal','workstation', 'opsi', 
+                'component','phone', 'winworkstation', 'printer', 'incoming');
+
         /* Build up array which represents the amount of errors per
          *  interval.
          */
@@ -262,11 +267,42 @@ class statistics extends plugin
             ksort($gData['actionsPerInterval'][$category]);
         }
 
+        /* Prepare object count per interval array.
+         */   
+        $gData['objectCountPerInterval'] = array(); 
+        foreach($res['objectCountPerInterval'] as $category => $data){
+            if(empty($category)) continue;
+            if(in_array($category,$mapSystems)){
+                $category = 'systems';
+            }
+
+            // Skip series which are not interesting for us
+            if(!in_array($category,array('users','groups','department','systems','ogroups','fai'))){
+                $category = 'remaining';
+            }
+
+            foreach($data as $dateStr => $count){
+                $date = strtotime($dateStr);
+
+                if(!isset($gData['objectCountPerInterval'][$category][$date])){
+                    $gData['objectCountPerInterval'][$category][$date]=0;
+                }
+                $gData['objectCountPerInterval'][$category][$date] += $count;
+            }
+            ksort($gData['objectCountPerInterval'][$category]);
+        }
+        // Move remaining to the end of the list
+        if(isset($gData['objectCountPerInterval']['remaining'])){
+            $data = $gData['objectCountPerInterval']['remaining'];
+            unset($gData['objectCountPerInterval']['remaining']);
+            $gData['objectCountPerInterval']['remaining'] = $data;
+        }
+
         // Clean data from unusable categories like ('terminals workstations, ...')
         foreach($gData as $serieName => $seriesData){
             foreach($seriesData as $key => $data){
                 $list = preg_split("/, /", $key);
-                if(count(array_intersect(array('server','terminal','workstation', 'opsi', 'component'), $list))){
+                if(count(array_intersect($mapSystems, $list))){
                     unset($gData[$serieName][$key]);
                     $gData[$serieName]['systems'] = $data;
                 }