From f3830941e4a446b96ceaa6744c70bbf7be614bda Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Dec 2022 16:21:45 +0100 Subject: [statistics] Only show graph if no non-location filters are set Closes #3694 --- modules-available/statistics/pages/summary.inc.php | 94 ++++++++++++---------- 1 file changed, 51 insertions(+), 43 deletions(-) (limited to 'modules-available/statistics/pages') 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); -- cgit v1.2.3-55-g7522