summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-12-21 20:09:15 +0100
committermsquare <msquare@notrademark.de>2018-12-22 11:31:33 +0100
commitb3f059ad04fc0f54282aea98c5c2af8d7e46867a (patch)
tree9a69e1bfb482fc5abb35d7c6f42355b290c21024 /src
parent482721eb1ba0ee21a3f75a8465fcf53ae08a1603 (diff)
metrics: Added vouchers and tshirts
Diffstat (limited to 'src')
-rw-r--r--src/Controllers/Metrics/Controller.php18
-rw-r--r--src/Controllers/Metrics/Stats.php35
2 files changed, 50 insertions, 3 deletions
diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php
index 0fd26396..86c21562 100644
--- a/src/Controllers/Metrics/Controller.php
+++ b/src/Controllers/Metrics/Controller.php
@@ -55,6 +55,17 @@ class Controller extends BaseController
$now = microtime(true);
$this->checkAuth();
+ $tshirtSizes = [];
+ $userSizes = $this->stats->tshirtSizes();
+
+ foreach ($this->config->get('tshirt_sizes') as $name => $description) {
+ $size = $userSizes->where('shirt_size', '=', $name)->sum('count');
+ $tshirtSizes[] = [
+ 'labels' => ['size' => $name],
+ $size,
+ ];
+ }
+
$data = [
$this->config->get('app_name') . ' stats',
'users' => [
@@ -84,6 +95,9 @@ class Controller extends BaseController
['labels' => ['state' => 'freeloaded'], 'value' => $this->stats->workSeconds(null, true)],
],
'worklog_seconds' => ['type' => 'gauge', $this->stats->worklogSeconds()],
+ 'vouchers' => ['type' => 'counter', $this->stats->vouchers()],
+ 'tshirts_issued' => ['type' => 'counter', 'help' => 'Issued T-Shirts', $this->stats->tshirts()],
+ 'tshirt_sizes' => ['type' => 'gauge', 'help' => 'The sizes users have configured'] + $tshirtSizes,
'shifts' => ['type' => 'gauge', $this->stats->shifts()],
'announcements' => [
'type' => 'gauge',
@@ -92,8 +106,8 @@ class Controller extends BaseController
],
'questions' => [
'type' => 'gauge',
- ['labels' => ['answered' => true], 'value' => $this->stats->questions(true)],
- ['labels' => ['answered' => false], 'value' => $this->stats->questions(false)],
+ ['labels' => ['state' => 'answered'], 'value' => $this->stats->questions(true)],
+ ['labels' => ['state' => 'pending'], 'value' => $this->stats->questions(false)],
],
'messages' => ['type' => 'gauge', $this->stats->messages()],
'password_resets' => ['type' => 'gauge', $this->stats->passwordResets()],
diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php
index 838411d1..11643e46 100644
--- a/src/Controllers/Metrics/Stats.php
+++ b/src/Controllers/Metrics/Stats.php
@@ -97,6 +97,40 @@ class Stats
}
/**
+ * @return int
+ */
+ public function vouchers(): int
+ {
+ return $this
+ ->getQuery('users_state')
+ ->sum('got_voucher');
+ }
+
+ /**
+ * @return int
+ */
+ public function tshirts(): int
+ {
+ return $this
+ ->getQuery('users_state')
+ ->where('got_shirt', '=', true)
+ ->count();
+ }
+
+ /**
+ * @return \Illuminate\Support\Collection
+ */
+ public function tshirtSizes()
+ {
+ return $this
+ ->getQuery('users_personal_data')
+ ->select(['shirt_size', $this->raw('COUNT(shirt_size) AS count')])
+ ->whereNotNull('shirt_size')
+ ->groupBy('shirt_size')
+ ->get();
+ }
+
+ /**
* @param string $vehicle
* @return int
* @codeCoverageIgnore
@@ -267,7 +301,6 @@ class Stats
/**
* @param mixed $value
* @return QueryExpression
- * @codeCoverageIgnore
*/
protected function raw($value)
{