diff options
author | Simon Rettberg | 2022-12-02 15:21:26 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-12-02 15:24:08 +0100 |
commit | 200d92c8491d5060af5dd839aa82d1e51b058dd6 (patch) | |
tree | afd9274f2de28b4c387f08550712629798883b26 /modules-available/statistics/hooks | |
parent | [inc/ArrayUtil] Fix sort flag handling (diff) | |
download | slx-admin-200d92c8491d5060af5dd839aa82d1e51b058dd6.tar.gz slx-admin-200d92c8491d5060af5dd839aa82d1e51b058dd6.tar.xz slx-admin-200d92c8491d5060af5dd839aa82d1e51b058dd6.zip |
[statistics] Per-location usage stats; include active lecture count
Diffstat (limited to 'modules-available/statistics/hooks')
-rw-r--r-- | modules-available/statistics/hooks/cron.inc.php | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index 7152b1da..d444c672 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -9,12 +9,42 @@ function logstats() $join = 'LEFT JOIN runmode r USING (machineuuid)'; $where = 'AND (r.isclient IS NULL OR r.isclient <> 0)'; } - $known = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE m.lastseen > $cutoff $where"); - $on = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE m.state IN ('IDLE', 'OCCUPIED') $where"); - $used = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE m.state = 'OCCUPIED' $where"); + // Get total/online/in-use + $known = Database::queryKeyValueList("SELECT locationid, Count(*) AS val FROM machine m + $join WHERE m.lastseen > $cutoff $where + GROUP BY locationid"); + $on = Database::queryKeyValueList("SELECT locationid, Count(*) AS val FROM machine m + $join WHERE m.state IN ('IDLE', 'OCCUPIED') $where + GROUP BY locationid"); + $used = Database::queryKeyValueList("SELECT locationid, Count(*) AS val FROM machine m + $join WHERE m.state = 'OCCUPIED' $where + GROUP BY locationid"); + // Get calendar data if available + if (Module::isAvailable('locationinfo')) { + // Refresh all calendars around 07:00 + $calendars = LocationInfo::getAllCalendars(date('G') != 7 || date('i') >= 10); + } + // Mash together + $data = ['usage' => []]; + foreach ($known as $lid => $val) { + $entry = ['t' => $val]; + if (isset($on[$lid])) { + $entry['o'] = $on[$lid]; + } + if (isset($used[$lid])) { + $entry['u'] = $used[$lid]; + } + if (isset($calendars[$lid])) { + $title = LocationInfo::extractCurrentEvent($calendars[$lid]); + if (!empty($title)) { + $entry['event'] = $title; + } + } + $data['usage'][$lid] = $entry; + } Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array( 'now' => $NOW, - 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'], + 'vals' => json_encode($data), )); } |