Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
efef966a
Commit
efef966a
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Code reformat and cleanup.
parent
a62353dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/statistics/lib/StatDataset.php
+321
-304
321 additions, 304 deletions
modules/statistics/lib/StatDataset.php
with
321 additions
and
304 deletions
modules/statistics/lib/StatDataset.php
+
321
−
304
View file @
efef966a
<?php
<?php
/*
/**
* @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
* @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @package simpleSAMLphp
*/
*/
class
sspmod_statistics_StatDataset
{
class
sspmod_statistics_StatDataset
{
protected
$statconfig
;
protected
$ruleconfig
;
protected
$statconfig
;
protected
$timeresconfig
;
protected
$ruleconfig
;
protected
$ruleid
;
protected
$timeresconfig
;
protected
$ruleid
;
protected
$fileslot
;
protected
$timeres
;
protected
$fileslot
;
protected
$timeres
;
protected
$delimiter
;
protected
$results
;
protected
$delimiter
;
protected
$summary
;
protected
$results
;
protected
$max
;
protected
$summary
;
protected
$max
;
protected
$datehandlerFile
;
protected
$datehandlerTick
;
protected
$datehandlerFile
;
protected
$datehandlerTick
;
/**
* Constructor
*/
/**
public
function
__construct
(
$statconfig
,
$ruleconfig
,
$ruleid
,
$timeres
,
$fileslot
)
{
* Constructor
assert
(
'$statconfig instanceof SimpleSAML_Configuration'
);
*/
assert
(
'$ruleconfig instanceof SimpleSAML_Configuration'
);
public
function
__construct
(
$statconfig
,
$ruleconfig
,
$ruleid
,
$timeres
,
$fileslot
)
$this
->
statconfig
=
$statconfig
;
{
$this
->
ruleconfig
=
$ruleconfig
;
assert
(
'$statconfig instanceof SimpleSAML_Configuration'
);
assert
(
'$ruleconfig instanceof SimpleSAML_Configuration'
);
$timeresconfigs
=
$statconfig
->
getConfigItem
(
'timeres'
);
$this
->
statconfig
=
$statconfig
;
$this
->
timeresconfig
=
$timeresconfigs
->
getConfigItem
(
$timeres
);
$this
->
ruleconfig
=
$ruleconfig
;
$this
->
ruleid
=
$ruleid
;
$timeresconfigs
=
$statconfig
->
getConfigItem
(
'timeres'
);
$this
->
fileslot
=
$fileslot
;
$this
->
timeresconfig
=
$timeresconfigs
->
getConfigItem
(
$timeres
);
$this
->
timeres
=
$timeres
;
$this
->
ruleid
=
$ruleid
;
$this
->
fileslot
=
$fileslot
;
$this
->
delimiter
=
'_'
;
$this
->
timeres
=
$timeres
;
$this
->
max
=
0
;
$this
->
delimiter
=
'_'
;
$this
->
datehandlerTick
=
new
sspmod_statistics_DateHandler
(
$this
->
statconfig
->
getValue
(
'offset'
,
0
));
$this
->
max
=
0
;
if
(
$this
->
timeresconfig
->
getValue
(
'customDateHandler'
,
'default'
)
===
'month'
)
{
$this
->
datehandlerFile
=
new
sspmod_statistics_DateHandlerMonth
(
0
);
$this
->
datehandlerTick
=
new
sspmod_statistics_DateHandler
(
$this
->
statconfig
->
getValue
(
'offset'
,
0
));
}
else
{
if
(
$this
->
timeresconfig
->
getValue
(
'customDateHandler'
,
'default'
)
===
'month'
)
{
$datehandlerFile
=
$this
->
datehandlerTick
;
$this
->
datehandlerFile
=
new
sspmod_statistics_DateHandlerMonth
(
0
);
}
}
else
{
$this
->
datehandlerFile
=
$this
->
datehandlerTick
;
}
$this
->
loadData
();
$this
->
loadData
();
}
}
public
function
getFileSlot
()
{
public
function
getFileSlot
()
return
$this
->
fileslot
;
{
}
return
$this
->
fileslot
;
}
public
function
getTimeRes
()
{
return
$this
->
timeres
;
}
public
function
getTimeRes
()
{
public
function
setDelimiter
(
$delimiter
=
'_'
)
{
return
$this
->
timeres
;
if
(
empty
(
$delimiter
))
$delimiter
=
'_'
;
}
$this
->
delimiter
=
$delimiter
;
}
public
function
getDelimiter
()
{
public
function
setDelimiter
(
$delimiter
=
'_'
)
if
(
$this
->
delimiter
===
'_'
)
return
NULL
;
{
return
$this
->
delimiter
;
if
(
empty
(
$delimiter
))
{
}
$delimiter
=
'_'
;
}
public
function
calculateMax
()
{
$this
->
delimiter
=
$delimiter
;
}
/*
* Get rule specific configuration from the configuration file.
*/
public
function
getDelimiter
()
$slotsize
=
$this
->
ruleconfig
->
getValue
(
'slot'
);
{
$dateformat_period
=
$this
->
timeresconfig
->
getValue
(
'dateformat-period'
);
if
(
$this
->
delimiter
===
'_'
)
{
$dateformat_intra
=
$this
->
timeresconfig
->
getValue
(
'dateformat-intra'
);
return
null
;
}
return
$this
->
delimiter
;
$maxvalue
=
0
;
$maxvaluetime
=
NULL
;
}
foreach
(
$this
->
results
AS
$slot
=>
&
$res
)
{
if
(
!
array_key_exists
(
$this
->
delimiter
,
$res
))
$res
[
$this
->
delimiter
]
=
0
;
if
(
$res
[
$this
->
delimiter
]
>
$maxvalue
)
{
public
function
calculateMax
()
$maxvaluetime
=
$this
->
datehandlerTick
->
prettyDateSlot
(
$slot
,
$slotsize
,
$dateformat_intra
);
{
}
$maxvalue
=
0
;
$maxvalue
=
max
(
$res
[
$this
->
delimiter
],
$maxvalue
);
foreach
(
$this
->
results
as
$slot
=>
&
$res
)
{
}
if
(
!
array_key_exists
(
$this
->
delimiter
,
$res
))
{
$this
->
max
=
sspmod_statistics_Graph_GoogleCharts
::
roof
(
$maxvalue
);
$res
[
$this
->
delimiter
]
=
0
;
}
}
$maxvalue
=
max
(
$res
[
$this
->
delimiter
],
$maxvalue
);
public
function
getDebugData
()
{
}
$debugdata
=
array
();
$this
->
max
=
sspmod_statistics_Graph_GoogleCharts
::
roof
(
$maxvalue
);
}
$slotsize
=
$this
->
timeresconfig
->
getValue
(
'slot'
);
$dateformat_period
=
$this
->
timeresconfig
->
getValue
(
'dateformat-period'
);
$dateformat_intra
=
$this
->
timeresconfig
->
getValue
(
'dateformat-intra'
);
public
function
getDebugData
()
{
foreach
(
$this
->
results
AS
$slot
=>
&
$res
)
{
$debugdata
=
array
();
$debugdata
[
$slot
]
=
array
(
$this
->
datehandlerTick
->
prettyDateSlot
(
$slot
,
$slotsize
,
$dateformat_intra
),
$res
[
$this
->
delimiter
]
);
}
$slotsize
=
$this
->
timeresconfig
->
getValue
(
'slot'
);
return
$debugdata
;
$dateformat_intra
=
$this
->
timeresconfig
->
getValue
(
'dateformat-intra'
);
}
foreach
(
$this
->
results
as
$slot
=>
&
$res
)
{
public
function
aggregateSummary
()
{
$debugdata
[
$slot
]
=
array
(
$this
->
datehandlerTick
->
prettyDateSlot
(
$slot
,
$slotsize
,
$dateformat_intra
),
/**
$res
[
$this
->
delimiter
]
* Aggregate summary table from dataset. To be used in the table view.
);
*/
}
$this
->
summary
=
array
();
return
$debugdata
;
foreach
(
$this
->
results
AS
$slot
=>
$res
)
{
}
foreach
(
$res
AS
$key
=>
$value
)
{
if
(
array_key_exists
(
$key
,
$this
->
summary
))
{
$this
->
summary
[
$key
]
+=
$value
;
public
function
aggregateSummary
()
}
else
{
{
$this
->
summary
[
$key
]
=
$value
;
// aggregate summary table from dataset. To be used in the table view
}
$this
->
summary
=
array
();
}
foreach
(
$this
->
results
as
$slot
=>
$res
)
{
}
foreach
(
$res
as
$key
=>
$value
)
{
asort
(
$this
->
summary
);
if
(
array_key_exists
(
$key
,
$this
->
summary
))
{
$this
->
summary
=
array_reverse
(
$this
->
summary
,
TRUE
);
$this
->
summary
[
$key
]
+=
$value
;
}
}
else
{
$this
->
summary
[
$key
]
=
$value
;
public
function
getTopDelimiters
()
{
}
/*
}
* Create a list of delimiter keys that has the highest total summary in this period.
}
*/
asort
(
$this
->
summary
);
$topdelimiters
=
array
();
$this
->
summary
=
array_reverse
(
$this
->
summary
,
true
);
$maxdelimiters
=
4
;
$i
=
0
;
}
foreach
(
$this
->
summary
AS
$key
=>
$value
)
{
if
(
$key
!==
'_'
)
$topdelimiters
[]
=
$key
;
public
function
getTopDelimiters
()
if
(
$i
++
>=
$maxdelimiters
)
break
;
{
}
// create a list of delimiter keys that has the highest total summary in this period
return
$topdelimiters
;
$topdelimiters
=
array
();
$maxdelimiters
=
4
;
}
$i
=
0
;
foreach
(
$this
->
summary
as
$key
=>
$value
)
{
public
function
availDelimiters
()
{
if
(
$key
!==
'_'
)
{
$availDelimiters
=
array
();
$topdelimiters
[]
=
$key
;
foreach
(
$this
->
summary
AS
$key
=>
$value
)
{
}
if
(
$key
!==
'_'
)
if
(
$i
++
>=
$maxdelimiters
)
{
$topdelimiters
[]
=
$key
;
break
;
$availdelimiters
[
$key
]
=
1
;
}
}
}
return
array_keys
(
$availdelimiters
);
return
$topdelimiters
;
}
}
public
function
getPieData
()
{
public
function
availDelimiters
()
$piedata
=
array
();
$sum
=
0
;
{
$topdelimiters
=
$this
->
getTopDelimiters
();
$availDelimiters
=
array
();
foreach
(
$this
->
summary
as
$key
=>
$value
)
{
foreach
(
$topdelimiters
AS
$td
)
{
$availDelimiters
[
$key
]
=
1
;
$sum
+=
$this
->
summary
[
$td
];
}
$piedata
[]
=
number_format
(
100
*
$this
->
summary
[
$td
]
/
$this
->
summary
[
'_'
],
2
);
return
array_keys
(
$availDelimiters
);
}
}
$piedata
[]
=
number_format
(
100
-
100
*
(
$sum
/
$this
->
summary
[
'_'
]),
2
);
return
$piedata
;
}
public
function
getPieData
()
{
public
function
getMax
()
{
$piedata
=
array
();
return
$this
->
max
;
$sum
=
0
;
}
$topdelimiters
=
$this
->
getTopDelimiters
();
public
function
getSummary
()
{
foreach
(
$topdelimiters
as
$td
)
{
return
$this
->
summary
;
$sum
+=
$this
->
summary
[
$td
];
}
$piedata
[]
=
number_format
(
100
*
$this
->
summary
[
$td
]
/
$this
->
summary
[
'_'
],
2
);
}
public
function
getResults
()
{
$piedata
[]
=
number_format
(
100
-
100
*
(
$sum
/
$this
->
summary
[
'_'
]),
2
);
return
$this
->
results
;
return
$piedata
;
}
}
public
function
getAxis
()
{
$slotsize
=
$this
->
timeresconfig
->
getValue
(
'slot'
);
public
function
getMax
()
$dateformat_period
=
$this
->
timeresconfig
->
getValue
(
'dateformat-period'
);
{
$dateformat_intra
=
$this
->
timeresconfig
->
getValue
(
'dateformat-intra'
);
return
$this
->
max
;
$axislabelint
=
$this
->
timeresconfig
->
getValue
(
'axislabelint'
);
}
$axis
=
array
();
public
function
getSummary
()
$axispos
=
array
();
{
$xentries
=
count
(
$this
->
results
);
return
$this
->
summary
;
$lastslot
=
0
;
$i
=
0
;
}
foreach
(
$this
->
results
AS
$slot
=>
$res
)
{
public
function
getResults
()
// check if there should be an axis here...
{
if
(
$slot
%
$axislabelint
==
0
)
{
return
$this
->
results
;
$axis
[]
=
$this
->
datehandlerTick
->
prettyDateSlot
(
$slot
,
$slotsize
,
$dateformat_intra
);
}
$axispos
[]
=
((
$i
)
/
(
$xentries
-
1
));
}
$lastslot
=
$slot
;
public
function
getAxis
()
$i
++
;
{
}
$slotsize
=
$this
->
timeresconfig
->
getValue
(
'slot'
);
$dateformat_period
=
$this
->
timeresconfig
->
getValue
(
'dateformat-period'
);
$axis
[]
=
$this
->
datehandlerTick
->
prettyDateSlot
(
$lastslot
+
1
,
$slotsize
,
$dateformat_intra
);
$dateformat_intra
=
$this
->
timeresconfig
->
getValue
(
'dateformat-intra'
);
$axislabelint
=
$this
->
timeresconfig
->
getValue
(
'axislabelint'
);
return
array
(
'axis'
=>
$axis
,
'axispos'
=>
$axispos
);
}
$axis
=
array
();
$axispos
=
array
();
$xentries
=
count
(
$this
->
results
);
/*
$lastslot
=
0
;
* Walk through dataset to get percent values from max into dataset[].
$i
=
0
;
*/
public
function
getPercentValues
()
{
foreach
(
$this
->
results
as
$slot
=>
$res
)
{
// check if there should be an axis here...
if
(
$slot
%
$axislabelint
==
0
)
{
$slotsize
=
$this
->
timeresconfig
->
getValue
(
'slot'
);
$axis
[]
=
$this
->
datehandlerTick
->
prettyDateSlot
(
$slot
,
$slotsize
,
$dateformat_intra
);
$dateformat_period
=
$this
->
timeresconfig
->
getValue
(
'dateformat-period'
);
$axispos
[]
=
((
$i
)
/
(
$xentries
-
1
));
$dateformat_intra
=
$this
->
timeresconfig
->
getValue
(
'dateformat-intra'
);
}
$axislabelint
=
$this
->
timeresconfig
->
getValue
(
'axislabelint'
);
$lastslot
=
$slot
;
$i
++
;
$xentries
=
count
(
$this
->
results
);
}
$lastslot
=
0
;
$i
=
0
;
$axis
[]
=
$this
->
datehandlerTick
->
prettyDateSlot
(
$lastslot
+
1
,
$slotsize
,
$dateformat_intra
);
$dataset
=
array
();
return
array
(
'axis'
=>
$axis
,
'axispos'
=>
$axispos
);
foreach
(
$this
->
results
AS
$slot
=>
$res
)
{
}
if
(
array_key_exists
(
$this
->
delimiter
,
$res
))
{
if
(
$res
[
$this
->
delimiter
]
===
NULL
)
{
$dataset
[]
=
-
1
;
/*
}
else
{
* Walk through dataset to get percent values from max into dataset[].
$dataset
[]
=
number_format
(
100
*
$res
[
$this
->
delimiter
]
/
$this
->
max
,
2
);
*/
}
public
function
getPercentValues
()
}
else
{
{
$dataset
[]
=
'0'
;
$i
=
0
;
}
$dataset
=
array
();
$lastslot
=
$slot
;
foreach
(
$this
->
results
as
$slot
=>
$res
)
{
$i
++
;
if
(
array_key_exists
(
$this
->
delimiter
,
$res
))
{
}
if
(
$res
[
$this
->
delimiter
]
===
null
)
{
$dataset
[]
=
-
1
;
return
$dataset
;
}
else
{
}
$dataset
[]
=
number_format
(
100
*
$res
[
$this
->
delimiter
]
/
$this
->
max
,
2
);
}
}
else
{
$dataset
[]
=
'0'
;
public
function
getDelimiterPresentation
()
{
}
$config
=
SimpleSAML_Configuration
::
getInstance
();
$i
++
;
$t
=
new
SimpleSAML_XHTML_Template
(
$config
,
'statistics:statistics-tpl.php'
);
}
$availdelimiters
=
$this
->
availDelimiters
();
return
$dataset
;
}
/*
public
function
getDelimiterPresentation
()
* Create a delimiter presentation filter for this rule...
{
*/
$config
=
SimpleSAML_Configuration
::
getInstance
();
if
(
$this
->
ruleconfig
->
hasValue
(
'fieldPresentation'
))
{
$t
=
new
SimpleSAML_XHTML_Template
(
$config
,
'statistics:statistics-tpl.php'
);
$fieldpresConfig
=
$this
->
ruleconfig
->
getConfigItem
(
'fieldPresentation'
);
$classname
=
SimpleSAML_Module
::
resolveClass
(
$fieldpresConfig
->
getValue
(
'class'
),
'Statistics_FieldPresentation'
);
$availdelimiters
=
$this
->
availDelimiters
();
if
(
!
class_exists
(
$classname
))
throw
new
Exception
(
'Could not find field presentation plugin ['
.
$classname
.
']: No class found'
);
// create a delimiter presentation filter for this rule...
$presentationHandler
=
new
$classname
(
$availdelimiters
,
$fieldpresConfig
->
getValue
(
'config'
),
$t
);
if
(
$this
->
ruleconfig
->
hasValue
(
'fieldPresentation'
))
{
$fieldpresConfig
=
$this
->
ruleconfig
->
getConfigItem
(
'fieldPresentation'
);
return
$presentationHandler
->
getPresentation
();
$classname
=
SimpleSAML_Module
::
resolveClass
(
}
$fieldpresConfig
->
getValue
(
'class'
),
'Statistics_FieldPresentation'
return
array
();
);
}
if
(
!
class_exists
(
$classname
))
{
throw
new
Exception
(
'Could not find field presentation plugin ['
.
$classname
.
']: No class found'
);
public
function
getDelimiterPresentationPie
()
{
}
$topdelimiters
=
$this
->
getTopDelimiters
();
$presentationHandler
=
new
$classname
(
$availdelimiters
,
$fieldpresConfig
->
getValue
(
'config'
),
$t
);
$delimiterPresentation
=
$this
->
getDelimiterPresentation
();
return
$presentationHandler
->
getPresentation
();
$pieaxis
=
array
();
}
foreach
(
$topdelimiters
AS
$key
)
{
$keyName
=
$key
;
return
array
();
if
(
array_key_exists
(
$key
,
$delimiterPresentation
))
$keyName
=
$delimiterPresentation
[
$key
];
}
$pieaxis
[]
=
$keyName
;
}
$pieaxis
[]
=
'Others'
;
public
function
getDelimiterPresentationPie
()
return
$pieaxis
;
{
}
$topdelimiters
=
$this
->
getTopDelimiters
();
$delimiterPresentation
=
$this
->
getDelimiterPresentation
();
$pieaxis
=
array
();
public
function
loadData
()
{
foreach
(
$topdelimiters
as
$key
)
{
$keyName
=
$key
;
$statdir
=
$this
->
statconfig
->
getValue
(
'statdir'
);
if
(
array_key_exists
(
$key
,
$delimiterPresentation
))
{
$resarray
=
array
();
$keyName
=
$delimiterPresentation
[
$key
];
$rules
=
SimpleSAML\Utils\Arrays
::
arrayize
(
$this
->
ruleid
);
}
foreach
(
$rules
AS
$rule
)
{
$pieaxis
[]
=
$keyName
;
// Get file and extract results.
}
$resultFileName
=
$statdir
.
'/'
.
$rule
.
'-'
.
$this
->
timeres
.
'-'
.
$this
->
fileslot
.
'.stat'
;
$pieaxis
[]
=
'Others'
;
if
(
!
file_exists
(
$resultFileName
))
return
$pieaxis
;
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
);
public
function
loadData
()
$newres
=
unserialize
(
$resultfile
);
{
if
(
empty
(
$newres
))
$statdir
=
$this
->
statconfig
->
getValue
(
'statdir'
);
throw
new
Exception
(
'Aggregated statistics in file ['
.
$resultFileName
.
'] was empty.'
);
$resarray
=
array
();
$resarray
[]
=
$newres
;
$rules
=
SimpleSAML\Utils\Arrays
::
arrayize
(
$this
->
ruleid
);
}
foreach
(
$rules
as
$rule
)
{
// Get file and extract results.
$combined
=
$resarray
[
0
];
$resultFileName
=
$statdir
.
'/'
.
$rule
.
'-'
.
$this
->
timeres
.
'-'
.
$this
->
fileslot
.
'.stat'
;
$count
=
count
(
$resarray
);
if
(
!
file_exists
(
$resultFileName
))
{
if
(
$count
>
1
)
{
throw
new
Exception
(
'Aggregated statitics file ['
.
$resultFileName
.
'] not found.'
);
for
(
$i
=
1
;
$i
<
$count
;
$i
++
)
{
}
$combined
=
$this
->
combine
(
$combined
,
$resarray
[
$i
]);
if
(
!
is_readable
(
$resultFileName
))
{
}
throw
new
Exception
(
'Could not read statitics file ['
.
$resultFileName
.
']. Bad file permissions?'
);
}
}
$this
->
results
=
$combined
;
$resultfile
=
file_get_contents
(
$resultFileName
);
}
$newres
=
unserialize
(
$resultfile
);
if
(
empty
(
$newres
))
{
throw
new
Exception
(
'Aggregated statistics in file ['
.
$resultFileName
.
'] was empty.'
);
}
$resarray
[]
=
$newres
;
}
$combined
=
$resarray
[
0
];
$count
=
count
(
$resarray
);
if
(
$count
>
1
)
{
for
(
$i
=
1
;
$i
<
$count
;
$i
++
)
{
$combined
=
$this
->
combine
(
$combined
,
$resarray
[
$i
]);
}
}
$this
->
results
=
$combined
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment