From 0b57b5f9e55e1f3cb09191a005031ceb824cdba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Thu, 5 Mar 2009 11:06:55 +0000 Subject: [PATCH] Do not show graph line at zero when there is not data... git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1373 44740490-163a-0410-bde0-09ae8108e29a --- modules/statistics/lib/Aggregator.php | 23 ++++++++++++++++++++--- modules/statistics/www/showstats.php | 12 +++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/modules/statistics/lib/Aggregator.php b/modules/statistics/lib/Aggregator.php index 345b44638..9be2b4e2d 100644 --- a/modules/statistics/lib/Aggregator.php +++ b/modules/statistics/lib/Aggregator.php @@ -113,17 +113,34 @@ class sspmod_statistics_Aggregator { foreach ($ruleresults AS $fileno => $fileres) { $slotlist = array_keys($fileres); + + $maxslot = $slotlist[count($slotlist)-1]; + #print_r($slotlist); // Get start and end slot number within the file, based on the fileslot. - $start = $datehandler->toSlot($datehandler->fromSlot($fileno, $this->statrules[$rulename]['fileslot']), $this->statrules[$rulename]['slot']); - $end = $datehandler->toSlot($datehandler->fromSlot($fileno+1, $this->statrules[$rulename]['fileslot']), $this->statrules[$rulename]['slot']); + $start = (int)$datehandler->toSlot($datehandler->fromSlot($fileno, $this->statrules[$rulename]['fileslot']), $this->statrules[$rulename]['slot']); + $end = (int)$datehandler->toSlot($datehandler->fromSlot($fileno+1, $this->statrules[$rulename]['fileslot']), $this->statrules[$rulename]['slot']); // Fill in missing entries and sort file results $filledresult = array(); for ($slot = $start; $slot < $end; $slot++) { - $filledresult[$slot] = (isset($fileres[$slot])) ? $fileres[$slot] : array('_' => 0); + #print_r(gettype($slot)); + if (array_key_exists($slot, $fileres)) { + $filledresult[$slot] = $fileres[$slot]; + } else { + #echo('SLot [' . $slot . '] of [' . $maxslot . ']' . "\n"); + if ($slot > $maxslot) { + $filledresult[$slot] = array('_' => -1); + } else { + $filledresult[$slot] = array('_' => NULL); + } + } + #print_r($filledresult[$slot]); +# = (isset($fileres[$slot])) ? $fileres[$slot] : array('_' => NULL); } + #print_r($filledresult); exit; + // store file file_put_contents($this->statdir . '/' . $rulename . '-' . $fileno . '.stat', serialize($filledresult), LOCK_EX ); } diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php index 2f8900267..43ee123ae 100644 --- a/modules/statistics/www/showstats.php +++ b/modules/statistics/www/showstats.php @@ -156,6 +156,10 @@ $maxvaluetime = 0; $debugdata = array(); + +/* + * Search for maximum value in order to scale the Y-scale of the graph presentation. + */ $maxdelimiter = $delimiter; if (array_key_exists('graph.total', $statrules[$rule]) && $statrules[$rule]['graph.total'] === TRUE) { $maxdelimiter = '_'; @@ -223,7 +227,11 @@ function getPercentValues($results, $delimiter) { foreach($results AS $slot => $res) { #echo ('<p>new value: ' . number_format(100*$res[$delimiter] / $max, 2)); if (array_key_exists($delimiter, $res)) { - $dataset[] = number_format(100*$res[$delimiter] / $max, 2); + if ($res[$delimiter] === -1) { + $dataset[] = -1; + } else { + $dataset[] = number_format(100*$res[$delimiter] / $max, 2); + } } else { $dataset[] = '0'; } @@ -252,6 +260,8 @@ if ($delimiter !== '_') { } } +#echo('<pre>'); print_r($datasets); exit; + #echo 'set axis on lastslot [' . $lastslot . ']'; $axis[] = $datehandler->prettyDateSlot($lastslot+1, $slotsize, $dateformat_intra); #print_r($axis); -- GitLab