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

Added support for Ratio type reports in the statistics module..

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1535 44740490-163a-0410-bde0-09ae8108e29a
parent b5e53b15
No related branches found
No related tags found
No related merge requests found
...@@ -140,19 +140,28 @@ $config = array ( ...@@ -140,19 +140,28 @@ $config = array (
), ),
), ),
'statrules' => array( 'statrules' => array(
// 'sloratio' => array( 'sloratio' => array(
// 'name' => 'SSO to SLO ratio', 'name' => 'SLO to SSO ratio',
// 'descr' => 'ratio', 'descr' => 'Comparison of the number of Single Log-Out compared to Single Sign-On. Graph shows how many logouts where initiated for each Single Sign-On.',
// 'type' => 'calculated',
// 'type' => 'ratio', 'presenter' => 'statistics:Ratio',
// 'ref' => array('slo', 'sso'),
// 'action' => 'saml20-idp-SSO', 'fieldPresentation' => array(
// 'col' => 6, // Service Provider EntityID 'class' => 'statistics:Entity',
// 'fieldPresentation' => array( 'config' => 'saml20-sp-remote',
// 'class' => 'statistics:Entity', ),
// 'config' => 'saml20-sp-remote', ),
// ), 'ssomulti' => array(
// ), 'name' => 'Requests per session',
'descr' => 'Number of SSO request pairs exchanged between IdP and SP within the same IdP session. A high number indicates that the session at the SP is timing out faster than at the IdP.',
'type' => 'calculated',
'presenter' => 'statistics:Ratio',
'ref' => array('sso', 'ssofirst'),
'fieldPresentation' => array(
'class' => 'statistics:Entity',
'config' => 'saml20-sp-remote',
),
),
'sso' => array( 'sso' => array(
'name' => 'SSO to service', 'name' => 'SSO to service',
'descr' => 'The number of logins at a Service Provider.', 'descr' => 'The number of logins at a Service Provider.',
...@@ -194,8 +203,8 @@ $config = array ( ...@@ -194,8 +203,8 @@ $config = array (
), ),
), ),
'slo' => array( 'slo' => array(
'name' => 'Logout', 'name' => 'SLO initiated from service',
'descr' => 'The number of initated Sinlge Logout.', 'descr' => 'The number of initated Sinlge Logout from each of the service providers.',
'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( 'fieldPresentation' => array(
...@@ -223,7 +232,6 @@ $config = array ( ...@@ -223,7 +232,6 @@ $config = array (
'config' => 'saml20-sp-remote', 'config' => 'saml20-sp-remote',
), ),
), ),
), ),
); );
......
...@@ -138,7 +138,11 @@ class sspmod_statistics_Aggregator { ...@@ -138,7 +138,11 @@ class sspmod_statistics_Aggregator {
// Iterate all the statrules from config. // Iterate all the statrules from config.
foreach ($this->statrules AS $rulename => $rule) { foreach ($this->statrules AS $rulename => $rule) {
$type = 'aggregate';
if (array_key_exists('type', $rule)) $type = $rule['type'];
if ($type !== 'aggregate') continue;
foreach($this->timeres AS $tres => $tresconfig ) { foreach($this->timeres AS $tres => $tresconfig ) {
// echo 'Comparing action: [' . $rule['action'] . '] with [' . $action . ']' . "\n"; // echo 'Comparing action: [' . $rule['action'] . '] with [' . $action . ']' . "\n";
......
<?php
/*
* @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @version $Id$
*/
class sspmod_statistics_RatioDataset extends sspmod_statistics_StatDataset {
public function aggregateSummary() {
/**
* Aggregate summary table from dataset. To be used in the table view.
*/
$this->summary = array();
$noofvalues = array();
foreach($this->results AS $slot => $res) {
foreach ($res AS $key => $value) {
if (array_key_exists($key, $this->summary)) {
$this->summary[$key] += $value;
if ($value > 0)
$noofvalues[$key]++;
} else {
$this->summary[$key] = $value;
if ($value > 0)
$noofvalues[$key] = 1;
else
$noofvalues[$key] = 0;
}
}
}
foreach($this->summary AS $key => $val) {
$this->summary[$key] = $this->divide($this->summary[$key], $noofvalues[$key]);
}
asort($this->summary);
$this->summary = array_reverse($this->summary, TRUE);
// echo '<pre>'; print_r($summaryDataset); exit;
}
private function ag($k, $a) {
if (array_key_exists($k, $a)) return $a[$k];
return 0;
}
private function divide($v1, $v2) {
if ($v2 == 0) return 0;
return ($v1 / $v2);
}
public function combine($result1, $result2) {
$combined = array();
foreach($result2 AS $tick => $val) {
$combined[$tick] = array();
foreach($val AS $index => $num) {
$combined[$tick][$index] = $this->divide(
$this->ag($index, $result1[$tick]),
$this->ag($index, $result2[$tick])
);
}
}
// echo('<pre>');
// echo('combine 1 ');
// print_r($result1);
// echo('combine 2 ');
// print_r($result2);
// echo('combineed ');
// print_r($combined);
//
// exit;
return $combined;
}
public function getPieData() {
return NULL;
}
}
...@@ -47,11 +47,12 @@ class sspmod_statistics_Ruleset { ...@@ -47,11 +47,12 @@ class sspmod_statistics_Ruleset {
/* /*
* Create array with information about available rules.. * Create array with information about available rules..
*/ */
$this->availrules = array_keys($statrules);
$available_rules = array(); $available_rules = array();
foreach ($this->available AS $key => $av) { foreach ($this->availrules AS $key) {
$available_rules[$key] = array('name' => $statrules[$key]['name'], 'descr' => $statrules[$key]['descr']); $available_rules[$key] = array('name' => $statrules[$key]['name'], 'descr' => $statrules[$key]['descr']);
} }
$this->availrules = array_keys($available_rules); // echo('<pre>'); print_r($available_rules); exit;
$this->availrulenames = $available_rules; $this->availrulenames = $available_rules;
} }
...@@ -81,7 +82,9 @@ class sspmod_statistics_Ruleset { ...@@ -81,7 +82,9 @@ class sspmod_statistics_Ruleset {
$rule = $this->resolveSelectedRule($preferRule); $rule = $this->resolveSelectedRule($preferRule);
$statrulesConfig = $this->statconfig->getConfigItem('statrules'); $statrulesConfig = $this->statconfig->getConfigItem('statrules');
$statruleConfig = $statrulesConfig->getConfigItem($rule); $statruleConfig = $statrulesConfig->getConfigItem($rule);
$statrule = new sspmod_statistics_StatRule($this->statconfig, $statruleConfig, $rule, $this->available[$rule]);
$presenterClass = SimpleSAML_Module::resolveClass($statruleConfig->getValue('presenter', 'statistics:BaseRule'), 'Statistics_Rulesets');
$statrule = new $presenterClass($this->statconfig, $statruleConfig, $rule, $this->available);
return $statrule; return $statrule;
} }
......
...@@ -6,21 +6,21 @@ ...@@ -6,21 +6,21 @@
*/ */
class sspmod_statistics_StatDataset { class sspmod_statistics_StatDataset {
private $statconfig; protected $statconfig;
private $ruleconfig; protected $ruleconfig;
private $timeresconfig; protected $timeresconfig;
private $ruleid; protected $ruleid;
private $fileslot; protected $fileslot;
private $timeres; protected $timeres;
private $delimiter; protected $delimiter;
private $results; protected $results;
private $summary; protected $summary;
private $max; protected $max;
private $datehandlerFile; protected $datehandlerFile;
private $datehandlerTick; protected $datehandlerTick;
/** /**
* Constructor * Constructor
...@@ -294,19 +294,29 @@ class sspmod_statistics_StatDataset { ...@@ -294,19 +294,29 @@ class sspmod_statistics_StatDataset {
public function loadData() { public function loadData() {
$statdir = $this->statconfig->getValue('statdir'); $statdir = $this->statconfig->getValue('statdir');
$resarray = array();
$rules = SimpleSAML_Utilities::arrayize($this->ruleid);
foreach($rules AS $rule) {
// Get file and extract results.
$resultFileName = $statdir . '/' . $rule . '-' . $this->timeres . '-'. $this->fileslot . '.stat';
if (!file_exists($resultFileName))
throw new Exception('Aggregated statitics file [' . $resultFileName . '] not found.');
if (!is_readable($resultFileName))
throw new Exception('Could not read statitics file [' . $resultFileName . ']. Bad file permissions?');
$resultfile = file_get_contents($resultFileName);
$newres = unserialize($resultfile);
if (empty($newres))
throw new Exception('Aggregated statistics in file [' . $resultFileName . '] was empty.');
$resarray[] = $newres;
}
// Get file and extract results. $combined = $resarray[0];
$resultFileName = $statdir . '/' . $this->ruleid . '-' . $this->timeres . '-'. $this->fileslot . '.stat'; if(count($resarray) > 1) {
if (!file_exists($resultFileName)) for($i = 1; $i < count($resarray); $i++) {
throw new Exception('Aggregated statitics file [' . $resultFileName . '] not found.'); $combined = $this->combine($combined, $resarray[$i]);
if (!is_readable($resultFileName)) }
throw new Exception('Could not read statitics file [' . $resultFileName . ']. Bad file permissions?'); }
$resultfile = file_get_contents($resultFileName); $this->results = $combined;
$this->results = unserialize($resultfile);
if (empty($this->results))
throw new Exception('Aggregated statistics in file [' . $resultFileName . '] was empty.');
// echo('<pre>'); print_r($this->results); exit;
} }
} }
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
* @package simpleSAMLphp * @package simpleSAMLphp
* @version $Id$ * @version $Id$
*/ */
class sspmod_statistics_StatRule { class sspmod_statistics_Statistics_Rulesets_BaseRule {
protected $statconfig;
protected $ruleconfig;
protected $ruleid;
protected $available;
private $statconfig;
private $ruleconfig;
private $ruleid;
private $available;
// private $datehandler;
/** /**
* Constructor * Constructor
*/ */
...@@ -20,10 +20,9 @@ class sspmod_statistics_StatRule { ...@@ -20,10 +20,9 @@ class sspmod_statistics_StatRule {
$this->statconfig = $statconfig; $this->statconfig = $statconfig;
$this->ruleconfig = $ruleconfig; $this->ruleconfig = $ruleconfig;
$this->ruleid = $ruleid; $this->ruleid = $ruleid;
$this->available = $available;
$this->available = NULL;
// $this->datehandlerFile = $datehandler; if (array_key_exists($ruleid, $available)) $this->available = $available[$ruleid];
// $this->datehandlerTick = $datehandler;
} }
public function getRuleID() { public function getRuleID() {
...@@ -67,7 +66,7 @@ class sspmod_statistics_StatRule { ...@@ -67,7 +66,7 @@ class sspmod_statistics_StatRule {
return $available_times; return $available_times;
} }
private function resolveTimeRes($preferTimeRes) { protected function resolveTimeRes($preferTimeRes) {
$timeresavailable = array_keys($this->available); $timeresavailable = array_keys($this->available);
$timeres = $timeresavailable[0]; $timeres = $timeresavailable[0];
...@@ -78,7 +77,7 @@ class sspmod_statistics_StatRule { ...@@ -78,7 +77,7 @@ class sspmod_statistics_StatRule {
return $timeres; return $timeres;
} }
private function resolveFileSlot($timeres, $preferTime) { protected function resolveFileSlot($timeres, $preferTime) {
// Get which time (fileslot) to use.. First get a default, which is the most recent one. // Get which time (fileslot) to use.. First get a default, which is the most recent one.
$fileslot = $this->available[$timeres][count($this->available[$timeres])-1]; $fileslot = $this->available[$timeres][count($this->available[$timeres])-1];
......
<?php
/*
* @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @version $Id$
*/
class sspmod_statistics_Statistics_Rulesets_Ratio extends sspmod_statistics_Statistics_Rulesets_BaseRule {
protected $refrule1;
protected $refrule2;
/**
* Constructor
*/
public function __construct($statconfig, $ruleconfig, $ruleid, $available) {
assert('$statconfig instanceof SimpleSAML_Configuration');
assert('$ruleconfig instanceof SimpleSAML_Configuration');
parent::__construct($statconfig, $ruleconfig, $ruleid, $available);
$refNames = $this->ruleconfig->getArray('ref');
$statrulesConfig = $this->statconfig->getConfigItem('statrules');
$statruleConfig1 = $statrulesConfig->getConfigItem($refNames[0]);
$statruleConfig2 = $statrulesConfig->getConfigItem($refNames[1]);
$this->refrule1 = new sspmod_statistics_Statistics_Rulesets_BaseRule($this->statconfig, $statruleConfig1, $refNames[0], $available);
$this->refrule2 = new sspmod_statistics_Statistics_Rulesets_BaseRule($this->statconfig, $statruleConfig2, $refNames[1], $available);
}
public function availableTimeRes() {
return $this->refrule1->availableTimeRes();
}
public function availableFileSlots($timeres) {
return $this->refrule1->availableFileSlots($timeres);
}
protected function resolveTimeRes($preferTimeRes) {
return $this->refrule1->resolveTimeRes($preferTimeRes);
}
protected function resolveFileSlot($timeres, $preferTime) {
return $this->refrule1->resolveFileSlot($timeres, $preferTime);
}
public function getTimeNavigation($timeres, $preferTime) {
return $this->refrule1->getTimeNavigation($timeres, $preferTime);
}
public function getDataSet($preferTimeRes, $preferTime) {
$timeres = $this->resolveTimeRes($preferTimeRes);
$fileslot = $this->resolveFileSlot($timeres, $preferTime);
$refNames = $this->ruleconfig->getArray('ref');
$dataset = new sspmod_statistics_RatioDataset($this->statconfig, $this->ruleconfig, $refNames, $timeres, $fileslot);
return $dataset;
}
}
...@@ -234,8 +234,9 @@ echo '</div>'; # end graph content. ...@@ -234,8 +234,9 @@ echo '</div>'; # end graph content.
$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'] . '" />'); if (isset($this->data['pieimgurl'])) {
echo('<img src="' . $this->data['pieimgurl'] . '" />');
}
echo '<table class="tableview"><tr><th class="value">Value</th><th class="category">Data range</th>'; echo '<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 ) {
......
...@@ -111,7 +111,9 @@ SimpleSAML_Module::callHooks('htmlinject', $hookinfo); ...@@ -111,7 +111,9 @@ SimpleSAML_Module::callHooks('htmlinject', $hookinfo);
$t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php'); $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php');
$t->data['header'] = 'stat'; $t->data['header'] = 'stat';
$t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $max); $t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $max);
$t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata); if (isset($piedata)) {
$t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata);
}
$t->data['available.rules'] = $ruleset->availableRulesNames(); $t->data['available.rules'] = $ruleset->availableRulesNames();
$t->data['available.times'] = $statrule->availableFileSlots($timeres); $t->data['available.times'] = $statrule->availableFileSlots($timeres);
$t->data['available.timeres'] = $statrule->availableTimeRes(); $t->data['available.timeres'] = $statrule->availableTimeRes();
......
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