From 5c6b40b28ead1157260e4abc2e697a696f69520e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 31 Jan 2017 15:45:28 +0100 Subject: [statistics_reporting] Make getdata functions options flag based in preparation of data export --- .../statistics_reporting/inc/getdata.inc.php | 87 ++++++++++++++-------- .../statistics_reporting/inc/remotereport.inc.php | 10 +-- .../statistics_reporting/page.inc.php | 10 +-- .../statistics_reporting/templates/_page.html | 24 +++--- 4 files changed, 76 insertions(+), 55 deletions(-) (limited to 'modules-available/statistics_reporting') 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 @@ 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 @@ {{lang_total}} - {{time}} - {{medianTime}} + {{time_s}} + {{medianTime_s}} {{sessions}} {{shortSessions}} - {{totalOfftime}} + {{totalOfftime_s}} @@ -42,11 +42,11 @@ {{#perLocation}} {{location}} - {{time}} - {{medianTime}} + {{time_s}} + {{medianTime_s}} {{sessions}} {{shortSessions}} - {{offTime}} + {{offTime_s}} {{/perLocation}} @@ -73,14 +73,14 @@ {{#perClient}} {{hostname}} - {{locationName}} - {{time}} - {{medianTime}} + {{location}} + {{time_s}} + {{medianTime_s}} {{sessions}} {{shortSessions}} - {{offTime}} - {{lastLogout}} - {{lastStart}} + {{offTime_s}} + {{lastLogout_s}} + {{lastStart_s}} {{/perClient}} -- cgit v1.2.3-55-g7522