summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/pages
diff options
context:
space:
mode:
authorSimon Rettberg2022-12-08 16:21:45 +0100
committerSimon Rettberg2022-12-08 16:21:45 +0100
commitf3830941e4a446b96ceaa6744c70bbf7be614bda (patch)
treede2a964cf4e8c98fa6161748dcb52cfc991559f1 /modules-available/statistics/pages
parent[remoteaccess] Add list of active locations to overview page (diff)
downloadslx-admin-f3830941e4a446b96ceaa6744c70bbf7be614bda.tar.gz
slx-admin-f3830941e4a446b96ceaa6744c70bbf7be614bda.tar.xz
slx-admin-f3830941e4a446b96ceaa6744c70bbf7be614bda.zip
[statistics] Only show graph if no non-location filters are set
Closes #3694
Diffstat (limited to 'modules-available/statistics/pages')
-rw-r--r--modules-available/statistics/pages/summary.inc.php94
1 files changed, 51 insertions, 43 deletions
diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php
index 6781ff05..71faff47 100644
--- a/modules-available/statistics/pages/summary.inc.php
+++ b/modules-available/statistics/pages/summary.inc.php
@@ -65,52 +65,60 @@ class SubPage
];
// Graph
// Get locations
- $locFilter = $filterSet->hasFilter('LocationStatisticsFilter');
- if ($locFilter === null || ($locFilter->op === '~' && (int)$locFilter->argument === 0)) {
- $locations = null;
- $op = null;
- } elseif ($locFilter->op === '~') {
- $locations = array_keys(Location::getRecursiveFlat($locFilter->argument));
- $op = $locFilter->op;
- } else {
- $locations = [$locFilter->argument];
- $op = $locFilter->op;
- }
- //error_log($op . ' ' . print_r($locations, true));
- $cutoff = time() - 2 * 86400;
- $res = Database::simpleQuery("SELECT dateline, data FROM statistic
- WHERE typeid = '~stats' AND dateline > $cutoff ORDER BY dateline DESC");
- $labels = [];
- $points1 = [];
- $points2 = [];
- $lectures = [];
- // Get max from 6 consecutive values, which should be 6*5 = 30m
- $sum = 0;
- foreach ($res as $row) {
- if ($row['data'][0] === '{') {
- $x = json_decode($row['data'], true);
- if (!is_array($x) || !isset($x['usage']))
- continue;
- $x = self::mangleStatsJson($x, $locations, $op);
- } else if ($locations === null) {
- $x = explode('#', $row['data']);
- if (count($x) < 3)
- continue;
- $x[] = 0;
+ if ($filterSet->suitableForUsageGraph()) {
+ $locFilter = $filterSet->hasFilter('LocationStatisticsFilter');
+ if ($locFilter === null
+ || ($locFilter->op === '~' && ($locFilter->argument == 0
+ || (is_array($locFilter->argument) && in_array(0, $locFilter->argument))))) {
+ $locations = null;
+ $op = null;
+ } elseif ($locFilter->op === '~') {
+ $locations = array_keys(Location::getRecursiveFlat($locFilter->argument));
+ $op = $locFilter->op;
} else {
- continue;
+ if (is_array($locFilter->argument)) {
+ $locations = $locFilter->argument;
+ } else {
+ $locations = [$locFilter->argument];
+ }
+ $op = $locFilter->op;
}
- if ($sum % 4 === 0) {
- $labels[] = date('H:i', $row['dateline']);
- } else {
- $x[1] = max($x[1], array_pop($points1));
- $x[2] = max($x[2], array_pop($points2));
- $x[3] += array_pop($lectures);
+ //error_log($op . ' ' . print_r($locations, true));
+ $cutoff = time() - 2 * 86400;
+ $res = Database::simpleQuery("SELECT dateline, data FROM statistic
+ WHERE typeid = '~stats' AND dateline > $cutoff ORDER BY dateline DESC");
+ $labels = [];
+ $points1 = [];
+ $points2 = [];
+ $lectures = [];
+ // Get max from 3 consecutive values, which should be 3*5 = 15m
+ $sum = 0;
+ foreach ($res as $row) {
+ if ($row['data'][0] === '{') {
+ $x = json_decode($row['data'], true);
+ if (!is_array($x) || !isset($x['usage']))
+ continue;
+ $x = self::mangleStatsJson($x, $locations, $op);
+ } else if ($locations === null) {
+ $x = explode('#', $row['data']);
+ if (count($x) < 3)
+ continue;
+ $x[] = 0;
+ } else {
+ continue;
+ }
+ if ($sum % 4 === 0) {
+ $labels[] = date('H:i', $row['dateline']);
+ } else {
+ $x[1] = max($x[1], array_pop($points1));
+ $x[2] = max($x[2], array_pop($points2));
+ $x[3] += array_pop($lectures);
+ }
+ $points1[] = $x[1];
+ $points2[] = $x[2];
+ $lectures[] = $x[3];
+ ++$sum;
}
- $points1[] = $x[1];
- $points2[] = $x[2];
- $lectures[] = $x[3];
- ++$sum;
}
if (!empty($points1) && max(...$points1) > 0) {
$labels = array_reverse($labels);