ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_statistics_StatDataset Class Reference
+ Inheritance diagram for sspmod_statistics_StatDataset:
+ Collaboration diagram for sspmod_statistics_StatDataset:

Public Member Functions

 __construct ($statconfig, $ruleconfig, $ruleid, $timeres, $fileslot)
 Constructor. More...
 
 getFileSlot ()
 
 getTimeRes ()
 
 setDelimiter ($delimiter='_')
 
 getDelimiter ()
 
 calculateMax ()
 
 getDebugData ()
 
 aggregateSummary ()
 
 getTopDelimiters ()
 
 availDelimiters ()
 
 getPieData ()
 
 getMax ()
 
 getSummary ()
 
 getResults ()
 
 getAxis ()
 
 getPercentValues ()
 
 getDelimiterPresentation ()
 
 getDelimiterPresentationPie ()
 
 loadData ()
 

Protected Attributes

 $statconfig
 
 $ruleconfig
 
 $timeresconfig
 
 $ruleid
 
 $fileslot
 
 $timeres
 
 $delimiter
 
 $results
 
 $summary
 
 $max
 
 $datehandlerFile
 
 $datehandlerTick
 

Detailed Description

Definition at line 8 of file StatDataset.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_statistics_StatDataset::__construct (   $statconfig,
  $ruleconfig,
  $ruleid,
  $timeres,
  $fileslot 
)

Constructor.

Definition at line 30 of file StatDataset.php.

References $datehandlerTick, $fileslot, $ruleconfig, $ruleid, $statconfig, $timeres, and loadData().

31  {
32  assert($statconfig instanceof SimpleSAML_Configuration);
33  assert($ruleconfig instanceof SimpleSAML_Configuration);
34  $this->statconfig = $statconfig;
35  $this->ruleconfig = $ruleconfig;
36 
37  $timeresconfigs = $statconfig->getConfigItem('timeres');
38  $this->timeresconfig = $timeresconfigs->getConfigItem($timeres);
39 
40  $this->ruleid = $ruleid;
41  $this->fileslot = $fileslot;
42  $this->timeres = $timeres;
43 
44  $this->delimiter = '_';
45  $this->max = 0;
46 
47  $this->datehandlerTick = new sspmod_statistics_DateHandler($this->statconfig->getValue('offset', 0));
48  if ($this->timeresconfig->getValue('customDateHandler', 'default') === 'month') {
49  $this->datehandlerFile = new sspmod_statistics_DateHandlerMonth(0);
50  } else {
51  $this->datehandlerFile = $this->datehandlerTick;
52  }
53 
54  $this->loadData();
55  }
+ Here is the call graph for this function:

Member Function Documentation

◆ aggregateSummary()

sspmod_statistics_StatDataset::aggregateSummary ( )

Definition at line 111 of file StatDataset.php.

References $key, and $res.

112  {
113  // aggregate summary table from dataset. To be used in the table view
114  $this->summary = array();
115  foreach ($this->results as $slot => $res) {
116  foreach ($res as $key => $value) {
117  if (array_key_exists($key, $this->summary)) {
118  $this->summary[$key] += $value;
119  } else {
120  $this->summary[$key] = $value;
121  }
122  }
123  }
124  asort($this->summary);
125  $this->summary = array_reverse($this->summary, true);
126  }
foreach($_POST as $key=> $value) $res
$key
Definition: croninfo.php:18

◆ availDelimiters()

sspmod_statistics_StatDataset::availDelimiters ( )

Definition at line 145 of file StatDataset.php.

References $key.

Referenced by getDelimiterPresentation().

146  {
147  $availDelimiters = array();
148  foreach ($this->summary as $key => $value) {
149  $availDelimiters[$key] = 1;
150  }
151  return array_keys($availDelimiters);
152  }
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ calculateMax()

sspmod_statistics_StatDataset::calculateMax ( )

Definition at line 83 of file StatDataset.php.

References $delimiter, $res, and sspmod_statistics_Graph_GoogleCharts\roof().

84  {
85  $maxvalue = 0;
86  foreach ($this->results as $slot => &$res) {
87  if (!array_key_exists($this->delimiter, $res)) {
89  }
90  $maxvalue = max($res[$this->delimiter], $maxvalue);
91  }
92  $this->max = sspmod_statistics_Graph_GoogleCharts::roof($maxvalue);
93  }
static roof($max)
Takes a input value, and generates a value that suits better as a max value on the Y-axis...
foreach($_POST as $key=> $value) $res
+ Here is the call graph for this function:

◆ getAxis()

sspmod_statistics_StatDataset::getAxis ( )

Definition at line 183 of file StatDataset.php.

References $axis, $i, and $res.

184  {
185  $slotsize = $this->timeresconfig->getValue('slot');
186  $dateformat_intra = $this->timeresconfig->getValue('dateformat-intra');
187  $axislabelint = $this->timeresconfig->getValue('axislabelint');
188 
189  $axis = array();
190  $axispos = array();
191  $xentries = count($this->results);
192  $lastslot = 0;
193  $i = 0;
194 
195  foreach ($this->results as $slot => $res) {
196  // check if there should be an axis here...
197  if ($slot % $axislabelint == 0) {
198  $axis[] = $this->datehandlerTick->prettyDateSlot($slot, $slotsize, $dateformat_intra);
199  $axispos[] = (($i) / ($xentries - 1));
200  }
201  $lastslot = $slot;
202  $i++;
203  }
204 
205  $axis[] = $this->datehandlerTick->prettyDateSlot($lastslot + 1, $slotsize, $dateformat_intra);
206 
207  return array('axis' => $axis, 'axispos' => $axispos);
208  }
foreach($_POST as $key=> $value) $res
$i
Definition: disco.tpl.php:19
$axis
Definition: showstats.php:88

◆ getDebugData()

sspmod_statistics_StatDataset::getDebugData ( )

Definition at line 95 of file StatDataset.php.

References $delimiter, and $res.

96  {
97  $debugdata = array();
98 
99  $slotsize = $this->timeresconfig->getValue('slot');
100  $dateformat_intra = $this->timeresconfig->getValue('dateformat-intra');
101 
102  foreach ($this->results as $slot => &$res) {
103  $debugdata[$slot] = array(
104  $this->datehandlerTick->prettyDateSlot($slot, $slotsize, $dateformat_intra),
106  );
107  }
108  return $debugdata;
109  }
foreach($_POST as $key=> $value) $res

◆ getDelimiter()

sspmod_statistics_StatDataset::getDelimiter ( )

Definition at line 75 of file StatDataset.php.

References $delimiter.

76  {
77  if ($this->delimiter === '_') {
78  return null;
79  }
80  return $this->delimiter;
81  }

◆ getDelimiterPresentation()

sspmod_statistics_StatDataset::getDelimiterPresentation ( )

Definition at line 233 of file StatDataset.php.

References $config, $t, availDelimiters(), SimpleSAML_Configuration\getInstance(), and SimpleSAML\Module\resolveClass().

Referenced by getDelimiterPresentationPie().

234  {
236  $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics.tpl.php');
237 
238  $availdelimiters = $this->availDelimiters();
239 
240  // create a delimiter presentation filter for this rule...
241  if ($this->ruleconfig->hasValue('fieldPresentation')) {
242  $fieldpresConfig = $this->ruleconfig->getConfigItem('fieldPresentation');
243  $classname = SimpleSAML\Module::resolveClass(
244  $fieldpresConfig->getValue('class'),
245  'Statistics_FieldPresentation'
246  );
247  if (!class_exists($classname)) {
248  throw new Exception('Could not find field presentation plugin ['.$classname.']: No class found');
249  }
250  $presentationHandler = new $classname($availdelimiters, $fieldpresConfig->getValue('config'), $t);
251 
252  return $presentationHandler->getPresentation();
253  }
254 
255  return array();
256  }
$config
Definition: bootstrap.php:15
static resolveClass($id, $type, $subclass=null)
Resolve module class.
Definition: Module.php:169
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDelimiterPresentationPie()

sspmod_statistics_StatDataset::getDelimiterPresentationPie ( )

Definition at line 258 of file StatDataset.php.

References $key, getDelimiterPresentation(), and getTopDelimiters().

259  {
260  $topdelimiters = $this->getTopDelimiters();
261  $delimiterPresentation = $this->getDelimiterPresentation();
262 
263  $pieaxis = array();
264  foreach ($topdelimiters as $key) {
265  $keyName = $key;
266  if (array_key_exists($key, $delimiterPresentation)) {
267  $keyName = $delimiterPresentation[$key];
268  }
269  $pieaxis[] = $keyName;
270  }
271  $pieaxis[] = 'Others';
272  return $pieaxis;
273  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getFileSlot()

sspmod_statistics_StatDataset::getFileSlot ( )

Definition at line 57 of file StatDataset.php.

References $fileslot.

58  {
59  return $this->fileslot;
60  }

◆ getMax()

sspmod_statistics_StatDataset::getMax ( )

Definition at line 168 of file StatDataset.php.

References $max.

169  {
170  return $this->max;
171  }

◆ getPercentValues()

sspmod_statistics_StatDataset::getPercentValues ( )

Definition at line 213 of file StatDataset.php.

References $i, and $res.

214  {
215  $i = 0;
216  $dataset = array();
217  foreach ($this->results as $slot => $res) {
218  if (array_key_exists($this->delimiter, $res)) {
219  if ($res[$this->delimiter] === null) {
220  $dataset[] = -1;
221  } else {
222  $dataset[] = number_format(100 * $res[$this->delimiter] / $this->max, 2);
223  }
224  } else {
225  $dataset[] = '0';
226  }
227  $i++;
228  }
229 
230  return $dataset;
231  }
foreach($_POST as $key=> $value) $res
$i
Definition: disco.tpl.php:19

◆ getPieData()

sspmod_statistics_StatDataset::getPieData ( )

Definition at line 154 of file StatDataset.php.

References $piedata, and getTopDelimiters().

155  {
156  $piedata = array();
157  $sum = 0;
158  $topdelimiters = $this->getTopDelimiters();
159 
160  foreach ($topdelimiters as $td) {
161  $sum += $this->summary[$td];
162  $piedata[] = number_format(100 * $this->summary[$td] / $this->summary['_'], 2);
163  }
164  $piedata[] = number_format(100 - 100 * ($sum / $this->summary['_']), 2);
165  return $piedata;
166  }
$piedata
Definition: showstats.php:83
+ Here is the call graph for this function:

◆ getResults()

sspmod_statistics_StatDataset::getResults ( )

Definition at line 178 of file StatDataset.php.

References $results.

179  {
180  return $this->results;
181  }

◆ getSummary()

sspmod_statistics_StatDataset::getSummary ( )

Definition at line 173 of file StatDataset.php.

References $summary.

174  {
175  return $this->summary;
176  }

◆ getTimeRes()

sspmod_statistics_StatDataset::getTimeRes ( )

Definition at line 62 of file StatDataset.php.

References $timeres.

63  {
64  return $this->timeres;
65  }

◆ getTopDelimiters()

sspmod_statistics_StatDataset::getTopDelimiters ( )

Definition at line 128 of file StatDataset.php.

References $i, and $key.

Referenced by getDelimiterPresentationPie(), and getPieData().

129  {
130  // create a list of delimiter keys that has the highest total summary in this period
131  $topdelimiters = array();
132  $maxdelimiters = 4;
133  $i = 0;
134  foreach ($this->summary as $key => $value) {
135  if ($key !== '_') {
136  $topdelimiters[] = $key;
137  }
138  if ($i++ >= $maxdelimiters) {
139  break;
140  }
141  }
142  return $topdelimiters;
143  }
$i
Definition: disco.tpl.php:19
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ loadData()

sspmod_statistics_StatDataset::loadData ( )

Definition at line 275 of file StatDataset.php.

References $i, $rule, and SimpleSAML\Utils\Arrays\arrayize().

Referenced by __construct().

276  {
277  $statdir = $this->statconfig->getValue('statdir');
278  $resarray = array();
279  $rules = SimpleSAML\Utils\Arrays::arrayize($this->ruleid);
280  foreach ($rules as $rule) {
281  // Get file and extract results.
282  $resultFileName = $statdir.'/'.$rule.'-'.$this->timeres.'-'.$this->fileslot.'.stat';
283  if (!file_exists($resultFileName)) {
284  throw new Exception('Aggregated statitics file ['.$resultFileName.'] not found.');
285  }
286  if (!is_readable($resultFileName)) {
287  throw new Exception('Could not read statitics file ['.$resultFileName.']. Bad file permissions?');
288  }
289  $resultfile = file_get_contents($resultFileName);
290  $newres = unserialize($resultfile);
291  if (empty($newres)) {
292  throw new Exception('Aggregated statistics in file ['.$resultFileName.'] was empty.');
293  }
294  $resarray[] = $newres;
295  }
296 
297  $combined = $resarray[0];
298  $count = count($resarray);
299  if ($count > 1) {
300  for ($i = 1; $i < $count; $i++) {
301  $combined = $this->combine($combined, $resarray[$i]);
302  }
303  }
304  $this->results = $combined;
305  }
static arrayize($data, $index=0)
Put a non-array variable into an array.
Definition: Arrays.php:24
$rule
Definition: showstats.php:43
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDelimiter()

sspmod_statistics_StatDataset::setDelimiter (   $delimiter = '_')

Definition at line 67 of file StatDataset.php.

References $delimiter.

68  {
69  if (empty($delimiter)) {
70  $delimiter = '_';
71  }
72  $this->delimiter = $delimiter;
73  }

Field Documentation

◆ $datehandlerFile

sspmod_statistics_StatDataset::$datehandlerFile
protected

Definition at line 23 of file StatDataset.php.

◆ $datehandlerTick

sspmod_statistics_StatDataset::$datehandlerTick
protected

Definition at line 24 of file StatDataset.php.

Referenced by __construct().

◆ $delimiter

sspmod_statistics_StatDataset::$delimiter
protected

Definition at line 18 of file StatDataset.php.

Referenced by calculateMax(), getDebugData(), getDelimiter(), and setDelimiter().

◆ $fileslot

sspmod_statistics_StatDataset::$fileslot
protected

Definition at line 15 of file StatDataset.php.

Referenced by __construct(), and getFileSlot().

◆ $max

sspmod_statistics_StatDataset::$max
protected

Definition at line 21 of file StatDataset.php.

Referenced by getMax().

◆ $results

sspmod_statistics_StatDataset::$results
protected

Definition at line 19 of file StatDataset.php.

Referenced by getResults().

◆ $ruleconfig

sspmod_statistics_StatDataset::$ruleconfig
protected

Definition at line 11 of file StatDataset.php.

Referenced by __construct().

◆ $ruleid

sspmod_statistics_StatDataset::$ruleid
protected

Definition at line 13 of file StatDataset.php.

Referenced by __construct().

◆ $statconfig

sspmod_statistics_StatDataset::$statconfig
protected

Definition at line 10 of file StatDataset.php.

Referenced by __construct().

◆ $summary

sspmod_statistics_StatDataset::$summary
protected

Definition at line 20 of file StatDataset.php.

Referenced by getSummary().

◆ $timeres

sspmod_statistics_StatDataset::$timeres
protected

Definition at line 16 of file StatDataset.php.

Referenced by __construct(), and getTimeRes().

◆ $timeresconfig

sspmod_statistics_StatDataset::$timeresconfig
protected

Definition at line 12 of file StatDataset.php.


The documentation for this class was generated from the following file: