From c023c8a9c6b7b40ee485776b516f6bec76b69919 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 24 Dec 2019 14:33:11 +0100 Subject: [PATCH] Metrics: Added users_force_active --- src/Controllers/Metrics/Controller.php | 1 + src/Controllers/Metrics/Stats.php | 9 +++++++++ tests/Unit/Controllers/Metrics/StatsTest.php | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index 99b71335..a47b8159 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -93,6 +93,7 @@ class Controller extends BaseController ['labels' => ['state' => 'arrived', 'working' => 'no'], 'value' => $this->stats->arrivedUsers(false)], ['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value' => $this->stats->arrivedUsers(true)], ], + 'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()], 'licenses' => [ 'type' => 'gauge', 'help' => 'The total number of licenses', diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index b7aecffd..91ee4853 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -7,6 +7,7 @@ use Engelsystem\Database\Database; use Engelsystem\Models\EventConfig; use Engelsystem\Models\News; use Engelsystem\Models\Question; +use Engelsystem\Models\User\State; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression as QueryExpression; @@ -79,6 +80,14 @@ class Stats ->count(); } + /** + * @return int + */ + public function forceActiveUsers(): int + { + return State::whereForceActive(true)->count(); + } + /** * The number of currently working users * diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index 146c44a0..2c974db3 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -121,6 +121,17 @@ class StatsTest extends TestCase $this->assertEquals(6, $stats->arrivedUsers()); } + /** + * @covers \Engelsystem\Controllers\Metrics\Stats::forceActiveUsers + */ + public function testForceActiveUsers() + { + $this->addUsers(); + + $stats = new Stats($this->database); + $this->assertEquals(2, $stats->forceActiveUsers()); + } + /** * @covers \Engelsystem\Controllers\Metrics\Stats::sessions */ @@ -199,8 +210,8 @@ class StatsTest extends TestCase $this->addUser(['arrived' => 1]); $this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL']); $this->addUser(['arrived' => 1, 'got_voucher' => 9]); - $this->addUser(['arrived' => 1, 'got_voucher' => 3]); - $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true]); + $this->addUser(['arrived' => 1, 'got_voucher' => 3, 'force_active' => true]); + $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true, 'force_active' => true]); $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L']); }