summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules-available/statistics/inc/statisticsfilter.inc.php5
-rw-r--r--modules-available/statistics/inc/statisticsfilterset.inc.php27
-rw-r--r--modules-available/statistics/pages/summary.inc.php94
3 files changed, 83 insertions, 43 deletions
diff --git a/modules-available/statistics/inc/statisticsfilter.inc.php b/modules-available/statistics/inc/statisticsfilter.inc.php
index f90c15c7..0b364715 100644
--- a/modules-available/statistics/inc/statisticsfilter.inc.php
+++ b/modules-available/statistics/inc/statisticsfilter.inc.php
@@ -808,6 +808,11 @@ class DatabaseFilter
return get_class($this->inst) === $what;
}
+ public function getClass(): string
+ {
+ return get_class($this->inst);
+ }
+
}
StatisticsFilter::initConstants();
diff --git a/modules-available/statistics/inc/statisticsfilterset.inc.php b/modules-available/statistics/inc/statisticsfilterset.inc.php
index 90a39f7d..c1401c11 100644
--- a/modules-available/statistics/inc/statisticsfilterset.inc.php
+++ b/modules-available/statistics/inc/statisticsfilterset.inc.php
@@ -107,4 +107,31 @@ class StatisticsFilterSet
return false;
}
+ public function suitableForUsageGraph(): bool
+ {
+ foreach ($this->filters as $filter) {
+ switch ($filter->getClass()) {
+ case 'LocationStatisticsFilter':
+ case 'IsClientStatisticsFilter':
+ break;
+ case 'DateStatisticsFilter':
+ if ($filter->op !== '>' && $filter->op !== '>=')
+ return false;
+ if (strtotime($filter->argument) + 3*86400 > time())
+ return false;
+ break;
+ case 'RuntimeStatisticsFilter':
+ if ($filter->op !== '>' && $filter->op !== '>=')
+ return false;
+ if ($filter->argument < 3 * 24)
+ return false;
+ break;
+ default:
+ error_log('NOPE: ' . $filter->getClass());
+ return false;
+ }
+ }
+ return true;
+ }
+
}
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);