diff --git a/modules/statistics/lib/Aggregator.php b/modules/statistics/lib/Aggregator.php index 9be2b4e2d441ecd574f9479394754e0db282d011..576e0227b429984418c332e066de78ee62dd1f41 100644 --- a/modules/statistics/lib/Aggregator.php +++ b/modules/statistics/lib/Aggregator.php @@ -109,6 +109,10 @@ class sspmod_statistics_Aggregator { // Iterate the first level of results, which is per rule, as defined in the config. foreach ($results AS $rulename => $ruleresults) { + + $filenos = array_keys($ruleresults); + $lastfile = $filenos[count($filenos)-1]; + // Iterate the second level of results, which is the fileslot. foreach ($ruleresults AS $fileno => $fileres) { @@ -129,10 +133,11 @@ class sspmod_statistics_Aggregator { $filledresult[$slot] = $fileres[$slot]; } else { #echo('SLot [' . $slot . '] of [' . $maxslot . ']' . "\n"); - if ($slot > $maxslot) { - $filledresult[$slot] = array('_' => -1); - } else { + if ($lastfile == $fileno && $slot > $maxslot) { + #if ($slot > $maxslot) { $filledresult[$slot] = array('_' => NULL); + } else { + $filledresult[$slot] = array('_' => 0); } } #print_r($filledresult[$slot]); diff --git a/modules/statistics/lib/Statistics/FieldPresentation/Base.php b/modules/statistics/lib/Statistics/FieldPresentation/Base.php new file mode 100644 index 0000000000000000000000000000000000000000..18eb0bdecc17238b4fe1518388bd1aa29d5f8abd --- /dev/null +++ b/modules/statistics/lib/Statistics/FieldPresentation/Base.php @@ -0,0 +1,20 @@ +<?php + +class sspmod_statistics_Statistics_FieldPresentation_Base { + + protected $fields; + protected $template; + protected $config; + + function __construct($fields, $config, $template) { + $this->fields = $fields; + $this->template = $template; + $this->config = $config; + } + + public function getPresentation() { + return array('_' => 'Total'); + } + + +} \ No newline at end of file diff --git a/modules/statistics/lib/Statistics/FieldPresentation/Entity.php b/modules/statistics/lib/Statistics/FieldPresentation/Entity.php new file mode 100644 index 0000000000000000000000000000000000000000..27b13b9893efe75a23f6a36a26a66bde3009b5dd --- /dev/null +++ b/modules/statistics/lib/Statistics/FieldPresentation/Entity.php @@ -0,0 +1,20 @@ +<?php + +class sspmod_statistics_Statistics_FieldPresentation_Entity extends sspmod_statistics_Statistics_FieldPresentation_Base { + + + public function getPresentation() { + $mh = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler(); + $metadata = $mh->getList($this->config); + + $translation = array('_' => 'All services'); + foreach($this->fields AS $field) { + if (array_key_exists($field, $metadata)) + $translation[$field] = $this->template->t($metadata[$field]['name'], array(), FALSE); + } + return $translation; + } + + + +} \ No newline at end of file diff --git a/modules/statistics/templates/statistics-tpl.php b/modules/statistics/templates/statistics-tpl.php index caf06c1edf3ae32cc30d35055e3e0d7adc7cde3b..5e498e52a3861bb624bc83959f7baa1242ef9077 100644 --- a/modules/statistics/templates/statistics-tpl.php +++ b/modules/statistics/templates/statistics-tpl.php @@ -73,17 +73,24 @@ echo '</td>'; // Select delimiter echo '<td style="text-align: right">'; + +#echo('<pre>here'); print_r($this->data['delimiterPresentation']); echo('</pre>'); + echo '<form style="display: inline">'; echo '<input type="hidden" name="rule" value="' . $this->data['selected.rule'] . '" />'; echo '<input type="hidden" name="time" value="' . $this->data['selected.time'] . '" />'; echo '<select onChange="submit();" name="d">'; foreach ($this->data['availdelimiters'] AS $key => $delim) { + + $delimName = $delim; + if(array_key_exists($delim, $this->data['delimiterPresentation'])) $delimName = $this->data['delimiterPresentation'][$delim]; + if ($key == '_') { echo '<option value="_">Total</option>'; } elseif ($delim == $_REQUEST['d']) { - echo '<option selected="selected" value="' . $delim . '">' . $delim . '</option>'; + echo '<option selected="selected" value="' . htmlentities($delim) . '">' . htmlentities($delimName) . '</option>'; } else { - echo '<option value="' . $delim . '">' . $delim . '</option>'; + echo '<option value="' . htmlentities($delim) . '">' . htmlentities($delimName) . '</option>'; } } echo '</select></form>'; diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php index 43ee123ae1841726612012a0784bdd7abd651560..b1f05db4f6d0182d0d45e94aac046745e441231f 100644 --- a/modules/statistics/www/showstats.php +++ b/modules/statistics/www/showstats.php @@ -92,6 +92,13 @@ if(array_key_exists('rule', $_GET)) { } } + + + + + + + /* * Get list of avaiable times in current file (rule) */ @@ -226,8 +233,11 @@ function getPercentValues($results, $delimiter) { $dataset = array(); foreach($results AS $slot => $res) { #echo ('<p>new value: ' . number_format(100*$res[$delimiter] / $max, 2)); +// echo('<hr><p>delimiter [<tt>' .$delimiter . '</tt>].'); +// echo('<p>Res <pre>'); print_r($res); echo( '</pre>'); +// echo('<p>return <pre>'); print_r(isset($res[$delimiter]) ? $res[$delimiter] : 'NO'); echo('</pre>'); if (array_key_exists($delimiter, $res)) { - if ($res[$delimiter] === -1) { + if ($res[$delimiter] === NULL) { $dataset[] = -1; } else { $dataset[] = number_format(100*$res[$delimiter] / $max, 2); @@ -253,13 +263,23 @@ function getPercentValues($results, $delimiter) { -$datasets[] = getPercentValues($results, '_'); +$datasets[] = getPercentValues($results, $delimiter); if ($delimiter !== '_') { if (array_key_exists('graph.total', $statrules[$rule]) && $statrules[$rule]['graph.total'] === TRUE) { - $datasets[] = getPercentValues($results, $delimiter); + $datasets[] = getPercentValues($results, '_'); } } + + + + + + + + + + #echo('<pre>'); print_r($datasets); exit; #echo 'set axis on lastslot [' . $lastslot . ']'; @@ -280,6 +300,24 @@ SimpleSAML_Module::callHooks('htmlinject', $hookinfo); $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php'); + + +/* + * Create a delimiter presentation filter for this rule... + */ +$delimiterPresentation = NULL; +if (array_key_exists('fieldPresentation', $statrules[$rule])) { + $classname = SimpleSAML_Module::resolveClass( $statrules[$rule]['fieldPresentation']['class'], 'Statistics_FieldPresentation'); + if (!class_exists($classname)) + throw new Exception('Could not find field presentation plugin [' . $classname . ']: No class found'); + + $presentationHandler = new $classname(array_keys($availdelimiters), $statrules[$rule]['fieldPresentation']['config'], $t); + $delimiterPresentation = $presentationHandler->getPresentation(); +} + + + + $t->data['header'] = 'stat'; $t->data['imgurl'] = $grapher->show($axis, $axispos, $datasets, $max); $t->data['available.rules'] = $available_rules; @@ -295,5 +333,6 @@ $t->data['selected.time'] = $fileslot; $t->data['debugdata'] = $debugdata; $t->data['summaryDataset'] = $summaryDataset; $t->data['availdelimiters'] = array_keys($availdelimiters); +$t->data['delimiterPresentation'] = $delimiterPresentation; $t->show();