Metrics: Added users_force_active

main
Igor Scheller 5 years ago
parent ea034ecec6
commit c023c8a9c6

@ -93,6 +93,7 @@ class Controller extends BaseController
['labels' => ['state' => 'arrived', 'working' => 'no'], 'value' => $this->stats->arrivedUsers(false)], ['labels' => ['state' => 'arrived', 'working' => 'no'], 'value' => $this->stats->arrivedUsers(false)],
['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value' => $this->stats->arrivedUsers(true)], ['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value' => $this->stats->arrivedUsers(true)],
], ],
'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()],
'licenses' => [ 'licenses' => [
'type' => 'gauge', 'type' => 'gauge',
'help' => 'The total number of licenses', 'help' => 'The total number of licenses',

@ -7,6 +7,7 @@ use Engelsystem\Database\Database;
use Engelsystem\Models\EventConfig; use Engelsystem\Models\EventConfig;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Question; use Engelsystem\Models\Question;
use Engelsystem\Models\User\State;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Expression as QueryExpression; use Illuminate\Database\Query\Expression as QueryExpression;
@ -79,6 +80,14 @@ class Stats
->count(); ->count();
} }
/**
* @return int
*/
public function forceActiveUsers(): int
{
return State::whereForceActive(true)->count();
}
/** /**
* The number of currently working users * The number of currently working users
* *

@ -121,6 +121,17 @@ class StatsTest extends TestCase
$this->assertEquals(6, $stats->arrivedUsers()); $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 * @covers \Engelsystem\Controllers\Metrics\Stats::sessions
*/ */
@ -199,8 +210,8 @@ class StatsTest extends TestCase
$this->addUser(['arrived' => 1]); $this->addUser(['arrived' => 1]);
$this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL']); $this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL']);
$this->addUser(['arrived' => 1, 'got_voucher' => 9]); $this->addUser(['arrived' => 1, 'got_voucher' => 9]);
$this->addUser(['arrived' => 1, 'got_voucher' => 3]); $this->addUser(['arrived' => 1, 'got_voucher' => 3, 'force_active' => true]);
$this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => 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']); $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L']);
} }

Loading…
Cancel
Save