diff options
author | Simon Rettberg | 2017-01-31 15:45:28 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-01-31 15:45:28 +0100 |
commit | 5c6b40b28ead1157260e4abc2e697a696f69520e (patch) | |
tree | eeb6030e4a391d5ef11f77ff7877c4640b76d2e7 /modules-available/statistics_reporting | |
parent | [statistics_reporting] fixed total showing wrong median and offline time (diff) | |
download | slx-admin-5c6b40b28ead1157260e4abc2e697a696f69520e.tar.gz slx-admin-5c6b40b28ead1157260e4abc2e697a696f69520e.tar.xz slx-admin-5c6b40b28ead1157260e4abc2e697a696f69520e.zip |
[statistics_reporting] Make getdata functions options flag based in preparation of data export
Diffstat (limited to 'modules-available/statistics_reporting')
4 files changed, 76 insertions, 55 deletions
diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php index 1a3c81dc..b19af966 100644 --- a/modules-available/statistics_reporting/inc/getdata.inc.php +++ b/modules-available/statistics_reporting/inc/getdata.inc.php @@ -1,5 +1,8 @@ <?php +define('GETDATA_ANONYMOUS', 1); +define('GETDATA_PRINTABLE', 2); + class GetData { public static $from; @@ -9,7 +12,8 @@ class GetData public static $salt; // total - public static function total($anonymize = false) { + public static function total($flags = 0) { + $printable = 0 !== ($flags & GETDATA_PRINTABLE); // 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); @@ -20,59 +24,75 @@ class GetData $row = $res->fetch(PDO::FETCH_ASSOC); $data = array_merge($data, array('totalOfftime' => $row['timeOff'])); - if (!$anonymize) { - $data["time"] = self::formatSeconds($data["time"]); - $data["medianTime"] = self::formatSeconds($data["medianTime"]); - $data["totalOfftime"] = self::formatSeconds($data["totalOfftime"]); + if ($printable) { + $data["time_s"] = self::formatSeconds($data["time"]); + $data["medianTime_s"] = self::formatSeconds($data["medianTime"]); + $data["totalOfftime_s"] = self::formatSeconds($data["totalOfftime"]); } return $data; } // per location - public static function perLocation($anonymize = false) { + public static function perLocation($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); + $printable = 0 !== ($flags & GETDATA_PRINTABLE); $res = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); - 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']); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $median = self::calcMedian(self::calcMedian($row['medianTime'])); + $entry = array( + 'location' => ($anonymize ? $row['locHash'] : $row['locName']), + 'time' => $row['timeSum'], + 'medianTime' => $median, + 'offTime' => $row['offlineSum'], + 'sessions' => $row['longSessions'], + 'shortSessions' => $row['shortSessions'] + ); + if ($printable) { + $entry['time_s'] = self::formatSeconds($row['timeSum']); + $entry['medianTime_s'] = self::formatSeconds($median); + $entry['offTime_s'] = self::formatSeconds($row['offlineSum']); } + $data[] = $entry; } return $data; } // per client - public static function perClient($anonymize = false) { + public static function perClient($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); + $printable = 0 !== ($flags & GETDATA_PRINTABLE); $res = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); - 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']); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $median = self::calcMedian(self::calcMedian($row['medianTime'])); + $entry = array( + 'hostname' => ($anonymize ? $row['clientHash'] : $row['clientName']), + 'time' => $row['timeSum'], + 'medianTime' => $median, + 'offTime' => $row['offlineSum'], + 'lastStart' => $row['lastStart'], + 'lastLogout' => $row['lastLogout'], + 'sessions' => $row['longSessions'], + 'shortSessions' => $row['shortSessions'], + 'location' => ($anonymize ? $row['locHash'] : $row['locName']), + ); + if ($printable) { + $entry['time_s'] = self::formatSeconds($row['timeSum']); + $entry['medianTime_s'] = self::formatSeconds($median); + $entry['offTime_s'] = self::formatSeconds($row['offlineSum']); + $entry['lastStart_s'] = date(DATE_RSS, $row['lastStart']); + $entry['lastLogout_s'] = date(DATE_RSS, $row['lastLogout']); } + $data[] = $entry; } return $data; } // per user - public static function perUser($anonymize = false) { + public static function perUser($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); $user = $anonymize ? 'userHash' : 'name'; @@ -84,7 +104,8 @@ class GetData // per vm - public static function perVM($anonymize = false) { + public static function perVM($flags = 0) { + $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); $vm = $anonymize ? 'vmHash' : 'name'; diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 0bf4e7e2..e00e6758 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -71,11 +71,11 @@ class RemoteReport GetData::$from = $from; GetData::$to = $to; GetData::$salt = bin2hex(Util::randomBytes(20)); - $data = GetData::total(true); - $data['perLocation'] = GetData::perLocation(true); - $data['perClient'] = GetData::perClient(true); - $data['perUser'] = GetData::perUser(true); - $data['perVM'] = GetData::perVM(true); + $data = GetData::total(GETDATA_ANONYMOUS); + $data['perLocation'] = GetData::perLocation(GETDATA_ANONYMOUS); + $data['perClient'] = GetData::perClient(GETDATA_ANONYMOUS); + $data['perUser'] = GetData::perUser(GETDATA_ANONYMOUS); + $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); $data['tsFrom'] = $from; $data['tsTo'] = $to; return $data; diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php index 0309be68..052d813d 100644 --- a/modules-available/statistics_reporting/page.inc.php +++ b/modules-available/statistics_reporting/page.inc.php @@ -33,11 +33,11 @@ class Page_Statistics_Reporting extends Page 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(); + $data = GetData::total(GETDATA_PRINTABLE); + $data['perLocation'] = GetData::perLocation(GETDATA_PRINTABLE); + $data['perClient'] = GetData::perClient(GETDATA_PRINTABLE); + $data['perUser'] = GetData::perUser(GETDATA_PRINTABLE); + $data['perVM'] = GetData::perVM(GETDATA_PRINTABLE); Render::addTemplate('columnChooser'); Render::addTemplate('_page', $data); diff --git a/modules-available/statistics_reporting/templates/_page.html b/modules-available/statistics_reporting/templates/_page.html index 37c3cf90..39726d51 100644 --- a/modules-available/statistics_reporting/templates/_page.html +++ b/modules-available/statistics_reporting/templates/_page.html @@ -15,11 +15,11 @@ <tbody> <tr> <th class="text-left">{{lang_total}}</th> - <td class="text-left column-totaltime">{{time}}</td> - <td class="text-left column-mediantime">{{medianTime}}</td> + <td class="text-left column-totaltime">{{time_s}}</td> + <td class="text-left column-mediantime">{{medianTime_s}}</td> <td class="text-left column-longsessions">{{sessions}}</td> <td class="text-left column-shortsessions">{{shortSessions}}</td> - <td class="text-left column-timeoffline">{{totalOfftime}}</td> + <td class="text-left column-timeoffline">{{totalOfftime_s}}</td> </tr> </tbody> </table> @@ -42,11 +42,11 @@ {{#perLocation}} <tr> <td class="locationName text-left">{{location}}</td> - <td data-sort-value="{{timeInSeconds}}" class="text-left column-totaltime">{{time}}</td> - <td data-sort-value="{{medianTimeInSeconds}}" class="text-left column-mediantime">{{medianTime}}</td> + <td data-sort-value="{{time}}" class="text-left column-totaltime">{{time_s}}</td> + <td data-sort-value="{{medianTime}}" class="text-left column-mediantime">{{medianTime_s}}</td> <td class="text-left column-longsessions">{{sessions}}</td> <td class="text-left column-shortsessions">{{shortSessions}}</td> - <td data-sort-value="{{offlineTimeInSeconds}}" class="text-left column-timeoffline">{{offTime}}</td> + <td data-sort-value="{{offTime}}" class="text-left column-timeoffline">{{offTime_s}}</td> </tr> {{/perLocation}} </tbody> @@ -73,14 +73,14 @@ {{#perClient}} <tr> <td class="text-left">{{hostname}}</td> - <td class="text-left column-location"><a class="locationLink" href="#">{{locationName}}</a></td> - <td data-sort-value="{{timeInSeconds}}" class="text-left column-totaltime">{{time}}</td> - <td data-sort-value="{{medianTimeInSeconds}}" class="text-left column-mediantime">{{medianTime}}</td> + <td class="text-left column-location"><a class="locationLink" href="#">{{location}}</a></td> + <td data-sort-value="{{time}}" class="text-left column-totaltime">{{time_s}}</td> + <td data-sort-value="{{medianTime}}" class="text-left column-mediantime">{{medianTime_s}}</td> <td class="text-left column-longsessions">{{sessions}}</td> <td class="text-left column-shortsessions">{{shortSessions}}</td> - <td data-sort-value="{{offlineTimeInSeconds}}" class="text-left column-timeoffline">{{offTime}}</td> - <td data-sort-value="{{lastLogoutUnixtime}}" class="text-left column-lastlogout">{{lastLogout}}</td> - <td data-sort-value="{{lastStartUnixtime}}" class="text-left column-laststart">{{lastStart}}</td> + <td data-sort-value="{{offTime}}" class="text-left column-timeoffline">{{offTime_s}}</td> + <td data-sort-value="{{lastLogout}}" class="text-left column-lastlogout">{{lastLogout_s}}</td> + <td data-sort-value="{{lastStart}}" class="text-left column-laststart">{{lastStart_s}}</td> </tr> {{/perClient}} </tbody> |