Skip to content

Commit d4991b4

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
1 parent 8538797 commit d4991b4

5 files changed

Lines changed: 137 additions & 22 deletions

File tree

modules/statistics/config-templates/module_statistics.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
//'auth' => 'feide',
1616

17+
'default' => 'sso_hoursweek',
18+
1719
'useridattr' => 'eduPersonPrincipalName',
1820
'allowedUsers' => array('andreas@uninett.no', 'ola.normann@sp.example.org'),
1921

@@ -44,6 +46,10 @@
4446

4547
'action' => 'saml20-sp-SSO',
4648
'col' => 6, // Service Provider EntityID
49+
'fieldPresentation' => array(
50+
'class' => 'statistics:Entity',
51+
'config' => 'saml20-sp-remote',
52+
),
4753
'slot' => 60*15, // Slots of 15 minutes
4854
'fileslot' => 60*60*24, // One day (24 hours) file slots
4955
'axislabelint' => 6*4, // Number of slots per label. 4 per hour *6 = 6 hours
@@ -57,6 +63,10 @@
5763

5864
'action' => 'saml20-sp-SSO',
5965
'col' => 6, // Service Provider EntityID
66+
'fieldPresentation' => array(
67+
'class' => 'statistics:Entity',
68+
'config' => 'saml20-sp-remote',
69+
),
6070
'slot' => 60*60*24, // Slots of 1 day (24 hours)
6171
'fileslot' => 60*60*24*80, // 80 days of data in each file
6272
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
@@ -70,6 +80,10 @@
7080

7181
'action' => 'saml20-idp-SSO',
7282
'col' => 8, // Service Provider EntityID
83+
'fieldPresentation' => array(
84+
'class' => 'statistics:Entity',
85+
'config' => 'saml20-sp-remote',
86+
),
7387
'slot' => 60*60*24, // Slots of 1 day (24 hours)
7488
'fileslot' => 60*60*24*80, // 80 days of data in each file
7589
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
@@ -86,6 +100,10 @@
86100

87101
'action' => 'saml20-sp-SSO',
88102
'col' => 6, // Service Provider EntityID
103+
'fieldPresentation' => array(
104+
'class' => 'statistics:Entity',
105+
'config' => 'saml20-sp-remote',
106+
),
89107
'slot' => 60*60, // Slots of one hour
90108
'fileslot' => 60*60*24*7, // 7 days of data in each file
91109
'axislabelint' => 24, // Number of slots per label. 24 is one each day
@@ -99,6 +117,10 @@
99117

100118
'action' => 'saml20-sp-SSO',
101119
'col' => 6, // Service Provider EntityID
120+
'fieldPresentation' => array(
121+
'class' => 'statistics:Entity',
122+
'config' => 'saml20-sp-remote',
123+
),
102124
'slot' => 60*60*24, // Slots of one day
103125
'fileslot' => 60*60*24*30, // 30 days of data in each file
104126
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week
@@ -112,6 +134,10 @@
112134

113135
'action' => 'saml20-idp-SLO',
114136
'col' => 7, // Service Provider EntityID that initiated the logout.
137+
'fieldPresentation' => array(
138+
'class' => 'statistics:Entity',
139+
'config' => 'saml20-sp-remote',
140+
),
115141
'slot' => 60*60*24, // Slots of one day
116142
'fileslot' => 60*60*24*30, // 30 days of data in each file
117143
'axislabelint' => 7, // Number of slots per label. 7 days => 1 week

modules/statistics/lib/DateHandler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@ class sspmod_statistics_DateHandler {
1515
*/
1616
public function __construct($offset) {
1717
$this->offset = $offset;
18+
19+
20+
}
21+
22+
private function getDST($timestamp) {
23+
if (idate('I', $timestamp)) return 3600;
24+
return 0;
1825
}
1926

2027
public function toSlot($epoch, $slotsize) {
21-
return floor( ($epoch + $this->offset) / $slotsize);
28+
$dst = $this->getDST($epoch);
29+
return floor( ($epoch + $this->offset + $dst) / $slotsize);
2230
}
2331

2432
public function fromSlot($slot, $slotsize) {
25-
return $slot*$slotsize - $this->offset;
33+
$temp = $slot*$slotsize - $this->offset;
34+
$dst = $this->getDST($temp);
35+
return $slot*$slotsize - $this->offset - $dst;
2636
}
2737

2838
public function prettyDateEpoch($epoch, $dateformat) {

modules/statistics/lib/Graph/GoogleCharts.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ public function show($axis, $axispos, $datasets, $max) {
9090
return $url;
9191
}
9292

93+
public function showPie($axis, $datasets) {
94+
95+
// echo('<pre>axis:');
96+
// print_r($axis);
97+
// print_r($datasets);
98+
99+
100+
$url = 'http://chart.apis.google.com/chart?' .
101+
102+
// Dimension of graph. Default is 800x350
103+
'chs=' . $this->x . 'x' . $this->y .
104+
105+
// Dateset values.
106+
'&chd=' . $this->encodedata(array($datasets)) .
107+
108+
// chart type is linechart
109+
'&cht=p' .
110+
111+
'&chl=' . $this->encodeaxis($axis);
112+
echo $url;
113+
# exit;
114+
return $url;
115+
}
116+
93117
/**
94118
* Takes a input value, and generates a value that suits better as a max
95119
* value on the Y-axis. In example 37.6 will not make a good max value, instead

modules/statistics/templates/statistics-tpl.php

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@
4949
div.corner_t {
5050
max-width: none ! important;
5151
}
52-
52+
table.timeseries tr.odd td {
53+
background-color: #f4f4f4;
54+
}
55+
table.timeseries td {
56+
padding-right: 2em; border: 1px solid #ccc
57+
}
58+
td.datacontent {
59+
text-align: right;
60+
}
5361
</style>
5462

5563
<?php
@@ -170,43 +178,62 @@
170178
* Handle table view - - - - - -
171179
*/
172180
$classint = array('odd', 'even'); $i = 0;
173-
echo '<div id="table" class="tabset_content">
181+
echo '<div id="table" class="tabset_content">';
182+
183+
echo('<img src="' . $this->data['pieimgurl'] . '" />');
184+
185+
echo '<table class="tableview"><tr><th class="value">Value</th><th class="category">Data range</th>';
174186

175-
<table class="tableview"><tr><th class="value">Value</th><th class="category">Data range</th>';
176187
foreach ( $this->data['summaryDataset'] as $key => $value ) {
177188
$clint = $classint[$i++ % 2];
178189

179190
$keyName = $key;
180191
if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key];
181192

182-
183-
184193
if ($key === '_') {
185194
echo '<tr class="total ' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
186195
} else {
187196
echo '<tr class="' . $clint . '"><td class="value">' . $value . '</td><td class="category">' . $keyName . '</td></tr>';
188197
}
189198
}
199+
190200
echo '</table></div>';
191201
// - - - - - - - End table view - - - - - - -
192202

193203

194-
195-
196-
204+
//
205+
// echo('<pre>');
206+
// print_r($this->data['results']);
207+
// exit;
197208

198209

199210
echo '<div id="debug" >';
200211

212+
#echo $this->data['selected.time'];
213+
#echo '<input style="width: 80%" value="' . htmlspecialchars($this->data['imgurl']) . '" />';
201214

215+
echo '<table class="timeseries" style="">';
216+
echo('<tr><th>Time</th><th>Total</th>');
217+
foreach($this->data['topdelimiters'] AS $key) {
218+
$keyName = $key;
219+
if(array_key_exists($key, $this->data['delimiterPresentation'])) $keyName = $this->data['delimiterPresentation'][$key];
220+
echo('<th>' . $keyName . '</th>');
221+
}
222+
echo('</tr>');
202223

203-
#echo $this->data['selected.time'];
204224

205-
#echo '<input style="width: 80%" value="' . htmlspecialchars($this->data['imgurl']) . '" />';
225+
$i = 0;
226+
foreach ($this->data['debugdata'] AS $slot => $dd) {
227+
echo('<tr class="' . ((++$i % 2) == 0 ? 'odd' : 'even') . '">');
228+
echo('<td style="">' . $dd[0] . '</td>');
229+
echo('<td class="datacontent">' . $dd[1] . '</td>');
206230

207-
echo '<table style="">';
208-
foreach ($this->data['debugdata'] AS $dd) {
209-
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>';
231+
foreach($this->data['topdelimiters'] AS $key) {
232+
echo('<td class="datacontent">' .
233+
(array_key_exists($key, $this->data['results'][$slot]) ? $this->data['results'][$slot][$key] : '&nbsp;') .
234+
'</td>');
235+
}
236+
echo('</tr>');
210237
}
211238
echo '</table>';
212239

modules/statistics/www/showstats.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
$availrulenames = array_keys($available_rules);
8484

8585
// Get selected rulename....
86-
$rule = $availrulenames[0];
86+
$rule = $statconfig->getString('default', $availrulenames[0]);
8787
if(array_key_exists('rule', $_GET)) {
8888
if (array_key_exists($_GET['rule'], $available_rules)) {
8989
$rule = $_GET['rule'];
@@ -94,9 +94,6 @@
9494

9595

9696

97-
98-
99-
10097
/*
10198
* Get list of avaiable times in current file (rule)
10299
*/
@@ -176,7 +173,7 @@
176173
$maxvaluetime = $datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra);
177174
}
178175
$maxvalue = max($res[$maxdelimiter],$maxvalue);
179-
$debugdata[] = array($datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra), $res[$maxdelimiter] );
176+
$debugdata[$slot] = array($datehandler->prettyDateSlot($slot, $slotsize, $dateformat_intra), $res[$maxdelimiter] );
180177
}
181178
$max = sspmod_statistics_Graph_GoogleCharts::roof($maxvalue);
182179

@@ -189,7 +186,7 @@
189186
/**
190187
* Aggregate summary table from dataset. To be used in the table view.
191188
*/
192-
$summaryDataset = array();
189+
$summaryDataset = array();
193190
foreach($results AS $slot => $res) {
194191
foreach ($res AS $key => $value) {
195192
if (array_key_exists($key, $summaryDataset)) {
@@ -201,11 +198,29 @@
201198
}
202199
asort($summaryDataset);
203200
$summaryDataset = array_reverse($summaryDataset, TRUE);
204-
#echo '<pre>'; print_r($summaryDataset); exit;
201+
// echo '<pre>'; print_r($summaryDataset); exit;
202+
203+
/*
204+
* Create a list of delimiter keys that has the highest total summary in this period.
205+
*/
206+
$topdelimiters = array();
207+
$maxdelimiters = 4; $i = 0;
208+
foreach($summaryDataset AS $key => $value) {
209+
if ($key !== '_')
210+
$topdelimiters[] = $key;
211+
if ($i++ >= $maxdelimiters) break;
212+
}
205213

214+
// echo('<pre>'); print_r($topdelimiters); exit;
206215

207216

208217

218+
$piedata = array(); $sum = 0;
219+
foreach($topdelimiters AS $td) {
220+
$sum += $summaryDataset[$td];
221+
$piedata[] = number_format(100*$summaryDataset[$td] / $summaryDataset['_'], 2);
222+
}
223+
$piedata[] = number_format(100*($sum /$summaryDataset['_']), 2);
209224

210225

211226
$datasets = array();
@@ -314,10 +329,21 @@ function getPercentValues($results, $delimiter) {
314329
}
315330

316331

332+
$pieaxis = array();
333+
foreach($topdelimiters AS $key) {
334+
$keyName = $key;
335+
if(array_key_exists($key, $delimiterPresentation)) $keyName = $delimiterPresentation[$key];
336+
$pieaxis[] = $keyName;
337+
}
338+
$pieaxis[] = 'Others';
339+
317340

318341

319342
$t->data['header'] = 'stat';
320343
$t->data['imgurl'] = $grapher->show($axis, $axispos, $datasets, $max);
344+
345+
$t->data['pieimgurl'] = $grapher->showPie($pieaxis, $piedata);
346+
321347
$t->data['available.rules'] = $available_rules;
322348
$t->data['available.times'] = $available_times;
323349
$t->data['available.times.prev'] = $available_times_prev;
@@ -329,7 +355,9 @@ function getPercentValues($results, $delimiter) {
329355
$t->data['selected.rule']= $rule;
330356
$t->data['selected.time'] = $fileslot;
331357
$t->data['debugdata'] = $debugdata;
358+
$t->data['results'] = $results;
332359
$t->data['summaryDataset'] = $summaryDataset;
360+
$t->data['topdelimiters'] = $topdelimiters;
333361
$t->data['availdelimiters'] = array_keys($availdelimiters);
334362
$t->data['delimiterPresentation'] = $delimiterPresentation;
335363
$t->show();

0 commit comments

Comments
 (0)