{{lang_totalTime}}
{{lang_medianSessionLength}}
-
{{lang_totalLogins}}
+
{{lang_sessions}}
+
{{lang_shortSessions}}
{{lang_totalOffTime}}
{{lang_clientLogout}}
{{lang_clientStart}}
--
cgit v1.2.3-55-g7522
From 2ab12fa0ce5fe4c916d5426e05656e61b4005b1e Mon Sep 17 00:00:00 2001
From: Udo Walter
Date: Thu, 22 Dec 2016 16:10:13 +0100
Subject: [statistics_reporting] changed cutoffs
---
.../inc/statisticreporting.inc.php | 41 +++++++++-------------
.../lang/de/template-tags.json | 4 +--
.../lang/en/template-tags.json | 4 +--
.../statistics_reporting/page.inc.php | 15 ++++----
4 files changed, 28 insertions(+), 36 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
index 7b1dcfdc..626aa290 100644
--- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php
+++ b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
@@ -4,17 +4,16 @@
class StatisticReporting
{
- public static function getClientStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $queryTime = time() - $cutOffTimeInSeconds;
+ public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, longSessions, lastLogout, lastStart, shortSessions FROM (
SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout'
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $queryTime)." sessionTable
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
GROUP BY machine.machineuuid
) t1
INNER JOIN (
SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.dateline) AS 'lastStart'
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $queryTime)." offlineTable
+ FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
GROUP BY machine.machineuuid
) t2
@@ -23,19 +22,17 @@ class StatisticReporting
}
// IFNULL(location.locationname, '') - emptry string can be replaced with anything (name of the null-ids in the table)
- public static function getLocationStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $queryTime = time() - $cutOffTimeInSeconds;
-
+ public static function getLocationStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT t1.locName, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
SELECT IFNULL(location.locationname, '') AS 'locName', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions'
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $queryTime)." sessionTable
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
GROUP BY location.locationname
) t1
INNER JOIN (
SELECT IFNULL(location.locationname, '') AS 'locName', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum'
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $queryTime)." offlineTable
+ FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
GROUP BY location.locationname
@@ -45,35 +42,31 @@ class StatisticReporting
}
// logins between bounds
- public static function getUserStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $queryTime = time() - $cutOffTimeInSeconds;
+ public static function getUserStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT username, COUNT(*) AS 'count'
FROM statistic
- WHERE typeid='.vmchooser-session-name' AND dateline>=$queryTime
+ WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
GROUP BY username ORDER BY 2 DESC");
return $res;
}
// vm logins between bounds
- public static function getVMStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $queryTime = time() - $cutOffTimeInSeconds;
- $res = Database::simpleQuery("SELECT data, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline>=$queryTime
+ public static function getVMStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT data, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) GROUP BY data ORDER BY 2 DESC");
return $res;
}
- public static function getOverallStatistics ($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $queryTime = time() - $cutOffTimeInSeconds;
+ public static function getOverallStatistics ($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT SUM(CAST(sessionTable.length AS UNSIGNED)) AS sum, GROUP_CONCAT(sessionTable.length) AS median, SUM(sessionTable.length >= 60) AS longSessions, SUM(sessionTable.length < 60) AS shortSessions
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $queryTime)." sessionTable");
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable");
return $res;
}
- public static function getTotalOfflineStatistics($cutOffTimeInSeconds, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $queryTime = time() - $cutOffTimeInSeconds;
+ public static function getTotalOfflineStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED))
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $queryTime)." offlineTable");
+ FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable");
return $res;
}
@@ -97,13 +90,13 @@ class StatisticReporting
return round($median);
}
- private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound, $cutoffTime)
+ private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound, $cutOff)
{
$lowerFormat = "'%y-%m-%d $lowerTimeBound:00:00'";
$upperFormat = "'%y-%m-%d ".($upperTimeBound-1).":59:59'";
$queryString = "
select
-
+
@startLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)),
@startUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)),
@endLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)),
@@ -157,7 +150,7 @@ class StatisticReporting
machineuuid
from statistic
- where dateline >= $cutoffTime and typeid = '$typeid' and (
+ where dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY) and typeid = '$typeid' and (
(UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat))) or
(UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)))
)
diff --git a/modules-available/statistics_reporting/lang/de/template-tags.json b/modules-available/statistics_reporting/lang/de/template-tags.json
index 68b68250..207949a9 100644
--- a/modules-available/statistics_reporting/lang/de/template-tags.json
+++ b/modules-available/statistics_reporting/lang/de/template-tags.json
@@ -20,8 +20,8 @@
"lang_location": "Raum",
"lang_medianSessionLength": "Mittlere Sitzungsdauer",
"lang_totalTime": "Gesamte Zeit",
- "lang_last1": "Letzten 24 Stunden",
- "lang_last2": "Letzten 48 Stunden",
+ "lang_last1": "Heute",
+ "lang_last2": "Letzten 2 Tage",
"lang_last7": "Letzten 7 Tage",
"lang_last14": "Letzten 14 Tage",
"lang_last30": "Letzten 30 Tage",
diff --git a/modules-available/statistics_reporting/lang/en/template-tags.json b/modules-available/statistics_reporting/lang/en/template-tags.json
index b9e0c61d..e9430960 100644
--- a/modules-available/statistics_reporting/lang/en/template-tags.json
+++ b/modules-available/statistics_reporting/lang/en/template-tags.json
@@ -20,8 +20,8 @@
"lang_location": "Location",
"lang_medianSessionLength": "Median Session Length",
"lang_totalTime": "Total Time",
- "lang_last1": "Last 24 hours",
- "lang_last2": "Last 48 hours",
+ "lang_last1": "Today",
+ "lang_last2": "Last 2 days",
"lang_last7": "Last 7 days",
"lang_last14": "Last 14 days",
"lang_last30": "Last 30 days",
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index f0f56e87..a55ba33f 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -24,8 +24,7 @@ class Page_Statistics_Reporting extends Page
{
// timespan you want to see = Days selected * seconds per Day (86400)
// default = 14 days
- $cutOff = Request::get('cutoff', 14, 'int');
- $cutOffTimer = $cutOff * 86400;
+ $cutOff = Request::get('cutoff', 14, 'int') - 1;
$lowerTimeBound = Request::get('lower', 0, 'int');
@@ -33,17 +32,17 @@ class Page_Statistics_Reporting extends Page
// total time online, average time online, total number of logins
- $res = StatisticReporting::getOverallStatistics($cutOffTimer, $lowerTimeBound, $upperTimeBound);
+ $res = StatisticReporting::getOverallStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$row = $res->fetch(PDO::FETCH_NUM);
$data = array('time' => StatisticReporting::formatSeconds($row[0]), 'medianTime' => StatisticReporting::formatSeconds(StatisticReporting::calcMedian($row[1])), 'sessions' => $row[2], 'shortSessions' => $row[3]);
//total time offline
- $res = StatisticReporting::getTotalOfflineStatistics($cutOffTimer, $lowerTimeBound, $upperTimeBound);
+ $res = StatisticReporting::getTotalOfflineStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$row = $res->fetch(PDO::FETCH_NUM);
$data = array_merge($data, array('totalOfftime' => StatisticReporting::formatSeconds($row[0])));
// per location
- $res = StatisticReporting::getLocationStatistics($cutOffTimer, $lowerTimeBound, $upperTimeBound);
+ $res = StatisticReporting::getLocationStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perLocation' => array());
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
@@ -52,7 +51,7 @@ class Page_Statistics_Reporting extends Page
}
// per client
- $res = StatisticReporting::getClientStatistics($cutOffTimer, $lowerTimeBound, $upperTimeBound);
+ $res = StatisticReporting::getClientStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perClient' => array());
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
@@ -62,14 +61,14 @@ class Page_Statistics_Reporting extends Page
}
// per user
- $res = StatisticReporting::getUserStatistics($cutOffTimer, $lowerTimeBound, $upperTimeBound);
+ $res = StatisticReporting::getUserStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perUser' => array());
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$data['perUser'][] = array('user' => $row[0], 'sessions' => $row[1]);
}
// per vm
- $res = StatisticReporting::getVMStatistics($cutOffTimer, $lowerTimeBound, $upperTimeBound);
+ $res = StatisticReporting::getVMStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perVM' => array());
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$data['perVM'][] = array('vm' => $row[0], 'sessions' => $row[1]);
--
cgit v1.2.3-55-g7522
From e61bb374f6bd7eddd6c7efdc80b835a88a1156e7 Mon Sep 17 00:00:00 2001
From: Christian Hofmaier
Date: Fri, 23 Dec 2016 16:01:58 +0100
Subject: [statistics_reporting] location for clienttable
---
.../statistics_reporting/inc/statisticreporting.inc.php | 5 +++--
modules-available/statistics_reporting/page.inc.php | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
index 626aa290..c821701b 100644
--- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php
+++ b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
@@ -5,10 +5,11 @@ class StatisticReporting
{
public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, longSessions, lastLogout, lastStart, shortSessions FROM (
- SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout'
+ $res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, longSessions, lastLogout, lastStart, shortSessions, locName FROM (
+ SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '') AS 'locName'
FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
+ LEFT JOIN location ON machine.locationid = location.locationid
GROUP BY machine.machineuuid
) t1
INNER JOIN (
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index a55ba33f..8bd593f4 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -57,7 +57,7 @@ class Page_Statistics_Reporting extends Page
$median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
$data['perClient'][] = array('hostname' => $row[0], 'time' => StatisticReporting::formatSeconds($row[1]), 'timeInSeconds' => $row[1],
'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'sessions' => $row[4],
- 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'lastStart' => date(DATE_RSS,$row[6]), 'lastStartUnixtime' => $row[6], 'shortSessions' => $row[7]);
+ 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'lastStart' => date(DATE_RSS,$row[6]), 'lastStartUnixtime' => $row[6], 'shortSessions' => $row[7], 'locationName' => $row[8]);
}
// per user
--
cgit v1.2.3-55-g7522
From d7eaf72343acc41f648f2c1ed6ff1845d9b514c2 Mon Sep 17 00:00:00 2001
From: Christian Hofmaier
Date: Thu, 29 Dec 2016 15:10:43 +0100
Subject: [statistics_reporting] added comments and improved readability
---
.../inc/statisticreporting.inc.php | 31 +++++++++++++++-------
.../statistics_reporting/page.inc.php | 4 +--
2 files changed, 23 insertions(+), 12 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
index b75c6eaa..689af37d 100644
--- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php
+++ b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
@@ -4,9 +4,10 @@
class StatisticReporting
{
+ // Client Data: Name, Time Online, Median Time Online, Time Offline, last logout, Last Time Booted, Number of Sessions > 60Sec, Number of Sessions < 60Sec, name of location
public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
- $res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, longSessions, lastLogout, lastStart, shortSessions, locName FROM (
+ $res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName FROM (
SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '$notassigned') AS 'locName'
FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
@@ -23,7 +24,7 @@ class StatisticReporting
return $res;
}
- // IFNULL(location.locationname, 'NOT ASSIGNED') - NOT ASSIGNED string can be replaced with anything (name of the null-ids in the table)
+ // Location Data: Name, Time Online, Median Time Online, Time Offline, Number of Sessions > 60Sec, Number of Sessions < 60Sec
public static function getLocationStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
$res = Database::simpleQuery("SELECT t1.locName, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
@@ -44,40 +45,47 @@ class StatisticReporting
return $res;
}
- // logins between bounds
+ // User Data: Name, Number of Logins
public static function getUserStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT username, COUNT(*) AS 'count'
FROM statistic
WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
- GROUP BY username ORDER BY 2 DESC");
+ GROUP BY username
+ ORDER BY 2 DESC");
return $res;
}
- // vm logins between bounds
+ // Virtual Machine Data: Name, Number of Usages
public static function getVMStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT data, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
- AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound)) GROUP BY data ORDER BY 2 DESC");
+ AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
+ GROUP BY data
+ ORDER BY 2 DESC");
return $res;
}
+ //Total Data: Time Online, Median Time Online, Number of Sessions > 60Sec, Number of Sessions < 60Sec
public static function getOverallStatistics ($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT SUM(CAST(sessionTable.length AS UNSIGNED)) AS sum, GROUP_CONCAT(sessionTable.length) AS median, SUM(sessionTable.length >= 60) AS longSessions, SUM(sessionTable.length < 60) AS shortSessions
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable");
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable");
return $res;
}
+ // Total Data(2): Time Offline
public static function getTotalOfflineStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED))
FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable");
return $res;
}
+ // Format $seconds into ".d .h .m .s" format (day, hour, minute, second)
public static function formatSeconds($seconds)
{
return intdiv($seconds, 3600*24).'d '.intdiv($seconds%(3600*24), 3600).'h '.intdiv($seconds%3600, 60).'m '.($seconds%60).'s';
}
+ // Calculate Median
public static function calcMedian($string) {
$arr = explode(",", $string);
sort($arr, SORT_NUMERIC);
@@ -93,6 +101,7 @@ class StatisticReporting
return round($median);
}
+ // query string which provides table with time-cutoff and time-bounds
private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound, $cutOff)
{
$lowerFormat = "'%y-%m-%d $lowerTimeBound:00:00'";
@@ -153,9 +162,11 @@ class StatisticReporting
machineuuid
from statistic
- where dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY) and typeid = '$typeid' and (
- (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat))) or
- (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)))
+ where dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY) and typeid = '$typeid'
+ and (
+ (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)))
+ or
+ (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)))
)
";
return "(".$queryString.")";
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index 8bd593f4..13446ed9 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -56,8 +56,8 @@ class Page_Statistics_Reporting extends Page
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
$data['perClient'][] = array('hostname' => $row[0], 'time' => StatisticReporting::formatSeconds($row[1]), 'timeInSeconds' => $row[1],
- 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'sessions' => $row[4],
- 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'lastStart' => date(DATE_RSS,$row[6]), 'lastStartUnixtime' => $row[6], 'shortSessions' => $row[7], 'locationName' => $row[8]);
+ 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'lastStartUnixtime' => $row[4],
+ 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'lastStart' => date(DATE_RSS,$row[6]), 'sessions' => $row[6], 'shortSessions' => $row[7], 'locationName' => $row[8]);
}
// per user
--
cgit v1.2.3-55-g7522
From 18a646aaf1032946574091f5be03347b3cf09855 Mon Sep 17 00:00:00 2001
From: Christian Hofmaier
Date: Mon, 9 Jan 2017 15:11:30 +0100
Subject: [statistics_reporting] bugfix
---
modules-available/statistics_reporting/inc/statisticreporting.inc.php | 2 +-
modules-available/statistics_reporting/page.inc.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
index 689af37d..39aa9377 100644
--- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php
+++ b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
@@ -4,7 +4,7 @@
class StatisticReporting
{
- // Client Data: Name, Time Online, Median Time Online, Time Offline, last logout, Last Time Booted, Number of Sessions > 60Sec, Number of Sessions < 60Sec, name of location
+ // Client Data: Name, Time Online, Median Time Online, Time Offline, last start, last logout, Last Time Booted, Number of Sessions > 60Sec, Number of Sessions < 60Sec, name of location
public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
$res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName FROM (
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index 13446ed9..c309bfb6 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -56,8 +56,8 @@ class Page_Statistics_Reporting extends Page
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
$data['perClient'][] = array('hostname' => $row[0], 'time' => StatisticReporting::formatSeconds($row[1]), 'timeInSeconds' => $row[1],
- 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'lastStartUnixtime' => $row[4],
- 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'lastStart' => date(DATE_RSS,$row[6]), 'sessions' => $row[6], 'shortSessions' => $row[7], 'locationName' => $row[8]);
+ 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'lastStart' => date(DATE_RSS,$row[4]), 'lastStartUnixtime' => $row[4],
+ 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'sessions' => $row[6], 'shortSessions' => $row[7], 'locationName' => $row[8]);
}
// per user
--
cgit v1.2.3-55-g7522
From d7fa39c85738fb998c79a866a7f0ed36b9403a87 Mon Sep 17 00:00:00 2001
From: Christian Hofmaier
Date: Mon, 9 Jan 2017 16:48:45 +0100
Subject: [statistics_reporting] improved readability, added hashed values to
queries
---
.../inc/statisticreporting.inc.php | 20 ++++++-------
.../statistics_reporting/page.inc.php | 34 +++++++++++-----------
2 files changed, 27 insertions(+), 27 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
index 39aa9377..c209c5ef 100644
--- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php
+++ b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
@@ -4,11 +4,11 @@
class StatisticReporting
{
- // Client Data: Name, Time Online, Median Time Online, Time Offline, last start, last logout, Last Time Booted, Number of Sessions > 60Sec, Number of Sessions < 60Sec, name of location
+ // Client Data: Name, Time Online, Median Time Online, Time Offline, last start, last logout, Last Time Booted, Number of Sessions > 60Sec, Number of Sessions < 60Sec, name of location, id of location (anonymized), machine uuid (anonymized)
public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
- $res = Database::simpleQuery("SELECT t1.name, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName FROM (
- SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '$notassigned') AS 'locName'
+ $res = Database::simpleQuery("SELECT t1.name AS clientName, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName, MD5(locId) AS locHash, MD5(t1.uuid) AS clientHash FROM (
+ SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId'
FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
@@ -24,11 +24,11 @@ class StatisticReporting
return $res;
}
- // Location Data: Name, Time Online, Median Time Online, Time Offline, Number of Sessions > 60Sec, Number of Sessions < 60Sec
+ // Location Data: Name, ID (anonymized), Time Online, Median Time Online, Time Offline, Number of Sessions > 60Sec, Number of Sessions < 60Sec
public static function getLocationStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
- $res = Database::simpleQuery("SELECT t1.locName, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
- SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions'
+ $res = Database::simpleQuery("SELECT t1.locName AS locName, MD5(locId) AS locHash, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
+ SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions'
FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
@@ -45,9 +45,9 @@ class StatisticReporting
return $res;
}
- // User Data: Name, Number of Logins
+ // User Data: Name, Name(anonymized), Number of Logins
public static function getUserStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT username, COUNT(*) AS 'count'
+ $res = Database::simpleQuery("SELECT username AS name, IF(username = 'anonymous', 'anonymous', md5(username)) AS userHash, COUNT(*) AS 'count'
FROM statistic
WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
@@ -58,7 +58,7 @@ class StatisticReporting
// Virtual Machine Data: Name, Number of Usages
public static function getVMStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT data, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
+ $res = Database::simpleQuery("SELECT data AS name, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
GROUP BY data
ORDER BY 2 DESC");
@@ -74,7 +74,7 @@ class StatisticReporting
// Total Data(2): Time Offline
public static function getTotalOfflineStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED))
+ $res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED)) AS timeOff
FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable");
return $res;
}
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index c309bfb6..e2c76b09 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -33,45 +33,45 @@ class Page_Statistics_Reporting extends Page
// total time online, average time online, total number of logins
$res = StatisticReporting::getOverallStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $row = $res->fetch(PDO::FETCH_NUM);
- $data = array('time' => StatisticReporting::formatSeconds($row[0]), 'medianTime' => StatisticReporting::formatSeconds(StatisticReporting::calcMedian($row[1])), 'sessions' => $row[2], 'shortSessions' => $row[3]);
+ $row = $res->fetch(PDO::FETCH_ASSOC);
+ $data = array('time' => StatisticReporting::formatSeconds($row['sum']), 'medianTime' => StatisticReporting::formatSeconds(StatisticReporting::calcMedian($row['median'])), 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
//total time offline
$res = StatisticReporting::getTotalOfflineStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $row = $res->fetch(PDO::FETCH_NUM);
- $data = array_merge($data, array('totalOfftime' => StatisticReporting::formatSeconds($row[0])));
+ $row = $res->fetch(PDO::FETCH_ASSOC);
+ $data = array_merge($data, array('totalOfftime' => StatisticReporting::formatSeconds($row['timeOff'])));
// per location
$res = StatisticReporting::getLocationStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perLocation' => array());
- while ($row = $res->fetch(PDO::FETCH_NUM)) {
- $median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
- $data['perLocation'][] = array('location' => $row[0], 'time' => StatisticReporting::formatSeconds($row[1]), 'timeInSeconds' => $row[1],
- 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'sessions' => $row[4], 'shortSessions' => $row[5]);
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row['medianTime']));
+ $data['perLocation'][] = array('location' => $row['locName'], 'time' => StatisticReporting::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
+ 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
}
// per client
$res = StatisticReporting::getClientStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perClient' => array());
- while ($row = $res->fetch(PDO::FETCH_NUM)) {
- $median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row[2]));
- $data['perClient'][] = array('hostname' => $row[0], 'time' => StatisticReporting::formatSeconds($row[1]), 'timeInSeconds' => $row[1],
- 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row[3]), 'offlineTimeInSeconds' => $row[3], 'lastStart' => date(DATE_RSS,$row[4]), 'lastStartUnixtime' => $row[4],
- 'lastLogout' => date(DATE_RSS,$row[5]), 'lastLogoutUnixtime' => $row[5], 'sessions' => $row[6], 'shortSessions' => $row[7], 'locationName' => $row[8]);
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row['medianTime']));
+ $data['perClient'][] = array('hostname' => $row['clientName'], 'time' => StatisticReporting::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
+ 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'lastStart' => date(DATE_RSS,$row['lastStart']), 'lastStartUnixtime' => $row['lastStart'],
+ 'lastLogout' => date(DATE_RSS,$row['lastLogout']), 'lastLogoutUnixtime' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row['locName']);
}
// per user
$res = StatisticReporting::getUserStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perUser' => array());
- while ($row = $res->fetch(PDO::FETCH_NUM)) {
- $data['perUser'][] = array('user' => $row[0], 'sessions' => $row[1]);
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $data['perUser'][] = array('user' => $row['name'], 'sessions' => $row['count']);
}
// per vm
$res = StatisticReporting::getVMStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
$data[] = array('perVM' => array());
- while ($row = $res->fetch(PDO::FETCH_NUM)) {
- $data['perVM'][] = array('vm' => $row[0], 'sessions' => $row[1]);
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $data['perVM'][] = array('vm' => $row['name'], 'sessions' => $row['count']);
}
Render::addTemplate('columnChooser');
--
cgit v1.2.3-55-g7522
From 9ccef127acd6dca0971e12726b019e2beaf7e4ce Mon Sep 17 00:00:00 2001
From: Udo Walter
Date: Thu, 12 Jan 2017 12:41:21 +0100
Subject: [statistics_reporting] moved some functions to a new class
---
.../statistics_reporting/inc/getdata.inc.php | 98 ++++++++++++
.../statistics_reporting/inc/queries.inc.php | 153 ++++++++++++++++++
.../inc/statisticreporting.inc.php | 175 ---------------------
.../statistics_reporting/page.inc.php | 55 +------
4 files changed, 259 insertions(+), 222 deletions(-)
create mode 100644 modules-available/statistics_reporting/inc/getdata.inc.php
create mode 100644 modules-available/statistics_reporting/inc/queries.inc.php
delete mode 100644 modules-available/statistics_reporting/inc/statisticreporting.inc.php
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php
new file mode 100644
index 00000000..a1df66d0
--- /dev/null
+++ b/modules-available/statistics_reporting/inc/getdata.inc.php
@@ -0,0 +1,98 @@
+fetch(PDO::FETCH_ASSOC);
+ $data = array('time' => self::formatSeconds($row['sum']), 'medianTime' => self::formatSeconds(self::calcMedian($row['median'])), 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
+
+ //total time offline
+ $res = Queries::getTotalOfflineStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $row = $res->fetch(PDO::FETCH_ASSOC);
+ $data = array_merge($data, array('totalOfftime' => self::formatSeconds($row['timeOff'])));
+
+ return $data;
+ }
+
+ // per location
+ public static function perLocation($anonymize = false) {
+ $res = Queries::getLocationStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $data = array();
+ $loc = $anonymize ? 'locHash' : 'locName';
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = self::calcMedian(self::calcMedian($row['medianTime']));
+ $data[] = array('location' => $row[$loc], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
+ 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
+ }
+ return $data;
+ }
+
+ // per client
+ public static function perClient($anonymize = false) {
+ $res = Queries::getClientStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $data = array();
+ $name = $anonymize ? 'clientHash' : 'hostname';
+ $loc = $anonymize ? 'locHash' : 'locName';
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = self::calcMedian(self::calcMedian($row['medianTime']));
+ $data[] = array('hostname' => $row[$name], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
+ 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'lastStart' => date(DATE_RSS,$row['lastStart']), 'lastStartUnixtime' => $row['lastStart'],
+ 'lastLogout' => date(DATE_RSS,$row['lastLogout']), 'lastLogoutUnixtime' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row[$loc]);
+ }
+ return $data;
+ }
+
+ // per user
+ public static function perUser($anonymize = false) {
+ $res = Queries::getUserStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $data = array();
+ $user = $anonymize ? 'userHash' : 'name';
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $data[] = array('user' => $row['name'], 'sessions' => $row['count']);
+ }
+ return $data;
+ }
+
+
+ // per vm
+ public static function perVM() {
+ $res = Queries::getVMStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $data = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $data[] = array('vm' => $row['name'], 'sessions' => $row['count']);
+ }
+ return $data;
+ }
+
+
+
+ // Format $seconds into ".d .h .m .s" format (day, hour, minute, second)
+ private static function formatSeconds($seconds)
+ {
+ return intdiv($seconds, 3600*24).'d '.intdiv($seconds%(3600*24), 3600).'h '.intdiv($seconds%3600, 60).'m '.($seconds%60).'s';
+ }
+
+ // Calculate Median
+ private static function calcMedian($string) {
+ $arr = explode(",", $string);
+ sort($arr, SORT_NUMERIC);
+ $count = count($arr); //total numbers in array
+ $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
+ if($count % 2) { // odd number, middle is the median
+ $median = $arr[(int) $middleval];
+ } else { // even number, calculate avg of 2 medians
+ $low = $arr[(int) $middleval];
+ $high = $arr[(int) $middleval+1];
+ $median = (($low+$high)/2);
+ }
+ return round($median);
+ }
+}
\ No newline at end of file
diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php
new file mode 100644
index 00000000..23afceed
--- /dev/null
+++ b/modules-available/statistics_reporting/inc/queries.inc.php
@@ -0,0 +1,153 @@
+ 60Sec, Number of Sessions < 60Sec, name of location, id of location (anonymized), machine uuid (anonymized)
+ public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
+ $res = Database::simpleQuery("SELECT t1.name AS clientName, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName, MD5(locId) AS locHash, MD5(t1.uuid) AS clientHash FROM (
+ SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId'
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
+ INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
+ LEFT JOIN location ON machine.locationid = location.locationid
+ GROUP BY machine.machineuuid
+ ) t1
+ INNER JOIN (
+ SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.dateline) AS 'lastStart'
+ FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
+ INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
+ GROUP BY machine.machineuuid
+ ) t2
+ ON t1.uuid = t2.uuid");
+ return $res;
+ }
+
+ // Location Data: Name, ID (anonymized), Time Online, Median Time Online, Time Offline, Number of Sessions > 60Sec, Number of Sessions < 60Sec
+ public static function getLocationStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
+ $res = Database::simpleQuery("SELECT t1.locName AS locName, MD5(locId) AS locHash, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
+ SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions'
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
+ INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
+ LEFT JOIN location ON machine.locationid = location.locationid
+ GROUP BY location.locationname
+ ) t1
+ INNER JOIN (
+ SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum'
+ FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
+ INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
+ LEFT JOIN location ON machine.locationid = location.locationid
+ GROUP BY location.locationname
+ ) t2
+ ON t1.locName = t2.locName");
+ return $res;
+ }
+
+ // User Data: Name, Name(anonymized), Number of Logins
+ public static function getUserStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT username AS name, IF(username = 'anonymous', 'anonymous', md5(username)) AS userHash, COUNT(*) AS 'count'
+ FROM statistic
+ WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
+ AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
+ GROUP BY username
+ ORDER BY 2 DESC");
+ return $res;
+ }
+
+ // Virtual Machine Data: Name, Number of Usages
+ public static function getVMStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT data AS name, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
+ AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
+ GROUP BY data
+ ORDER BY 2 DESC");
+ return $res;
+ }
+
+ //Total Data: Time Online, Median Time Online, Number of Sessions > 60Sec, Number of Sessions < 60Sec
+ public static function getOverallStatistics ($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT SUM(CAST(sessionTable.length AS UNSIGNED)) AS sum, GROUP_CONCAT(sessionTable.length) AS median, SUM(sessionTable.length >= 60) AS longSessions, SUM(sessionTable.length < 60) AS shortSessions
+ FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable");
+ return $res;
+ }
+
+ // Total Data(2): Time Offline
+ public static function getTotalOfflineStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED)) AS timeOff
+ FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable");
+ return $res;
+ }
+
+ // query string which provides table with time-cutoff and time-bounds
+ private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound, $cutOff)
+ {
+ $lowerFormat = "'%y-%m-%d $lowerTimeBound:00:00'";
+ $upperFormat = "'%y-%m-%d ".($upperTimeBound-1).":59:59'";
+ $queryString = "
+ select
+
+ @startLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)),
+ @startUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)),
+ @endLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)),
+ @endUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)),
+
+ (CAST(data AS SIGNED)
+ - IF(
+ dateline > @startUpper,
+ UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat) + INTERVAL 1 DAY) - dateline,
+ IF(
+ dateline < @startLower,
+ @startLower - dateline,
+ 0
+ )
+ )
+ - IF(
+ dateline+data > @endUpper,
+ dateline+data - (@endUpper + 1),
+ IF(
+ dateline+data < @endLower,
+ dateline+data - (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat) - INTERVAL 1 DAY) + 1),
+ 0
+ )
+ )
+ - ( TO_DAYS(FROM_UNIXTIME(dateline+data, '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(dateline, '%y-%m-%d'))
+ - 2
+ + IF(dateline <= @startUpper, 1, 0)
+ + IF(dateline+data >= @endLower, 1, 0)
+ ) * ((24 - ($upperTimeBound - $lowerTimeBound)) * 3600)
+
+ - IF(
+ @leftBound := IF(dateline <= @startUpper, @startUpper, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat) + INTERVAL 1 DAY))
+ < @rightBound := IF(dateline+data >= @endLower, @endLower, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat) - INTERVAL 1 DAY)),
+ IF(
+ @timeDiff := (
+ (date_format(from_unixtime(@leftBound), '%H') -
+ date_format(convert_tz(from_unixtime(@leftBound), @@session.time_zone, '+00:00'), '%H') + 24) % 24
+ -
+ (date_format(from_unixtime(@rightBound), '%H') -
+ date_format(convert_tz(from_unixtime(@rightBound), @@session.time_zone, '+00:00'), '%H') + 24) % 24) = 1
+ AND ($lowerTimeBound >= 2 OR $upperTimeBound <= 2),
+ 3600,
+ IF(@timeDiff = -1 AND ($lowerTimeBound >= 3 OR $upperTimeBound <= 3), -3600, 0)
+ ),
+ 0
+ )
+
+ ) as 'length',
+ dateline,
+ data,
+ machineuuid
+
+ from statistic
+ where dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY) and typeid = '$typeid'
+ and (
+ (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)))
+ or
+ (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)))
+ )
+ ";
+ return "(".$queryString.")";
+ }
+}
+
diff --git a/modules-available/statistics_reporting/inc/statisticreporting.inc.php b/modules-available/statistics_reporting/inc/statisticreporting.inc.php
deleted file mode 100644
index c209c5ef..00000000
--- a/modules-available/statistics_reporting/inc/statisticreporting.inc.php
+++ /dev/null
@@ -1,175 +0,0 @@
- 60Sec, Number of Sessions < 60Sec, name of location, id of location (anonymized), machine uuid (anonymized)
- public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
- $res = Database::simpleQuery("SELECT t1.name AS clientName, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName, MD5(locId) AS locHash, MD5(t1.uuid) AS clientHash FROM (
- SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId'
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
- INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
- LEFT JOIN location ON machine.locationid = location.locationid
- GROUP BY machine.machineuuid
- ) t1
- INNER JOIN (
- SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.dateline) AS 'lastStart'
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
- INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
- GROUP BY machine.machineuuid
- ) t2
- ON t1.uuid = t2.uuid");
- return $res;
- }
-
- // Location Data: Name, ID (anonymized), Time Online, Median Time Online, Time Offline, Number of Sessions > 60Sec, Number of Sessions < 60Sec
- public static function getLocationStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
- $res = Database::simpleQuery("SELECT t1.locName AS locName, MD5(locId) AS locHash, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
- SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions'
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
- INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
- LEFT JOIN location ON machine.locationid = location.locationid
- GROUP BY location.locationname
- ) t1
- INNER JOIN (
- SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum'
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
- INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
- LEFT JOIN location ON machine.locationid = location.locationid
- GROUP BY location.locationname
- ) t2
- ON t1.locName = t2.locName");
- return $res;
- }
-
- // User Data: Name, Name(anonymized), Number of Logins
- public static function getUserStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT username AS name, IF(username = 'anonymous', 'anonymous', md5(username)) AS userHash, COUNT(*) AS 'count'
- FROM statistic
- WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
- AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
- GROUP BY username
- ORDER BY 2 DESC");
- return $res;
- }
-
- // Virtual Machine Data: Name, Number of Usages
- public static function getVMStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT data AS name, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
- AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
- GROUP BY data
- ORDER BY 2 DESC");
- return $res;
- }
-
- //Total Data: Time Online, Median Time Online, Number of Sessions > 60Sec, Number of Sessions < 60Sec
- public static function getOverallStatistics ($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT SUM(CAST(sessionTable.length AS UNSIGNED)) AS sum, GROUP_CONCAT(sessionTable.length) AS median, SUM(sessionTable.length >= 60) AS longSessions, SUM(sessionTable.length < 60) AS shortSessions
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable");
- return $res;
- }
-
- // Total Data(2): Time Offline
- public static function getTotalOfflineStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED)) AS timeOff
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable");
- return $res;
- }
-
- // Format $seconds into ".d .h .m .s" format (day, hour, minute, second)
- public static function formatSeconds($seconds)
- {
- return intdiv($seconds, 3600*24).'d '.intdiv($seconds%(3600*24), 3600).'h '.intdiv($seconds%3600, 60).'m '.($seconds%60).'s';
- }
-
- // Calculate Median
- public static function calcMedian($string) {
- $arr = explode(",", $string);
- sort($arr, SORT_NUMERIC);
- $count = count($arr); //total numbers in array
- $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
- if($count % 2) { // odd number, middle is the median
- $median = $arr[(int) $middleval];
- } else { // even number, calculate avg of 2 medians
- $low = $arr[(int) $middleval];
- $high = $arr[(int) $middleval+1];
- $median = (($low+$high)/2);
- }
- return round($median);
- }
-
- // query string which provides table with time-cutoff and time-bounds
- private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound, $cutOff)
- {
- $lowerFormat = "'%y-%m-%d $lowerTimeBound:00:00'";
- $upperFormat = "'%y-%m-%d ".($upperTimeBound-1).":59:59'";
- $queryString = "
- select
-
- @startLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)),
- @startUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)),
- @endLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)),
- @endUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)),
-
- (CAST(data AS SIGNED)
- - IF(
- dateline > @startUpper,
- UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat) + INTERVAL 1 DAY) - dateline,
- IF(
- dateline < @startLower,
- @startLower - dateline,
- 0
- )
- )
- - IF(
- dateline+data > @endUpper,
- dateline+data - (@endUpper + 1),
- IF(
- dateline+data < @endLower,
- dateline+data - (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat) - INTERVAL 1 DAY) + 1),
- 0
- )
- )
- - ( TO_DAYS(FROM_UNIXTIME(dateline+data, '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(dateline, '%y-%m-%d'))
- - 2
- + IF(dateline <= @startUpper, 1, 0)
- + IF(dateline+data >= @endLower, 1, 0)
- ) * ((24 - ($upperTimeBound - $lowerTimeBound)) * 3600)
-
- - IF(
- @leftBound := IF(dateline <= @startUpper, @startUpper, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat) + INTERVAL 1 DAY))
- < @rightBound := IF(dateline+data >= @endLower, @endLower, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat) - INTERVAL 1 DAY)),
- IF(
- @timeDiff := (
- (date_format(from_unixtime(@leftBound), '%H') -
- date_format(convert_tz(from_unixtime(@leftBound), @@session.time_zone, '+00:00'), '%H') + 24) % 24
- -
- (date_format(from_unixtime(@rightBound), '%H') -
- date_format(convert_tz(from_unixtime(@rightBound), @@session.time_zone, '+00:00'), '%H') + 24) % 24) = 1
- AND ($lowerTimeBound >= 2 OR $upperTimeBound <= 2),
- 3600,
- IF(@timeDiff = -1 AND ($lowerTimeBound >= 3 OR $upperTimeBound <= 3), -3600, 0)
- ),
- 0
- )
-
- ) as 'length',
- dateline,
- data,
- machineuuid
-
- from statistic
- where dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY) and typeid = '$typeid'
- and (
- (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)))
- or
- (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)))
- )
- ";
- return "(".$queryString.")";
- }
-}
-
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index e2c76b09..82c03acc 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -24,55 +24,16 @@ class Page_Statistics_Reporting extends Page
{
// timespan you want to see = Days selected * seconds per Day (86400)
// default = 14 days
- $cutOff = Request::get('cutoff', 14, 'int') - 1;
+ GetData::$cutOff = Request::get('cutoff', 14, 'int') - 1;
+ GetData::$lowerTimeBound = Request::get('lower', 0, 'int');
+ GetData::$upperTimeBound = Request::get('upper', 24, 'int');
- $lowerTimeBound = Request::get('lower', 0, 'int');
+ $data = array_merge(GetData::total(), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array()));
+ $data['perLocation'] = GetData::perLocation();
+ $data['perClient'] = GetData::perClient();
+ $data['perUser'] = GetData::perUser();
+ $data['perVM'] = GetData::perVM();
- $upperTimeBound = Request::get('upper', 24, 'int');
-
-
- // total time online, average time online, total number of logins
- $res = StatisticReporting::getOverallStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $row = $res->fetch(PDO::FETCH_ASSOC);
- $data = array('time' => StatisticReporting::formatSeconds($row['sum']), 'medianTime' => StatisticReporting::formatSeconds(StatisticReporting::calcMedian($row['median'])), 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
-
- //total time offline
- $res = StatisticReporting::getTotalOfflineStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $row = $res->fetch(PDO::FETCH_ASSOC);
- $data = array_merge($data, array('totalOfftime' => StatisticReporting::formatSeconds($row['timeOff'])));
-
- // per location
- $res = StatisticReporting::getLocationStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $data[] = array('perLocation' => array());
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row['medianTime']));
- $data['perLocation'][] = array('location' => $row['locName'], 'time' => StatisticReporting::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
- 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
- }
-
- // per client
- $res = StatisticReporting::getClientStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $data[] = array('perClient' => array());
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $median = StatisticReporting::calcMedian(StatisticReporting::calcMedian($row['medianTime']));
- $data['perClient'][] = array('hostname' => $row['clientName'], 'time' => StatisticReporting::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
- 'medianTime' => StatisticReporting::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => StatisticReporting::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'lastStart' => date(DATE_RSS,$row['lastStart']), 'lastStartUnixtime' => $row['lastStart'],
- 'lastLogout' => date(DATE_RSS,$row['lastLogout']), 'lastLogoutUnixtime' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row['locName']);
- }
-
- // per user
- $res = StatisticReporting::getUserStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $data[] = array('perUser' => array());
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $data['perUser'][] = array('user' => $row['name'], 'sessions' => $row['count']);
- }
-
- // per vm
- $res = StatisticReporting::getVMStatistics($cutOff, $lowerTimeBound, $upperTimeBound);
- $data[] = array('perVM' => array());
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $data['perVM'][] = array('vm' => $row['name'], 'sessions' => $row['count']);
- }
Render::addTemplate('columnChooser');
Render::addTemplate('_page', $data);
--
cgit v1.2.3-55-g7522
From 5da76e80a9fb64bfbda5897aa08fa1bc575dbd25 Mon Sep 17 00:00:00 2001
From: Udo Walter
Date: Fri, 13 Jan 2017 13:22:27 +0100
Subject: [statistics_reporting] improved cutoff in query functions + bugfix
---
.../statistics_reporting/hooks/cron.inc.php | 3 +
.../statistics_reporting/inc/getdata.inc.php | 17 ++--
.../statistics_reporting/inc/queries.inc.php | 91 +++++++++++++---------
.../statistics_reporting/page.inc.php | 5 +-
4 files changed, 70 insertions(+), 46 deletions(-)
create mode 100644 modules-available/statistics_reporting/hooks/cron.inc.php
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php
new file mode 100644
index 00000000..b79883df
--- /dev/null
+++ b/modules-available/statistics_reporting/hooks/cron.inc.php
@@ -0,0 +1,3 @@
+fetch(PDO::FETCH_ASSOC);
$data = array('time' => self::formatSeconds($row['sum']), 'medianTime' => self::formatSeconds(self::calcMedian($row['median'])), 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
//total time offline
- $res = Queries::getTotalOfflineStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $res = Queries::getTotalOfflineStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$row = $res->fetch(PDO::FETCH_ASSOC);
$data = array_merge($data, array('totalOfftime' => self::formatSeconds($row['timeOff'])));
@@ -24,7 +25,7 @@ class GetData
// per location
public static function perLocation($anonymize = false) {
- $res = Queries::getLocationStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $res = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
$loc = $anonymize ? 'locHash' : 'locName';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
@@ -37,9 +38,9 @@ class GetData
// per client
public static function perClient($anonymize = false) {
- $res = Queries::getClientStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $res = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- $name = $anonymize ? 'clientHash' : 'hostname';
+ $name = $anonymize ? 'clientHash' : 'clientName';
$loc = $anonymize ? 'locHash' : 'locName';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$median = self::calcMedian(self::calcMedian($row['medianTime']));
@@ -52,7 +53,7 @@ class GetData
// per user
public static function perUser($anonymize = false) {
- $res = Queries::getUserStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
$user = $anonymize ? 'userHash' : 'name';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
@@ -64,7 +65,7 @@ class GetData
// per vm
public static function perVM() {
- $res = Queries::getVMStatistics(self::$cutOff, self::$lowerTimeBound, self::$upperTimeBound);
+ $res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$data[] = array('vm' => $row['name'], 'sessions' => $row['count']);
diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php
index 23afceed..23f5fb03 100644
--- a/modules-available/statistics_reporting/inc/queries.inc.php
+++ b/modules-available/statistics_reporting/inc/queries.inc.php
@@ -5,18 +5,18 @@ class Queries
{
// Client Data: Name, Time Online, Median Time Online, Time Offline, last start, last logout, Last Time Booted, Number of Sessions > 60Sec, Number of Sessions < 60Sec, name of location, id of location (anonymized), machine uuid (anonymized)
- public static function getClientStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ public static function getClientStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24, $excludeToday = false) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
$res = Database::simpleQuery("SELECT t1.name AS clientName, timeSum, medianTime, offlineSum, lastStart, lastLogout, longSessions, shortSessions, locName, MD5(locId) AS locHash, MD5(t1.uuid) AS clientHash FROM (
SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions',MAX(sessionTable.dateline + sessionTable.data) AS 'lastLogout', IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId'
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
+ FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
GROUP BY machine.machineuuid
) t1
INNER JOIN (
SELECT machine.hostname AS 'name', machine.machineuuid AS 'uuid', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum', MAX(offlineTable.dateline) AS 'lastStart'
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
+ FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable
INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
GROUP BY machine.machineuuid
) t2
@@ -25,18 +25,18 @@ class Queries
}
// Location Data: Name, ID (anonymized), Time Online, Median Time Online, Time Offline, Number of Sessions > 60Sec, Number of Sessions < 60Sec
- public static function getLocationStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ public static function getLocationStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24, $excludeToday = false) {
$notassigned = Dictionary::translateFile('template-tags', 'lang_notassigned');
$res = Database::simpleQuery("SELECT t1.locName AS locName, MD5(locId) AS locHash, timeSum, medianTime, offlineSum, longSessions, shortSessions FROM (
SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', location.locationid AS 'locId', SUM(CAST(sessionTable.length AS UNSIGNED)) AS 'timeSum', GROUP_CONCAT(sessionTable.length) AS 'medianTime', SUM(sessionTable.length >= 60) AS 'longSessions', SUM(sessionTable.length < 60) AS 'shortSessions'
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable
+ FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable
INNER JOIN machine ON sessionTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
GROUP BY location.locationname
) t1
INNER JOIN (
SELECT IFNULL(location.locationname, '$notassigned') AS 'locName', SUM(CAST(offlineTable.length AS UNSIGNED)) AS 'offlineSum'
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable
+ FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable
INNER JOIN machine ON offlineTable.machineuuid = machine.machineuuid
LEFT JOIN location ON machine.locationid = location.locationid
GROUP BY location.locationname
@@ -46,80 +46,96 @@ class Queries
}
// User Data: Name, Name(anonymized), Number of Logins
- public static function getUserStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT username AS name, IF(username = 'anonymous', 'anonymous', md5(username)) AS userHash, COUNT(*) AS 'count'
+ public static function getUserStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT username AS name, IF(username = 'anonymous', 'anonymous', md5(username)) AS userHash, COUNT(*) AS 'count'
FROM statistic
- WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
- AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
+ WHERE typeid='.vmchooser-session-name' AND dateline+data >= $from and dateline <= $to AND (
+ (@daysDiff := (TO_DAYS(FROM_UNIXTIME(@end := IF(dateline+data > $to, $to, dateline+data), '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(@start := IF(dateline < $from, $from, dateline), '%y-%m-%d'))) = 0
+ and (FROM_UNIXTIME(@end, '%H') >= $lowerTimeBound) AND (FROM_UNIXTIME(@start, '%H') < $upperTimeBound))
+ or
+ (@daysDiff = 1 and (FROM_UNIXTIME(@end, '%H') >= $lowerTimeBound) OR (FROM_UNIXTIME(@start, '%H') < $upperTimeBound))
+ or
+ @daysDiff >= 2
+ )
GROUP BY username
ORDER BY 2 DESC");
return $res;
}
// Virtual Machine Data: Name, Number of Usages
- public static function getVMStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
- $res = Database::simpleQuery("SELECT data AS name, COUNT(*) AS 'count' FROM statistic WHERE typeid='.vmchooser-session-name' AND dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY)
- AND ((FROM_UNIXTIME(dateline+data, '%H')*1 >= $lowerTimeBound) AND (FROM_UNIXTIME(dateline, '%H')*1 < $upperTimeBound))
+ public static function getVMStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ $res = Database::simpleQuery("SELECT data AS name, COUNT(*) AS 'count'
+ FROM statistic
+ WHERE typeid='.vmchooser-session-name' AND dateline+data >= $from and dateline <= $to AND (
+ (@daysDiff := (TO_DAYS(FROM_UNIXTIME(@end := IF(dateline+data > $to, $to, dateline+data), '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(@start := IF(dateline < $from, $from, dateline), '%y-%m-%d'))) = 0
+ and (FROM_UNIXTIME(@end, '%H') >= $lowerTimeBound) AND (FROM_UNIXTIME(@start, '%H') < $upperTimeBound))
+ or
+ (@daysDiff = 1 and (FROM_UNIXTIME(@end, '%H') >= $lowerTimeBound) OR (FROM_UNIXTIME(@start, '%H') < $upperTimeBound))
+ or
+ @daysDiff >= 2
+ )
GROUP BY data
ORDER BY 2 DESC");
return $res;
}
//Total Data: Time Online, Median Time Online, Number of Sessions > 60Sec, Number of Sessions < 60Sec
- public static function getOverallStatistics ($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ public static function getOverallStatistics ($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT SUM(CAST(sessionTable.length AS UNSIGNED)) AS sum, GROUP_CONCAT(sessionTable.length) AS median, SUM(sessionTable.length >= 60) AS longSessions, SUM(sessionTable.length < 60) AS shortSessions
- FROM ".self::getBoundedTableQueryString('~session-length', $lowerTimeBound, $upperTimeBound, $cutOff)." sessionTable");
+ FROM ".self::getBoundedTableQueryString('~session-length', $from, $to, $lowerTimeBound, $upperTimeBound)." sessionTable");
return $res;
}
// Total Data(2): Time Offline
- public static function getTotalOfflineStatistics($cutOff, $lowerTimeBound = 0, $upperTimeBound = 24) {
+ public static function getTotalOfflineStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) {
$res = Database::simpleQuery("SELECT SUM(CAST(offlineTable.length AS UNSIGNED)) AS timeOff
- FROM ".self::getBoundedTableQueryString('~offline-length', $lowerTimeBound, $upperTimeBound, $cutOff)." offlineTable");
+ FROM ".self::getBoundedTableQueryString('~offline-length', $from, $to, $lowerTimeBound, $upperTimeBound)." offlineTable");
return $res;
}
// query string which provides table with time-cutoff and time-bounds
- private static function getBoundedTableQueryString($typeid, $lowerTimeBound, $upperTimeBound, $cutOff)
+ private static function getBoundedTableQueryString($typeid, $from, $to, $lowerTimeBound, $upperTimeBound)
{
$lowerFormat = "'%y-%m-%d $lowerTimeBound:00:00'";
$upperFormat = "'%y-%m-%d ".($upperTimeBound-1).":59:59'";
$queryString = "
select
+ @start := IF(dateline < $from, $from, dateline),
+ @end := IF(dateline+data > $to, $to, dateline+data),
@startLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)),
@startUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)),
@endLower := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)),
@endUpper := UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)),
- (CAST(data AS SIGNED)
+ (CAST(@end-@start AS SIGNED)
- IF(
- dateline > @startUpper,
- UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat) + INTERVAL 1 DAY) - dateline,
+ @start > @startUpper,
+ UNIX_TIMESTAMP(FROM_UNIXTIME(@start, $lowerFormat) + INTERVAL 1 DAY) - @start,
IF(
- dateline < @startLower,
- @startLower - dateline,
+ @start < @startLower,
+ @startLower - @start,
0
)
)
- IF(
- dateline+data > @endUpper,
- dateline+data - (@endUpper + 1),
+ @end > @endUpper,
+ @end - (@endUpper + 1),
IF(
- dateline+data < @endLower,
- dateline+data - (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat) - INTERVAL 1 DAY) + 1),
+ @end < @endLower,
+ @end - (UNIX_TIMESTAMP(FROM_UNIXTIME(@end, $upperFormat) - INTERVAL 1 DAY) + 1),
0
)
)
- - ( TO_DAYS(FROM_UNIXTIME(dateline+data, '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(dateline, '%y-%m-%d'))
- - 2
- + IF(dateline <= @startUpper, 1, 0)
- + IF(dateline+data >= @endLower, 1, 0)
+ - ( TO_DAYS(FROM_UNIXTIME(@end, '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(@start, '%y-%m-%d'))
+ - 2
+ + IF(@start <= @startUpper, 1, 0)
+ + IF(@end >= @endLower, 1, 0)
) * ((24 - ($upperTimeBound - $lowerTimeBound)) * 3600)
- IF(
- @leftBound := IF(dateline <= @startUpper, @startUpper, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat) + INTERVAL 1 DAY))
- < @rightBound := IF(dateline+data >= @endLower, @endLower, UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat) - INTERVAL 1 DAY)),
+ @leftBound := IF(@start <= @startUpper, @startUpper, UNIX_TIMESTAMP(FROM_UNIXTIME(@start, $upperFormat) + INTERVAL 1 DAY))
+ < @rightBound := IF(@end >= @endLower, @endLower, UNIX_TIMESTAMP(FROM_UNIXTIME(@end, $lowerFormat) - INTERVAL 1 DAY)),
IF(
@timeDiff := (
(date_format(from_unixtime(@leftBound), '%H') -
@@ -133,18 +149,19 @@ class Queries
),
0
)
-
) as 'length',
dateline,
data,
machineuuid
from statistic
- where dateline+data >= UNIX_TIMESTAMP(CURDATE() - INTERVAL $cutOff DAY) and typeid = '$typeid'
+ where dateline+data >= $from and dateline <= $to and typeid = '$typeid'
and (
- (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $lowerFormat)) <= dateline and dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)))
+ (@daysDiff := (TO_DAYS(FROM_UNIXTIME(dateline+data, '%y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(dateline, '%y-%m-%d'))) = 0 and (dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)) and dateline+data >= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat))))
or
- (UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat)) <= dateline+data and dateline+data <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $upperFormat)))
+ (@daysDiff = 1 and (dateline <= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline, $upperFormat)) or dateline+data >= UNIX_TIMESTAMP(FROM_UNIXTIME(dateline+data, $lowerFormat))))
+ or
+ @daysDiff >= 2
)
";
return "(".$queryString.")";
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index 82c03acc..aa373f54 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -24,7 +24,10 @@ class Page_Statistics_Reporting extends Page
{
// timespan you want to see = Days selected * seconds per Day (86400)
// default = 14 days
- GetData::$cutOff = Request::get('cutoff', 14, 'int') - 1;
+ $date = new DateTime(date('Y-m-d 00:00:00'));
+ $date->sub(new DateInterval('P'.(Request::get('cutoff', 14, 'int') - 1).'D'));
+ GetData::$from = $date->getTimestamp();
+ GetData::$to = time();
GetData::$lowerTimeBound = Request::get('lower', 0, 'int');
GetData::$upperTimeBound = Request::get('upper', 24, 'int');
--
cgit v1.2.3-55-g7522
From 3df046508f58bbfff51c5cad33f42af4e378bea7 Mon Sep 17 00:00:00 2001
From: Udo Walter
Date: Fri, 13 Jan 2017 16:19:33 +0100
Subject: [statistics_reporting] improved anonymization
---
.../statistics_reporting/inc/getdata.inc.php | 50 +++++++++++++++-------
.../statistics_reporting/page.inc.php | 5 +--
2 files changed, 36 insertions(+), 19 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php
index 8628d9db..880256d6 100644
--- a/modules-available/statistics_reporting/inc/getdata.inc.php
+++ b/modules-available/statistics_reporting/inc/getdata.inc.php
@@ -13,12 +13,18 @@ class GetData
// total time online, average time online, total number of logins
$res = Queries::getOverallStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$row = $res->fetch(PDO::FETCH_ASSOC);
- $data = array('time' => self::formatSeconds($row['sum']), 'medianTime' => self::formatSeconds(self::calcMedian($row['median'])), 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
+ $data = array('time' => $row['sum'], 'medianTime' => self::calcMedian($row['median']), 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
//total time offline
$res = Queries::getTotalOfflineStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$row = $res->fetch(PDO::FETCH_ASSOC);
- $data = array_merge($data, array('totalOfftime' => self::formatSeconds($row['timeOff'])));
+ $data = array_merge($data, array('totalOfftime' => $row['timeOff']));
+
+ if (!$anonymize) {
+ $data["time"] = self::formatSeconds($data["time"]);
+ $data["medianTime"] = self::formatSeconds($data["time"]);
+ $data["totalOfftime"] = self::formatSeconds($data["time"]);
+ }
return $data;
}
@@ -27,11 +33,19 @@ class GetData
public static function perLocation($anonymize = false) {
$res = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- $loc = $anonymize ? 'locHash' : 'locName';
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $median = self::calcMedian(self::calcMedian($row['medianTime']));
- $data[] = array('location' => $row[$loc], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
- 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
+ if (!$anonymize) {
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = self::calcMedian(self::calcMedian($row['medianTime']));
+ $data[] = array('location' => $row['locName'], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
+ 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']),
+ 'offlineTimeInSeconds' => $row['offlineSum'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
+ }
+ } else {
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = self::calcMedian(self::calcMedian($row['medianTime']));
+ $data[] = array('location' => $row['locHash'], 'time' => $row['timeSum'], 'medianTime' => $median, 'offTime' => $row['offlineSum'],
+ 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions']);
+ }
}
return $data;
}
@@ -40,13 +54,19 @@ class GetData
public static function perClient($anonymize = false) {
$res = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- $name = $anonymize ? 'clientHash' : 'clientName';
- $loc = $anonymize ? 'locHash' : 'locName';
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $median = self::calcMedian(self::calcMedian($row['medianTime']));
- $data[] = array('hostname' => $row[$name], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
- 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'lastStart' => date(DATE_RSS,$row['lastStart']), 'lastStartUnixtime' => $row['lastStart'],
- 'lastLogout' => date(DATE_RSS,$row['lastLogout']), 'lastLogoutUnixtime' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row[$loc]);
+ if (!$anonymize) {
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = self::calcMedian(self::calcMedian($row['medianTime']));
+ $data[] = array('hostname' => $row['clientName'], 'time' => self::formatSeconds($row['timeSum']), 'timeInSeconds' => $row['timeSum'],
+ 'medianTime' => self::formatSeconds($median), 'medianTimeInSeconds' => $median, 'offTime' => self::formatSeconds($row['offlineSum']), 'offlineTimeInSeconds' => $row['offlineSum'], 'lastStart' => date(DATE_RSS, $row['lastStart']), 'lastStartUnixtime' => $row['lastStart'],
+ 'lastLogout' => date(DATE_RSS, $row['lastLogout']), 'lastLogoutUnixtime' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row['locName']);
+ }
+ } else {
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $median = self::calcMedian(self::calcMedian($row['medianTime']));
+ $data[] = array('hostname' => $row['clientHash'], 'time' => $row['timeSum'], 'medianTime' => $median, 'offTime' => $row['offlineSum'], 'lastStart' => $row['lastStart'],
+ 'lastLogout' => $row['lastLogout'], 'sessions' => $row['longSessions'], 'shortSessions' => $row['shortSessions'], 'locationName' => $row['locHash']);
+ }
}
return $data;
}
@@ -57,7 +77,7 @@ class GetData
$data = array();
$user = $anonymize ? 'userHash' : 'name';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $data[] = array('user' => $row['name'], 'sessions' => $row['count']);
+ $data[] = array('user' => $row[$user], 'sessions' => $row['count']);
}
return $data;
}
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index aa373f54..941bf12f 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -24,9 +24,7 @@ class Page_Statistics_Reporting extends Page
{
// timespan you want to see = Days selected * seconds per Day (86400)
// default = 14 days
- $date = new DateTime(date('Y-m-d 00:00:00'));
- $date->sub(new DateInterval('P'.(Request::get('cutoff', 14, 'int') - 1).'D'));
- GetData::$from = $date->getTimestamp();
+ GetData::$from = strtotime("- ".(Request::get('cutoff', 14, 'int') - 1)." days 00:00:00");
GetData::$to = time();
GetData::$lowerTimeBound = Request::get('lower', 0, 'int');
GetData::$upperTimeBound = Request::get('upper', 24, 'int');
@@ -37,7 +35,6 @@ class Page_Statistics_Reporting extends Page
$data['perUser'] = GetData::perUser();
$data['perVM'] = GetData::perVM();
-
Render::addTemplate('columnChooser');
Render::addTemplate('_page', $data);
}
--
cgit v1.2.3-55-g7522
From 9cd078d34d5f3172e8e770fce3c3ec7d6445a460 Mon Sep 17 00:00:00 2001
From: Udo Walter
Date: Mon, 16 Jan 2017 18:59:46 +0100
Subject: [statistics_reporting] added ui to disable the reporting
---
.../lang/de/template-tags.json | 4 +-
.../lang/en/template-tags.json | 4 +-
.../statistics_reporting/page.inc.php | 45 ++++++++++++++-------
modules-available/statistics_reporting/style.css | 4 ++
.../templates/columnChooser.html | 46 +++++++++++++++++++++-
5 files changed, 85 insertions(+), 18 deletions(-)
(limited to 'modules-available/statistics_reporting/page.inc.php')
diff --git a/modules-available/statistics_reporting/lang/de/template-tags.json b/modules-available/statistics_reporting/lang/de/template-tags.json
index 7dcec880..73c39e1e 100644
--- a/modules-available/statistics_reporting/lang/de/template-tags.json
+++ b/modules-available/statistics_reporting/lang/de/template-tags.json
@@ -28,5 +28,7 @@
"lang_last30": "Letzten 30 Tage",
"lang_last90": "Letzten 90 Tage",
"lang_apply": "Anwenden",
- "lang_notassigned": "NICHT ZUGEWIESEN"
+ "lang_save": "Speichern",
+ "lang_notassigned": "NICHT ZUGEWIESEN",
+ "lang_reportingDescription": "Helfen Sie uns bwLehrpool, durch das wöchentliche, automatische Verschicken eines anonymisierten Statistikberichts, zu verbessern."
}
\ No newline at end of file
diff --git a/modules-available/statistics_reporting/lang/en/template-tags.json b/modules-available/statistics_reporting/lang/en/template-tags.json
index 366a10de..90d59b38 100644
--- a/modules-available/statistics_reporting/lang/en/template-tags.json
+++ b/modules-available/statistics_reporting/lang/en/template-tags.json
@@ -28,5 +28,7 @@
"lang_last30": "Last 30 days",
"lang_last90": "Last 90 days",
"lang_apply": "Apply",
- "lang_notassigned": "NOT ASSIGNED"
+ "lang_save": "Save",
+ "lang_notassigned": "NOT ASSIGNED",
+ "lang_reportingDescription": "Help us improve bwLehrpool by automatically sending an anonymized statistics report once per week."
}
\ No newline at end of file
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index 941bf12f..1428848a 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -4,6 +4,8 @@
class Page_Statistics_Reporting extends Page
{
+ private $action = false;
+
/**
* Called before any page rendering happens - early hook to check parameters etc.
*/
@@ -15,6 +17,8 @@ class Page_Statistics_Reporting extends Page
Message::addError('main.no-permission');
Util::redirect('?do=Main'); // does not return
}
+
+ $this->action = Request::any('action', 'show', 'string');
}
/**
@@ -22,20 +26,31 @@ class Page_Statistics_Reporting extends Page
*/
protected function doRender()
{
- // timespan you want to see = Days selected * seconds per Day (86400)
- // default = 14 days
- GetData::$from = strtotime("- ".(Request::get('cutoff', 14, 'int') - 1)." days 00:00:00");
- GetData::$to = time();
- GetData::$lowerTimeBound = Request::get('lower', 0, 'int');
- GetData::$upperTimeBound = Request::get('upper', 24, 'int');
-
- $data = array_merge(GetData::total(), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array()));
- $data['perLocation'] = GetData::perLocation();
- $data['perClient'] = GetData::perClient();
- $data['perUser'] = GetData::perUser();
- $data['perVM'] = GetData::perVM();
-
- Render::addTemplate('columnChooser');
- Render::addTemplate('_page', $data);
+ if ($this->action === 'show') {
+ // timespan you want to see. default = last 7 days
+ GetData::$from = strtotime("- " . (Request::get('cutoff', 14, 'int') - 1) . " days 00:00:00");
+ GetData::$to = time();
+ GetData::$lowerTimeBound = Request::get('lower', 0, 'int');
+ GetData::$upperTimeBound = Request::get('upper', 24, 'int');
+
+ $data = array_merge(GetData::total(), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array()));
+ $data['perLocation'] = GetData::perLocation();
+ $data['perClient'] = GetData::perClient();
+ $data['perUser'] = GetData::perUser();
+ $data['perVM'] = GetData::perVM();
+
+ Render::addTemplate('columnChooser');
+ Render::addTemplate('_page', $data);
+ }
+ }
+
+ protected function doAjax()
+ {
+ $this->action = Request::any('action', false, 'string');
+ if ($this->action === 'setReporting') {
+ Property::set("reportingStatus", Request::get('reporting', "on", 'string'));
+ } elseif ($this->action === 'getReporting') {
+ echo Property::get("reportingStatus", "on");
+ }
}
}
diff --git a/modules-available/statistics_reporting/style.css b/modules-available/statistics_reporting/style.css
index d7fa7a2f..4f314b14 100644
--- a/modules-available/statistics_reporting/style.css
+++ b/modules-available/statistics_reporting/style.css
@@ -7,6 +7,10 @@
margin-bottom: 10px;
}
+.top-row #button-settings {
+ margin-right: 0;
+}
+
.buttonbar button {
margin-bottom: 4px;
}
diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html
index 09551fc1..47fef2a5 100644
--- a/modules-available/statistics_reporting/templates/columnChooser.html
+++ b/modules-available/statistics_reporting/templates/columnChooser.html
@@ -22,6 +22,7 @@