summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Controllers/Metrics/Controller.php1
-rw-r--r--src/Controllers/Metrics/Stats.php9
-rw-r--r--tests/Unit/Controllers/Metrics/StatsTest.php15
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;
@@ -80,6 +81,14 @@ class Stats
}
/**
+ * @return int
+ */
+ public function forceActiveUsers(): int
+ {
+ return State::whereForceActive(true)->count();
+ }
+
+ /**
* The number of currently working users
*
* @param null $freeloaded
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
@@ -122,6 +122,17 @@ class StatsTest extends TestCase
}
/**
+ * @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
*/
public function testSessions()
@@ -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']);
}