diff --git a/modules/statistics/config-templates/module_statistics.php b/modules/statistics/config-templates/module_statistics.php index f5432703709ba0e70950524a65f527b5f25bb4bc..7b839148f924f822cea140625d0750c48e675a50 100644 --- a/modules/statistics/config-templates/module_statistics.php +++ b/modules/statistics/config-templates/module_statistics.php @@ -14,6 +14,8 @@ $config = array ( */ //'auth' => 'feide', + 'default' => 'sso_hoursweek', + 'useridattr' => 'eduPersonPrincipalName', 'allowedUsers' => array('andreas@uninett.no', 'ola.normann@sp.example.org'), @@ -44,6 +46,10 @@ $config = array ( 'action' => 'saml20-sp-SSO', 'col' => 6, // Service Provider EntityID + 'fieldPresentation' => array( + 'class' => 'statistics:Entity', + 'config' => 'saml20-sp-remote', + ), 'slot' => 60*15, // Slots of 15 minutes 'fileslot' => 60*60*24, // One day (24 hours) file slots 'axislabelint' => 6*4, // Number of slots per label. 4 per hour *6 = 6 hours @@ -57,6 +63,10 @@ $config = array ( 'action' => 'saml20-sp-SSO', 'col' => 6, // Service Provider EntityID + 'fieldPresentation' => array( + 'class' => 'statistics:Entity', + 'config' => 'saml20-sp-remote', + ), 'slot' => 60*60*24, // Slots of 1 day (24 hours) 'fileslot' => 60*60*24*80, // 80 days of data in each file 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week @@ -70,6 +80,10 @@ $config = array ( 'action' => 'saml20-idp-SSO', 'col' => 8, // Service Provider EntityID + 'fieldPresentation' => array( + 'class' => 'statistics:Entity', + 'config' => 'saml20-sp-remote', + ), 'slot' => 60*60*24, // Slots of 1 day (24 hours) 'fileslot' => 60*60*24*80, // 80 days of data in each file 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week @@ -86,6 +100,10 @@ $config = array ( 'action' => 'saml20-sp-SSO', 'col' => 6, // Service Provider EntityID + 'fieldPresentation' => array( + 'class' => 'statistics:Entity', + 'config' => 'saml20-sp-remote', + ), 'slot' => 60*60, // Slots of one hour 'fileslot' => 60*60*24*7, // 7 days of data in each file 'axislabelint' => 24, // Number of slots per label. 24 is one each day @@ -99,6 +117,10 @@ $config = array ( 'action' => 'saml20-sp-SSO', 'col' => 6, // Service Provider EntityID + 'fieldPresentation' => array( + 'class' => 'statistics:Entity', + 'config' => 'saml20-sp-remote', + ), 'slot' => 60*60*24, // Slots of one day 'fileslot' => 60*60*24*30, // 30 days of data in each file 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week @@ -112,6 +134,10 @@ $config = array ( 'action' => 'saml20-idp-SLO', 'col' => 7, // Service Provider EntityID that initiated the logout. + 'fieldPresentation' => array( + 'class' => 'statistics:Entity', + 'config' => 'saml20-sp-remote', + ), 'slot' => 60*60*24, // Slots of one day 'fileslot' => 60*60*24*30, // 30 days of data in each file 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week diff --git a/modules/statistics/lib/DateHandler.php b/modules/statistics/lib/DateHandler.php index fafde9e3a4bc10bbe5d472a50471cbac0949143b..ebc07a11eaa349bbeefd87b7aae89835f8795dce 100644 --- a/modules/statistics/lib/DateHandler.php +++ b/modules/statistics/lib/DateHandler.php @@ -15,14 +15,24 @@ class sspmod_statistics_DateHandler { */ public function __construct($offset) { $this->offset = $offset; + + + } + + private function getDST($timestamp) { + if (idate('I', $timestamp)) return 3600; + return 0; } public function toSlot($epoch, $slotsize) { - return floor( ($epoch + $this->offset) / $slotsize); + $dst = $this->getDST($epoch); + return floor( ($epoch + $this->offset + $dst) / $slotsize); } public function fromSlot($slot, $slotsize) { - return $slot*$slotsize - $this->offset; + $temp = $slot*$slotsize - $this->offset; + $dst = $this->getDST($temp); + return $slot*$slotsize - $this->offset - $dst; } public function prettyDateEpoch($epoch, $dateformat) { diff --git a/modules/statistics/lib/Graph/GoogleCharts.php b/modules/statistics/lib/Graph/GoogleCharts.php index 787843a8cab0b2cec3b63a50b24a74561d19c045..561dc2edae228cc0a55323a6058e20d65b1e6fa6 100644 --- a/modules/statistics/lib/Graph/GoogleCharts.php +++ b/modules/statistics/lib/Graph/GoogleCharts.php @@ -90,6 +90,30 @@ class sspmod_statistics_Graph_GoogleCharts { return $url; } + public function showPie($axis, $datasets) { + + // echo('<pre>axis:'); + // print_r($axis); + // print_r($datasets); + + + $url = 'http://chart.apis.google.com/chart?' . + + // Dimension of graph. Default is 800x350 + 'chs=' . $this->x . 'x' . $this->y . + + // Dateset values. + '&chd=' . $this->encodedata(array($datasets)) . + + // chart type is linechart + '&cht=p' . + + '&chl=' . $this->encodeaxis($axis); + echo $url; + # exit; + return $url; + } + /** * Takes a input value, and generates a value that suits better as a max * value on the Y-axis. In example 37.6 will not make a good max value, instead diff --git a/modules/statistics/templates/statistics-tpl.php b/modules/statistics/templates/statistics-tpl.php index 038cf02481b38cba9cda109f75c8f8bd525dced0..48b4c6c71fbeb1a8cd2727bfe28941e66d37cd3c 100644 --- a/modules/statistics/templates/statistics-tpl.php +++ b/modules/statistics/templates/statistics-tpl.php @@ -49,7 +49,15 @@ div#content { div.corner_t { max-width: none ! important; } - +table.timeseries tr.odd td { + background-color: #f4f4f4; +} +table.timeseries td { + padding-right: 2em; border: 1px solid #ccc +} +td.datacontent { + text-align: right; +} </style> <?php @@ -170,43 +178,62 @@ echo '</div>'; # end graph content. * Handle table view - - - - - - */ $classint = array('odd', 'even'); $i = 0; -echo '<div id="table" class="tabset_content"> +echo '<div id="table" class="tabset_content">'; + +echo('<img src="' . $this->data['pieimgurl'] . '" />'); + +echo '<table class="tableview"><tr><th class="value">Value</th><th class="category">Data range</th>'; -<table class="tableview"><tr><th class="value">Value</th><th class="category">Data range</th>'; foreach ( $this->data['summaryDataset'] as $key => $value ) { $clint = $classint[$i++ % 2]; $keyName = $key; if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key]; - - if ($key === '_') { echo '<tr class="total ' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>'; } else { echo '<tr class="' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>'; } } + echo '</table></div>'; // - - - - - - - End table view - - - - - - - - - - +// +// echo('<pre>'); +// print_r($this->data['results']); +// exit; echo '<div id="debug" >'; +#echo $this->data['selected.time']; +#echo '<input style="width: 80%" value="' . htmlspecialchars($this->data['imgurl']) . '" />'; +echo '<table class="timeseries" style="">'; +echo('<tr><th>Time</th><th>Total</th>'); +foreach($this->data['topdelimiters'] AS $key) { + $keyName = $key; + if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key]; + echo('<th>' . $keyName . '</th>'); +} +echo('</tr>'); -#echo $this->data['selected.time']; -#echo '<input style="width: 80%" value="' . htmlspecialchars($this->data['imgurl']) . '" />'; +$i = 0; +foreach ($this->data['debugdata'] AS $slot => $dd) { + echo('<tr class="' . ((++$i % 2) == 0 ? 'odd' : 'even') . '">'); + echo('<td style="">' . $dd[0] . '</td>'); + echo('<td class="datacontent">' . $dd[1] . '</td>'); -echo '<table style="">'; -foreach ($this->data['debugdata'] AS $dd) { - echo '<tr><td style="padding-right: 2em; border: 1px solid #ccc">' . $dd[0] . '</td><td style="padding-right: 2em; border: 1px solid #ccc">' . $dd[1] . '</td></tr>'; + foreach($this->data['topdelimiters'] AS $key) { + echo('<td class="datacontent">' . + (array_key_exists($key, $this->data['results'][$slot]) ? $this->data['results'][$slot][$key] : ' ') . + '</td>'); + } + echo('</tr>'); } echo '</table>'; diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php index 1f6f79b5fbc8acca3462e2d28fa063f8a571025f..e972b6ab43dde9bb9a9aa7b302edc6a8d0edac43 100644 --- a/modules/statistics/www/showstats.php +++ b/modules/statistics/www/showstats.php @@ -83,7 +83,7 @@ foreach ($available AS $key => $av) { $availrulenames = array_keys($available_rules); // Get selected rulename.... -$rule = $availrulenames[0]; +$rule = $statconfig->getString('default', $availrulenames[0]); if(array_key_exists('rule', $_GET)) { if (array_key_exists($_GET['rule'], $available_rules)) { $rule = $_GET['rule']; @@ -94,9 +94,6 @@ if(array_key_exists('rule', $_GET)) { - - - /* * Get list of avaiable times in current file (rule) */ @@ -176,7 +173,7 @@ foreach($results AS $slot => &$res) { $maxvaluetime = $datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra); } $maxvalue = max($res[$maxdelimiter],$maxvalue); - $debugdata[] = array($datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra), $res[$maxdelimiter] ); + $debugdata[$slot] = array($datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra), $res[$maxdelimiter] ); } $max = sspmod_statistics_Graph_GoogleCharts::roof($maxvalue); @@ -189,7 +186,7 @@ $max = sspmod_statistics_Graph_GoogleCharts::roof($maxvalue); /** * Aggregate summary table from dataset. To be used in the table view. */ -$summaryDataset = array(); +$summaryDataset = array(); foreach($results AS $slot => $res) { foreach ($res AS $key => $value) { if (array_key_exists($key, $summaryDataset)) { @@ -201,11 +198,29 @@ foreach($results AS $slot => $res) { } asort($summaryDataset); $summaryDataset = array_reverse($summaryDataset, TRUE); -#echo '<pre>'; print_r($summaryDataset); exit; +// echo '<pre>'; print_r($summaryDataset); exit; + +/* + * Create a list of delimiter keys that has the highest total summary in this period. + */ +$topdelimiters = array(); +$maxdelimiters = 4; $i = 0; +foreach($summaryDataset AS $key => $value) { + if ($key !== '_') + $topdelimiters[] = $key; + if ($i++ >= $maxdelimiters) break; +} +// echo('<pre>'); print_r($topdelimiters); exit; +$piedata = array(); $sum = 0; +foreach($topdelimiters AS $td) { + $sum += $summaryDataset[$td]; + $piedata[] = number_format(100*$summaryDataset[$td] / $summaryDataset['_'], 2); +} +$piedata[] = number_format(100*($sum /$summaryDataset['_']), 2); $datasets = array(); @@ -314,10 +329,21 @@ if (array_key_exists('fieldPresentation', $statrules[$rule])) { } +$pieaxis = array(); +foreach($topdelimiters AS $key) { + $keyName = $key; + if(array_key_exists($key, $delimiterPresentation)) $keyName = $delimiterPresentation[$key]; + $pieaxis[] = $keyName; +} +$pieaxis[] = 'Others'; + $t->data['header'] = 'stat'; $t->data['imgurl'] = $grapher->show($axis, $axispos, $datasets, $max); + +$t->data['pieimgurl'] = $grapher->showPie($pieaxis, $piedata); + $t->data['available.rules'] = $available_rules; $t->data['available.times'] = $available_times; $t->data['available.times.prev'] = $available_times_prev; @@ -329,7 +355,9 @@ $t->data['jquery'] = $jquery; $t->data['selected.rule']= $rule; $t->data['selected.time'] = $fileslot; $t->data['debugdata'] = $debugdata; +$t->data['results'] = $results; $t->data['summaryDataset'] = $summaryDataset; +$t->data['topdelimiters'] = $topdelimiters; $t->data['availdelimiters'] = array_keys($availdelimiters); $t->data['delimiterPresentation'] = $delimiterPresentation; $t->show();