X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Fplugins%2Fgeneric%2Fstatistics%2Fclass_statistics.inc;h=d3f967c701b0d263f21cc67b7d4bc0c50ed6c89f;hb=0f0f7df464d6f671fe783610d50e5ffa15b4dfc9;hp=433e33833440fb7cfb4c2de8ab73a272294c605e;hpb=e5daabd24dd55cda2b7dc3c76d613e0a4e3d9ca3;p=gosa.git diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc index 433e33833..d3f967c70 100644 --- a/gosa-core/plugins/generic/statistics/class_statistics.inc +++ b/gosa-core/plugins/generic/statistics/class_statistics.inc @@ -10,10 +10,18 @@ class statistics extends plugin var $rpcHandle = NULL; var $rpcConfigured = FALSE; - var $graphID_1 = 0; - var $graphID_2 = 0; + var $statisticData = array(); + + var $graphIDs = array(); + var $skipSeries = array(); + var $seriesListPerGraph = array(); + + var $legendR = 235; + var $legendG = 235; + var $legendB = 235; + + var $font = "./themes/default/fonts/LiberationSans-Regular.ttf"; - var $graph1Interval = 1; var $graph1DatePicker1 = 0; var $graph1DatePicker2 = 0; @@ -24,7 +32,7 @@ class statistics extends plugin plugin::plugin($config, NULL); // Init start and stop times for graph 1 - $this->graph1DatePicker1 = date('d.m.Y', time() - 7 * 24 * 60 *60); + $this->graph1DatePicker1 = date('d.m.Y', time() - 14 * 24 * 60 *60); $this->graph1DatePicker2 = date('d.m.Y', time()); // First try to retrieve values via RPC @@ -40,6 +48,18 @@ class statistics extends plugin // Get list of unsubmitted files. $this->unsbmittedFiles = $this->getUnsubmittedStatistics(); + + // Collect category translations + $this->catTranslations = array(); + foreach($this->config->configRegistry->getListOfPlugins() as $plugin => $data){ + if(isset($data['plCategory'])){ + foreach($data['plCategory'] as $id => $name){ + if(!is_numeric($id)){ + $this->catTranslations[$id] = $name['description']; + } + } + } + } } /*! \brief Returns a list local stored statistic files @@ -47,7 +67,6 @@ class statistics extends plugin */ function getLocalStatisticsFiles() { - $res = stats::getLocalStatFiles(); $tmp = array(); if(count($res)){ @@ -69,12 +88,15 @@ class statistics extends plugin { $available = $this->getLocalStatisticsFiles(); $alreadyTransmitted = $this->getStatisticsDatesFromServer(); - $unsubmitted = array_intersect($available,$alreadyTransmitted); + + $unsubmitted = array(); + foreach($available as $key => $day){ + if(!isset($alreadyTransmitted[$key])) $unsubmitted [$key] = $day; + } // Exclude statistic collection from today, they are still active and cannot be submitted. $curDate = date('Y-m-d'); if(isset($unsubmitted)) unset($unsubmitted[$curDate]); - return($unsubmitted); } @@ -84,6 +106,12 @@ class statistics extends plugin */ function getStatisticsDatesFromServer() { + // Do not request anything while rpc isn't configured. + if(!$this->rpcConfigured){ + return(array()); + } + + // Try to gather statistic dates from the backenbd. $res = $this->rpcHandle->getInstanceStatDates(); $dates = array(); if(!$this->rpcHandle->success()){ @@ -93,28 +121,23 @@ class statistics extends plugin $dates[$date] = strtotime($date); } } + $this->rpcHandle_Error = !$this->rpcHandle->success(); return($dates); } function execute() { - if(isset($_POST['graph1DatePicker1'])) $this->graph1DatePicker1 = get_post('graph1DatePicker1'); - if(isset($_POST['graph1DatePicker2'])) $this->graph1DatePicker2 = get_post('graph1DatePicker2'); - if(isset($_POST['graph1Interval'])) $this->graph1Interval = get_post('graph1Interval'); - - if(!$this->graph1Interval) $this->graph1Interval = 1; - $smarty = get_smarty(); $smarty->assign('graph1DatePicker1', $this->graph1DatePicker1); $smarty->assign('graph1DatePicker2', $this->graph1DatePicker2); - $smarty->assign('graph1Interval', $this->graph1Interval); - $smarty->assign('intervalValues', array('1','2','5','7','30')); + + $this->reloadGraphs(); // Do not render anything if we are not prepared to send and receive data via rpc. $smarty->assign("rpcConfigured", $this->rpcConfigured); $smarty->assign("validRpcHandle", TRUE); - if(!$this->rpcConfigured || !$this->rpcHandle){ + if(!$this->rpcHandle){ $smarty->assign("validRpcHandle", FALSE); return($smarty->fetch(get_template_path('statistics.tpl', TRUE))); } @@ -133,205 +156,397 @@ class statistics extends plugin msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); }else{ stats::removeStatsFile($filename); - echo "Inserted ".$res." entries for date ".date('d.m.Y', $date)."
"; } + $this->rpcHandle_Error = !$this->rpcHandle->success(); } $this->unsbmittedFiles = $this->getUnsubmittedStatistics(); } // Transmit daily statistics to GOsa-Server - if(isset($_POST['receiveStatistics'])){ + if(isset($_POST['receiveStatistics']) && $this->rpcConfigured){ + $start = strtotime($this->graph1DatePicker1); + $stop = strtotime($this->graph1DatePicker2); + $res = $this->rpcHandle->getInstanceStats($start,$stop); + if(!$this->rpcHandle->success()){ + msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); + }elseif($res){ + $this->statisticData = $this->prepareGraphData($res); + $this->reloadGraphs(); + } + $this->rpcHandle_Error = !$this->rpcHandle->success(); + } - // First try to retrieve values via RPC - if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ - $start = strtotime($this->graph1DatePicker1); - $stop = strtotime($this->graph1DatePicker2); + $smarty->assign('seriesListPerGraph', $this->seriesListPerGraph); + $smarty->assign('skipSeries', $this->skipSeries); + $smarty->assign('graphIDs', $this->graphIDs); + $smarty->assign('unsbmittedFiles', count($this->unsbmittedFiles)); + $smarty->assign('unsbmittedFilesMsg', sprintf( + _("You have currently %s unsubmitted statistic collection, do you want to transmit them now?"), + count($this->unsbmittedFiles))); + + $smarty->assign('rpcHandle_Error', $this->rpcHandle_Error); + return($smarty->fetch(get_template_path('statistics.tpl', TRUE))); + } - // Request statistics now - $res = $this->rpcHandle->getInstanceStats($start,$stop); - if(!$this->rpcHandle->success()){ - msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); - } - if($res){ + /*! \brief Prepares the graph data we've received from the rpc-service. + * This method will construct a usable data-array with converted + * date strings. + */ + function prepareGraphData($res) + { + + /* Build up array which represents the amount of errors per + * interval. + */ + $gData = array(); + foreach($res['errorsPerInterval'] as $dateStr => $data){ + $date = strtotime($dateStr); + $gData['errorsPerInterval'][$date] = $data; + } + ksort($gData['errorsPerInterval']); + + + /* Build up timeline + */ + $Xam = 5; + $cnt = 0; + $numCnt = $res['errorsPerInterval']; + foreach($gData['errorsPerInterval'] as $date => $data){ + if((count($numCnt) <= $Xam) || + ($cnt % (floor(count($numCnt) / $Xam )) == 0)){ + $gData['dates'][$date] = date('d.m.Y', $date); + }else{ + $gData['dates'][$date] = ' '; + } + $cnt ++; + } + ksort($gData['dates']); - // Include pChart - new pChartInclude(); + + /* Build up 'actions per category' array, this will later + * be represented using a pie chart. + */ + $gData['actionsPerCategory'] = $res['actionsPerCategory']; + arsort($gData['actionsPerCategory']); + + + /* Build up system-info array per interval. + */ + foreach($res['usagePerInterval'] as $dateStr => $data){ + $date = strtotime($dateStr); + foreach($data as $type => $count){ + $gData['usagePerInterval'][$type][$date] = $count; + } + } + foreach($gData['usagePerInterval'] as $key => $data) + ksort($gData['usagePerInterval'][$key]); - // Get most used categories, but only eight at once. - if(count($res['actionsPerCategory'])){ - // -------- - // Generate PIE chart of most used categories - // -------- + /* Prepare actions-per-interval array. + */ + foreach($res['actionsPerInterval'] as $category => $data){ + if(empty($category)) continue; + foreach($data as $dateStr => $count){ + $date = strtotime($dateStr); + $gData['actionsPerInterval'][$category][$date]=$count; + } + ksort($gData['actionsPerInterval'][$category]); + } + $this->skipSeries[1] = array(); + $this->skipSeries[2] = array(); + $this->skipSeries[3] = array(); + $this->skipSeries[4] = array(); + $this->skipSeries[5] = array(); + return($gData); + } - arsort($res['actionsPerCategory']); - $mostUsedCategories = array_slice($res['actionsPerCategory'],0,8); - // Dataset definition - $DataSet = new pData; - $this->graphID_1 = preg_replace("/[^0-9]/","",microtime(TRUE)); + function check() + { + $messages = plugin::check(); + return($messages); + } - $values = array_values($mostUsedCategories); - $keys = array_keys($mostUsedCategories); - $DataSet->AddPoint($values,"Serie1"); - $DataSet->AddAllSeries(); - $DataSet->AddPoint($keys,"Serie2"); - $DataSet->SetAbsciseLabelSerie("Serie2"); + function save_object() + { + plugin::save_object(); + if(isset($_POST['graph1DatePicker1'])) $this->graph1DatePicker1 = get_post('graph1DatePicker1'); + if(isset($_POST['graph1DatePicker2'])) $this->graph1DatePicker2 = get_post('graph1DatePicker2'); - // Initialise the graph - $Test = new pChart(400,200); - $Test->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10); + + // Get series to enable or disable + foreach($this->seriesListPerGraph as $graphId => $series){ + $this->skipSeries[$graphId] = array(); + if(isset($_POST["graphPosted_{$graphId}"])){ + foreach($series as $seriesName => $seriesDesc){ + if(!isset($_POST["addSeries_{$graphId}_{$seriesName}"])){ + $this->skipSeries[$graphId][] = $seriesName; + } + } + } + } + } - $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); + /*! \brief This method tries to translate category names. + * @param The category name to translate + * @return String The translated category names. + */ + function getCategoryTranslation($name) + { + $ret =""; - $file = '/tmp/graph_'.$this->graphID_1; - $Test->Render($file); - session::set('statistics::graphFile'.$this->graphID_1,$file); - } + // Extract category names from the given string. + $list = preg_split("/, /", $name); - // -------- - // Generate combined line and car chart of plugin usage, ldap execution time and errors - // -------- - - // Generate new and unique graph id - $this->graphID_2 = preg_replace("/[^0-9]/","",microtime(TRUE)); - - // Prepare transmitted data, sort it by date and collect - // transmitted timestamps to be able to print the x-Axis labels. - $dataArray = array(); - $dates = array(); - $DataSet2 = new pData; - $max = 1; - $seriesNumber = 0; - foreach($res['actionsPerInterval'] as $category => $entriesPerDate){ - - // Collect data per category and store used timestamps - foreach($entriesPerDate as $dateStr => $count){ - $date = strtotime($dateStr); - $dates[$date]=$date; - - // Do not append empty data - if(empty($category)) continue; - if($count) $count = ($count); - $dataArray[$category][$date] = $count; - } - - - // Do not append empty data - if(empty($category)) continue; - - // Sort results. - ksort($dataArray[$category]); - - // Add results to our data set. - $DataSet2->AddPoint($dataArray[$category], $category); - $DataSet2->SetSerieName(_($category), $category); - $Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1",0,"Daily incomes"); - $DataSet2->AddSerie($category); - $seriesNumber++; - - // Detect maximum value, to adjust the Y-Axis - $tmpMax = max($dataArray[$category]); - if($tmpMax > $max) $max = $tmpMax; - } - ksort($dates); - - // Prepare date strings for X-Axis, only print a given number of - // of labels to keep the axis readable. - $Xam = 5; // Number of labels - $cnt = 0; - $tmp = array(); - foreach($dates as $stamp){ - if((count($dates) <= $Xam) || ($cnt % (floor(count($dates) / $Xam )) == 0)){ - $tmp[$stamp] = date('d.m.Y',$stamp); - }else{ - $tmp[$stamp] = ' '; - } - $cnt ++; - } + // We do not have a category for systems directly, so we've to map all system types to 'System'. + // If we do not map to _(Systems) the graph legend will be half screen width. + if(count(array_intersect(array('server','terminal','workstation', 'opsi', 'component'), $list))){ + return(_("Systems")); + } - $DataSet2->AddPoint($tmp, 'date'); - $DataSet2->SetAbsciseLabelSerie('date'); - - $Test2 = new pChart(800,230); - $Test2->setFixedScale(0.0001,($max*1.1)); - $Test2->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10); - $Test2->setGraphArea(50,30,585,200); - $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->drawGrid(4,TRUE,200,200,200,50); - $Test2->drawTreshold(0,143,55,72,TRUE,TRUE); - $Test2->drawTitle(50,22,"Plugin usage over time",50,50,50,585); - - if(count($dates)){ - $Test2->drawScale($DataSet2->GetData(),$DataSet2->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2); - } + // Walk through category names and try to find a translation. + foreach($list as $cat){ + $cat = trim($cat); + if(isset($this->catTranslations[$cat])){ + $cat = _($this->catTranslations[$cat]); + }elseif(!empty($cat)){ + $cat = _($cat); + } + $ret .= $cat.", "; + } + return(rtrim($ret, ', ')); + } - // Draw the cubic curve graph - if(count($dataArray)){ - $Test2->drawFilledLineGraph($DataSet2->GetData(),$DataSet2->GetDataDescription(),50,TRUE); - } - // Add error series - $errors = array(); - foreach($res['errorsPerInterval'] as $dateStr => $count){ - $date = strtotime($dateStr); - if($count !=0) $count = ($count); - $errors[$date] = $count; - } + /*! \brief Reload the graph images. + */ + function reloadGraphs() + { + new pChartInclude(); - $DataSet2->AddPoint($errors, 'Errors'); - $DataSet2->SetSerieName('Errors', 'Errors'); - $DataSet2->AddSerie('Errors'); - $seriesNumber ++; - - $Test2->setColorPalette($seriesNumber-1,255,0,0); + $gData = $this->statisticData; + if(!count($gData)){ + return; + } + if(count($gData['actionsPerCategory'])){ + $this->generateCategoryPieGraph($gData['actionsPerCategory']); + } + $this->generateActionsGraph($gData); + + // Generate graph which displays the memory usage over time + $series = array( + 'max_mem' => _('Max'), + 'avg_mem' => _('Avergae'), + 'min_mem' => _('Min')); + $this->generateSystemStatsGraph($gData,'usagePerInterval',$series, _("Memory usage"),3); + + // Generate graph which displays the cpu load over time + $series = array( + 'max_load' => _('Max'), + 'avg_load' => _('Avergae'), + 'min_load' => _('Min')); + $this->generateSystemStatsGraph($gData,'usagePerInterval',$series, _("CPU load"),4); + + // Generate graph which displays the render time + $series = array( + 'max_render' => _('Max'), + 'avg_render' => _('Avergae'), + 'min_render' => _('Min')); + $this->generateSystemStatsGraph($gData,'usagePerInterval',$series, _("Render time"),5); + + // Generate graph which displays the plugin duration + $series = array( + 'max_dur' => _('Max'), + 'avg_dur' => _('Avergae'), + 'min_dur' => _('Min')); + $this->generateSystemStatsGraph($gData,'usagePerInterval',$series, _("Seconds per action"),6); + } - // Draw legend - $Test2->drawLegend(650,30,$DataSet2->GetDataDescription(),255,255,255); - // Remove plugin usage from data series, just keep error series. - foreach($dataArray as $categoryName => $list){ - $DataSet2->RemoveSerie($categoryName); - } - - // Draw right scale (Errors per day) - $Test2->setFixedScale(0.0001,(max($errors) +1) *1.1); - $Test2->drawRightScale($DataSet2->GetData(),$DataSet2->GetDataDescription(),SCALE_NORMAL,120,150,150,TRUE,0,2); - $Test2->drawBarGraph($DataSet2->GetData(),$DataSet2->GetDataDescription()); - - $file = '/tmp/graph_'.$this->graphID_2; - $Test2->Render($file); - session::set('statistics::graphFile'.$this->graphID_2,$file); - } + /*! \brief Generates the line-graph which displays the plugin usage over time. + */ + function generateActionsGraph($gData) + { + $lineMax = 100; + $errorMax = (max($gData['errorsPerInterval']) < 100)? 100:max($gData['errorsPerInterval']); + $dataSet = new pData; + $seriesCnt = 0; + $gID = 2; + foreach($gData['actionsPerInterval'] as $category => $entriesPerDate){ + if(empty($category) || in_array($category, $this->skipSeries[$gID])) continue; + + // Add results to our data set. + $dataSet->AddPoint($entriesPerDate, $category); + $dataSet->SetSerieName($this->getCategoryTranslation($category), $category); + $dataSet->AddSerie($category); + + // Detect maximum value, to adjust the Y-Axis + $tmpMax = max($entriesPerDate); + if($tmpMax > $lineMax) $lineMax = $tmpMax; + $seriesCnt ++; + } + + // Add timeline + $dataSet->AddPoint($gData['dates'], 'date'); + $dataSet->SetAbsciseLabelSerie('date'); + + $chart = new pChart(800,230); + $chart->setFixedScale(0.000,$lineMax); + $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10); + $chart->setGraphArea(50,30,585,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,"Plugin usage over time",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); + } + + // Do we've to add the errors series? + // If we have to, then add the error-data-series. + // and set the color for the new error-series to red. + if(!in_array('errorsPerInterval', $this->skipSeries[$gID])){ + + // Set the color for the error Series to 'red'. + // This has to be done before drawing the legend. + $chart->setColorPalette($seriesCnt,255,0,0); + + $dataSet->AddPoint($gData['errorsPerInterval'], 'Errors'); + $dataSet->SetSerieName(_('Error'), 'Errors'); + $dataSet->AddSerie('Errors'); + } + + + // Draw legend, but only if there is something to draw! + if($seriesCnt || !in_array('errorsPerInterval', $this->skipSeries[$gID])){ + $chart->drawLegend(650,30,$dataSet->GetDataDescription(),255,255,255); + } + + // Draw the error graph on top of the other graphs now. + // But remove the category-graph before. + if(!in_array('errorsPerInterval', $this->skipSeries[$gID])){ + + // Remove all graph series and add the error-series, then draw the new graph. + // (It is not relevant if it was really added before, so we simply remove all series!) + foreach($gData['actionsPerInterval'] as $category => $data){ + $dataSet->RemoveSerie($category); } + $chart->setFixedScale(0,$errorMax); + $chart->drawRightScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,120,150,150,TRUE,0,2, TRUE); + $chart->drawBarGraph($dataSet->GetData(),$dataSet->GetDataDescription()); } - $smarty->assign('graphID_1', $this->graphID_1); - $smarty->assign('graphID_2', $this->graphID_2); - $smarty->assign('unsbmittedFiles', count($this->unsbmittedFiles)); - $smarty->assign('unsbmittedFilesMsg', - sprintf( - _("You have currently %s unsubmitted statistic collection, do you want to transmit them now?"), - count($this->unsbmittedFiles))); - return($smarty->fetch(get_template_path('statistics.tpl', TRUE))); + // Generate new and unique graph id + $this->graphIDs[$gID] = preg_replace("/[^0-9]/","",microtime(TRUE)); + $file = '/tmp/graph_'.$this->graphIDs[$gID]; + $chart->Render($file); + session::set('statistics::graphFile'.$this->graphIDs[$gID],$file); + + // Keep a list of all selecteable data-series, to allow the user to disable + // or enable series on demand. + $this->seriesListPerGraph[$gID] = array(); + foreach($gData['actionsPerInterval'] as $key => $data){ + $this->seriesListPerGraph[$gID][$key] = $this->getCategoryTranslation($key); + } + $this->seriesListPerGraph[$gID]['errorsPerInterval'] = _("Error"); + + return; } + - function check() - { - $messages = plugin::check(); - return($messages); + /*! \brief Generates a graph about system informations. + */ + function generateSystemStatsGraph($gData, $key = "", $series= array(), $title = "", $gID=0 ) + { + // Add series data to dataSet + $dataSet = new pData; + $max = 0; + foreach($series as $seriesName => $seriesDesc){ + if(isset($gData[$key][$seriesName])){ + $dataSet->AddPoint($gData[$key][$seriesName],$seriesName); + $dataSet->SetSerieName($seriesDesc,$seriesName); + if($max < max($gData[$key][$seriesName])) $max = max($gData[$key][$seriesName]); + } + } + $dataSet->AddAllSeries(); + $dataSet->AddPoint($gData['dates'], 'date'); + $dataSet->SetAbsciseLabelSerie('date'); + + $chart = new pChart(800,230); + $chart->setFixedScale(0.0001,($max*1.1)); + $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10); + $chart->setGraphArea(50,30,585,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,$title,50,50,50,585); + $chart->drawLegend(650,30,$dataSet->GetDataDescription(),255,255,255); + + $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, FALSE); + $chart->drawFilledCubicCurve($dataSet->GetData(),$dataSet->GetDataDescription(),.1,50); + + $this->graphIDs[$gID] = preg_replace("/[^0-9]/","",microtime(TRUE)); + $file = '/tmp/graph_'.$this->graphIDs[$gID]; + $chart->Render($file); + session::set('statistics::graphFile'.$this->graphIDs[$gID],$file); } - function save_object() + + /*! \brief Generate the pie-chart which displays the overall-plugin-usage + */ + function generateCategoryPieGraph($data) { - plugin::save_object(); + // Sort data by usage count and slice array to get + // the eight most used categories + $gID = 1; + arsort($data); + $mostUsedCategories = array_slice($data,0,7); + + // Get the rest of categories and combine them 'others' + $theRest = array_slice($data,7); + $mostUsedCategories['remaining'] = array_sum($theRest); + + // Try to find a translation for the given category names + $values = array_values($mostUsedCategories); + $keys = array_keys($mostUsedCategories); + foreach($keys as $id => $cat){ + $keys[$id] = $this->getCategoryTranslation($cat); + } + + // Dataset definition + $dataSet = new pData; + $dataSet->AddPoint($values,"Serie1"); + $dataSet->AddAllSeries(); + $dataSet->AddPoint($keys,"Serie2"); + $dataSet->SetAbsciseLabelSerie("Serie2"); + + // Set graph area + $x = 400; + $y = 200; + + // Initialise the graph + $chart = new pChart($x,$y); + $chart->setFontProperties($this->font,10); + $chart->drawPieGraph($dataSet->GetData(),$dataSet->GetDataDescription(),($x/3),($y/2)-10,($y/2),PIE_PERCENTAGE,TRUE,50,20,3); + $chart->drawPieLegend(($x/3*2),15,$dataSet->GetData(),$dataSet->GetDataDescription(), + $this->legendR,$this->legendG,$this->legendB); + + // Store graph data + $this->graphIDs[$gID] = preg_replace("/[^0-9]/","",microtime(TRUE)); + $file = '/tmp/graph_'.$this->graphIDs[$gID]; + $chart->Render($file); + session::set('statistics::graphFile'.$this->graphIDs[$gID],$file); } } ?>