summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics_reporting
diff options
context:
space:
mode:
authorSimon Rettberg2020-10-22 15:14:11 +0200
committerSimon Rettberg2020-10-22 15:14:11 +0200
commit46220dbd2a781a6df0b7e96d9dc38a0268caea11 (patch)
tree924544971ceb7fd99121bbb218734de7239e93d9 /modules-available/statistics_reporting
parent[locationinfo] Relative paths for assets in rewrite mode (diff)
downloadslx-admin-46220dbd2a781a6df0b7e96d9dc38a0268caea11.tar.gz
slx-admin-46220dbd2a781a6df0b7e96d9dc38a0268caea11.tar.xz
slx-admin-46220dbd2a781a6df0b7e96d9dc38a0268caea11.zip
[statistics_reporting] Add exam statistics
Diffstat (limited to 'modules-available/statistics_reporting')
-rw-r--r--modules-available/statistics_reporting/inc/queries.inc.php35
-rw-r--r--modules-available/statistics_reporting/inc/remotereport.inc.php3
2 files changed, 33 insertions, 5 deletions
diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php
index c77f0ed8..f389cfb1 100644
--- a/modules-available/statistics_reporting/inc/queries.inc.php
+++ b/modules-available/statistics_reporting/inc/queries.inc.php
@@ -345,12 +345,12 @@ class Queries
return $res;
}
- public static function getDozmodStats($from, $to)
+ public static function getDozmodStats(int $from, int $to)
{
- if (!Module::isAvailable('dozmod'))
- return array('disabled' => true);
+ if (Module::get('dozmod') === false)
+ return ['disabled' => true];
- $return = array();
+ $return = [];
$return['vms'] = Database::queryFirst("SELECT Count(*) AS `total`, Sum(If(createtime >= $from, 1, 0)) AS `new`,
Sum(If(updatetime >= $from, 1, 0)) AS `updated`, Sum(If(latestversionid IS NOT NULL, 1, 0)) AS `valid`
FROM sat.imagebase
@@ -366,6 +366,33 @@ class Queries
return $return;
}
+ public static function getExamStats(int $from, int $to)
+ {
+ if (Module::get('exams') === false)
+ return ['disabled' => true];
+ $return = [];
+ $eres = Database::simpleQuery("SELECT starttime, endtime, GROUP_CONCAT(exl.locationid) AS `locs` FROM exams
+ LEFT JOIN exams_x_location exl USING (examid)
+ WHERE starttime < $to AND endtime > $from");
+ while ($row = $eres->fetch(PDO::FETCH_ASSOC)) {
+ // Get all boot events
+ $data = ['from' => $row['starttime'], 'to' => $row['endtime']];
+ if (empty($row['locs'])) {
+ $exam = Database::queryFirst("SELECT Count(*) AS `event`, Avg(s.data) AS length FROM statistic s
+ WHERE typeid = '~session-length'
+ AND dateline BETWEEN :from AND :to", $data);
+ } else {
+ $data['locs'] = explode(',', $row['locs']);
+ $exam = Database::queryFirst("SELECT Count(*) AS `event`, Avg(s.data) AS length FROM statistic s
+ INNER JOIN machine m USING (machineuuid)
+ WHERE typeid = '~session-length' AND m.locationid IN (:locs)
+ AND dateline BETWEEN :from AND :to", $data);
+ }
+ $return[] = $exam;
+ }
+ return $return;
+ }
+
public static function getAggregatedMachineStats($from)
{
$return = array();
diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php
index f8f54a86..2de49d04 100644
--- a/modules-available/statistics_reporting/inc/remotereport.inc.php
+++ b/modules-available/statistics_reporting/inc/remotereport.inc.php
@@ -68,7 +68,7 @@ class RemoteReport
* @param int[] $days list of days to generate aggregated stats for
* @return array wrapped up statistics, ready for reporting
*/
- public static function generateReport($to, $days = false) {
+ public static function generateReport(int $to, $days = false) {
if ($days === false) {
$days = [7, 30, 90];
}
@@ -89,6 +89,7 @@ class RemoteReport
$data['tsTo'] = $to;
$data['dozmod'] = Queries::getDozmodStats($from, $to);
$data['machines'] = Queries::getAggregatedMachineStats($from);
+ $data['exams'] = Queries::getExamStats($from, $to);
$result['days' . $day] = $data;
}
$result['server'] = self::getLocalHardware();