diff options
author | Simon Rettberg | 2020-01-17 17:56:46 +0100 |
---|---|---|
committer | Simon Rettberg | 2020-01-17 17:56:46 +0100 |
commit | 701d9b01775a6befa0aafedd1e2d56237ad3ed58 (patch) | |
tree | 734fdfd2bd996fa423fa5838d9d835bbbce736e3 /modules-available/statistics_reporting/inc | |
parent | [statistics_reporting] Remove dead code (diff) | |
download | slx-admin-701d9b01775a6befa0aafedd1e2d56237ad3ed58.tar.gz slx-admin-701d9b01775a6befa0aafedd1e2d56237ad3ed58.tar.xz slx-admin-701d9b01775a6befa0aafedd1e2d56237ad3ed58.zip |
[statistics_reporting] Don't consider machines not recently used
... machine must have been running in the previous 30 days, relative to
the "from" timestamp of selected interval.
Diffstat (limited to 'modules-available/statistics_reporting/inc')
-rw-r--r-- | modules-available/statistics_reporting/inc/queries.inc.php | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index 58e9e63b..39e43765 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -13,11 +13,12 @@ class Queries } } - public static function getClientStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) + public static function getClientStatistics(int $from, int $to, $lowerTimeBound = 0, $upperTimeBound = 24) { + $fromCutoff = $from - 86400 * 30; $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, m.locationid, m.firstseen -- , m.lastboot, m.logintime, m.state - FROM machine m WHERE firstseen <= $to"); // " WHERE lastseen >= :from", compact('from')); + FROM machine m WHERE firstseen <= $to AND lastseen > $fromCutoff"); // " WHERE lastseen >= :from", compact('from')); $machines = self::getStats3($res, $from, $to, $lowerTimeBound, $upperTimeBound); foreach ($machines as &$machine) { $machine['medianSessionLength'] = self::calcMedian($machine['sessions']); @@ -27,11 +28,12 @@ class Queries return $machines; } - public static function getLocationStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) + public static function getLocationStatistics(int $from, int $to, $lowerTimeBound = 0, $upperTimeBound = 24) { + $fromCutoff = $from - 86400 * 30; $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, m.locationid, m.firstseen -- , m.lastboot, m.logintime, m.state - FROM machine m WHERE firstseen <= $to"); // " WHERE lastseen >= :from", compact('from')); + FROM machine m WHERE firstseen <= $to AND lastseen > $fromCutoff"); // " WHERE lastseen >= :from", compact('from')); $machines = self::getStats3($res, $from, $to, $lowerTimeBound, $upperTimeBound); $locations = []; $keys = ['locationid', 'totalTime', 'totalOffTime', 'totalSessionTime', 'totalStandbyTime', 'totalIdleTime', 'totalIdleTime', 'longSessions', 'shortSessions', 'sessions']; @@ -58,11 +60,12 @@ class Queries return $locations; } - public static function getOverallStatistics($from, $to, $lowerTimeBound = 0, $upperTimeBound = 24) + public static function getOverallStatistics(int $from, int $to, $lowerTimeBound = 0, $upperTimeBound = 24) { + $fromCutoff = $from - 86400 * 30; $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, m.locationid, m.firstseen -- , m.lastboot, m.logintime, m.state - FROM machine m WHERE firstseen <= $to"); // " WHERE lastseen >= :from", compact('from')); + FROM machine m WHERE firstseen <= $to AND lastseen > $fromCutoff"); // " WHERE lastseen >= :from", compact('from')); $machines = self::getStats3($res, $from, $to, $lowerTimeBound, $upperTimeBound); $total = false; $keys = ['totalTime', 'totalOffTime', 'totalSessionTime', 'totalStandbyTime', 'totalIdleTime', 'totalIdleTime', 'longSessions', 'shortSessions', 'sessions']; |