Skip to content
Snippets Groups Projects
Commit d4991b40 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Add DST support in date handler. Added summary columns per delimiter. Added pie chart. +++

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1485 44740490-163a-0410-bde0-09ae8108e29a
parent 85387973
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,8 @@ $config = array ( ...@@ -14,6 +14,8 @@ $config = array (
*/ */
//'auth' => 'feide', //'auth' => 'feide',
'default' => 'sso_hoursweek',
'useridattr' => 'eduPersonPrincipalName', 'useridattr' => 'eduPersonPrincipalName',
'allowedUsers' => array('andreas@uninett.no', 'ola.normann@sp.example.org'), 'allowedUsers' => array('andreas@uninett.no', 'ola.normann@sp.example.org'),
...@@ -44,6 +46,10 @@ $config = array ( ...@@ -44,6 +46,10 @@ $config = array (
'action' => 'saml20-sp-SSO', 'action' => 'saml20-sp-SSO',
'col' => 6, // Service Provider EntityID 'col' => 6, // Service Provider EntityID
'fieldPresentation' => array(
'class' => 'statistics:Entity',
'config' => 'saml20-sp-remote',
),
'slot' => 60*15, // Slots of 15 minutes 'slot' => 60*15, // Slots of 15 minutes
'fileslot' => 60*60*24, // One day (24 hours) file slots 'fileslot' => 60*60*24, // One day (24 hours) file slots
'axislabelint' => 6*4, // Number of slots per label. 4 per hour *6 = 6 hours 'axislabelint' => 6*4, // Number of slots per label. 4 per hour *6 = 6 hours
...@@ -57,6 +63,10 @@ $config = array ( ...@@ -57,6 +63,10 @@ $config = array (
'action' => 'saml20-sp-SSO', 'action' => 'saml20-sp-SSO',
'col' => 6, // Service Provider EntityID 'col' => 6, // Service Provider EntityID
'fieldPresentation' => array(
'class' => 'statistics:Entity',
'config' => 'saml20-sp-remote',
),
'slot' => 60*60*24, // Slots of 1 day (24 hours) 'slot' => 60*60*24, // Slots of 1 day (24 hours)
'fileslot' => 60*60*24*80, // 80 days of data in each file 'fileslot' => 60*60*24*80, // 80 days of data in each file
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
...@@ -70,6 +80,10 @@ $config = array ( ...@@ -70,6 +80,10 @@ $config = array (
'action' => 'saml20-idp-SSO', 'action' => 'saml20-idp-SSO',
'col' => 8, // Service Provider EntityID 'col' => 8, // Service Provider EntityID
'fieldPresentation' => array(
'class' => 'statistics:Entity',
'config' => 'saml20-sp-remote',
),
'slot' => 60*60*24, // Slots of 1 day (24 hours) 'slot' => 60*60*24, // Slots of 1 day (24 hours)
'fileslot' => 60*60*24*80, // 80 days of data in each file 'fileslot' => 60*60*24*80, // 80 days of data in each file
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
...@@ -86,6 +100,10 @@ $config = array ( ...@@ -86,6 +100,10 @@ $config = array (
'action' => 'saml20-sp-SSO', 'action' => 'saml20-sp-SSO',
'col' => 6, // Service Provider EntityID 'col' => 6, // Service Provider EntityID
'fieldPresentation' => array(
'class' => 'statistics:Entity',
'config' => 'saml20-sp-remote',
),
'slot' => 60*60, // Slots of one hour 'slot' => 60*60, // Slots of one hour
'fileslot' => 60*60*24*7, // 7 days of data in each file 'fileslot' => 60*60*24*7, // 7 days of data in each file
'axislabelint' => 24, // Number of slots per label. 24 is one each day 'axislabelint' => 24, // Number of slots per label. 24 is one each day
...@@ -99,6 +117,10 @@ $config = array ( ...@@ -99,6 +117,10 @@ $config = array (
'action' => 'saml20-sp-SSO', 'action' => 'saml20-sp-SSO',
'col' => 6, // Service Provider EntityID 'col' => 6, // Service Provider EntityID
'fieldPresentation' => array(
'class' => 'statistics:Entity',
'config' => 'saml20-sp-remote',
),
'slot' => 60*60*24, // Slots of one day 'slot' => 60*60*24, // Slots of one day
'fileslot' => 60*60*24*30, // 30 days of data in each file 'fileslot' => 60*60*24*30, // 30 days of data in each file
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
...@@ -112,6 +134,10 @@ $config = array ( ...@@ -112,6 +134,10 @@ $config = array (
'action' => 'saml20-idp-SLO', 'action' => 'saml20-idp-SLO',
'col' => 7, // Service Provider EntityID that initiated the logout. '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 'slot' => 60*60*24, // Slots of one day
'fileslot' => 60*60*24*30, // 30 days of data in each file 'fileslot' => 60*60*24*30, // 30 days of data in each file
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week 'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
......
...@@ -15,14 +15,24 @@ class sspmod_statistics_DateHandler { ...@@ -15,14 +15,24 @@ class sspmod_statistics_DateHandler {
*/ */
public function __construct($offset) { public function __construct($offset) {
$this->offset = $offset; $this->offset = $offset;
}
private function getDST($timestamp) {
if (idate('I', $timestamp)) return 3600;
return 0;
} }
public function toSlot($epoch, $slotsize) { 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) { 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) { public function prettyDateEpoch($epoch, $dateformat) {
......
...@@ -90,6 +90,30 @@ class sspmod_statistics_Graph_GoogleCharts { ...@@ -90,6 +90,30 @@ class sspmod_statistics_Graph_GoogleCharts {
return $url; 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 * 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 * value on the Y-axis. In example 37.6 will not make a good max value, instead
......
...@@ -49,7 +49,15 @@ div#content { ...@@ -49,7 +49,15 @@ div#content {
div.corner_t { div.corner_t {
max-width: none ! important; 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> </style>
<?php <?php
...@@ -170,43 +178,62 @@ echo '</div>'; # end graph content. ...@@ -170,43 +178,62 @@ echo '</div>'; # end graph content.
* Handle table view - - - - - - * Handle table view - - - - - -
*/ */
$classint = array('odd', 'even'); $i = 0; $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 ) { foreach ( $this->data['summaryDataset'] as $key => $value ) {
$clint = $classint[$i++ % 2]; $clint = $classint[$i++ % 2];
$keyName = $key; $keyName = $key;
if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key]; if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key];
if ($key === '_') { if ($key === '_') {
echo '<tr class="total ' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>'; echo '<tr class="total ' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
} else { } else {
echo '<tr class="' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>'; echo '<tr class="' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
} }
} }
echo '</table></div>'; echo '</table></div>';
// - - - - - - - End table view - - - - - - - // - - - - - - - End table view - - - - - - -
//
// echo('<pre>');
// print_r($this->data['results']);
// exit;
echo '<div id="debug" >'; 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['topdelimiters'] AS $key) {
foreach ($this->data['debugdata'] AS $dd) { echo('<td class="datacontent">' .
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>'; (array_key_exists($key, $this->data['results'][$slot]) ? $this->data['results'][$slot][$key] : '&nbsp;') .
'</td>');
}
echo('</tr>');
} }
echo '</table>'; echo '</table>';
......
...@@ -83,7 +83,7 @@ foreach ($available AS $key => $av) { ...@@ -83,7 +83,7 @@ foreach ($available AS $key => $av) {
$availrulenames = array_keys($available_rules); $availrulenames = array_keys($available_rules);
// Get selected rulename.... // Get selected rulename....
$rule = $availrulenames[0]; $rule = $statconfig->getString('default', $availrulenames[0]);
if(array_key_exists('rule', $_GET)) { if(array_key_exists('rule', $_GET)) {
if (array_key_exists($_GET['rule'], $available_rules)) { if (array_key_exists($_GET['rule'], $available_rules)) {
$rule = $_GET['rule']; $rule = $_GET['rule'];
...@@ -94,9 +94,6 @@ if(array_key_exists('rule', $_GET)) { ...@@ -94,9 +94,6 @@ if(array_key_exists('rule', $_GET)) {
/* /*
* Get list of avaiable times in current file (rule) * Get list of avaiable times in current file (rule)
*/ */
...@@ -176,7 +173,7 @@ foreach($results AS $slot => &$res) { ...@@ -176,7 +173,7 @@ foreach($results AS $slot => &$res) {
$maxvaluetime = $datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra); $maxvaluetime = $datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra);
} }
$maxvalue = max($res[$maxdelimiter],$maxvalue); $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); $max = sspmod_statistics_Graph_GoogleCharts::roof($maxvalue);
...@@ -189,7 +186,7 @@ $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. * Aggregate summary table from dataset. To be used in the table view.
*/ */
$summaryDataset = array(); $summaryDataset = array();
foreach($results AS $slot => $res) { foreach($results AS $slot => $res) {
foreach ($res AS $key => $value) { foreach ($res AS $key => $value) {
if (array_key_exists($key, $summaryDataset)) { if (array_key_exists($key, $summaryDataset)) {
...@@ -201,11 +198,29 @@ foreach($results AS $slot => $res) { ...@@ -201,11 +198,29 @@ foreach($results AS $slot => $res) {
} }
asort($summaryDataset); asort($summaryDataset);
$summaryDataset = array_reverse($summaryDataset, TRUE); $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(); $datasets = array();
...@@ -314,10 +329,21 @@ if (array_key_exists('fieldPresentation', $statrules[$rule])) { ...@@ -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['header'] = 'stat';
$t->data['imgurl'] = $grapher->show($axis, $axispos, $datasets, $max); $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.rules'] = $available_rules;
$t->data['available.times'] = $available_times; $t->data['available.times'] = $available_times;
$t->data['available.times.prev'] = $available_times_prev; $t->data['available.times.prev'] = $available_times_prev;
...@@ -329,7 +355,9 @@ $t->data['jquery'] = $jquery; ...@@ -329,7 +355,9 @@ $t->data['jquery'] = $jquery;
$t->data['selected.rule']= $rule; $t->data['selected.rule']= $rule;
$t->data['selected.time'] = $fileslot; $t->data['selected.time'] = $fileslot;
$t->data['debugdata'] = $debugdata; $t->data['debugdata'] = $debugdata;
$t->data['results'] = $results;
$t->data['summaryDataset'] = $summaryDataset; $t->data['summaryDataset'] = $summaryDataset;
$t->data['topdelimiters'] = $topdelimiters;
$t->data['availdelimiters'] = array_keys($availdelimiters); $t->data['availdelimiters'] = array_keys($availdelimiters);
$t->data['delimiterPresentation'] = $delimiterPresentation; $t->data['delimiterPresentation'] = $delimiterPresentation;
$t->show(); $t->show();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment