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']); }