add user info to metrics

This commit is contained in:
Xu 2023-12-28 17:56:56 +01:00 committed by Igor Scheller
parent d6412605f2
commit 2883a66f49
3 changed files with 21 additions and 1 deletions

View File

@ -77,6 +77,7 @@ class Controller extends BaseController
['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value'
=> $this->stats->usersState(true)],
],
'users_info' => ['type' => 'gauge', $this->stats->usersInfo()],
'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()],
'users_pronouns' => ['type' => 'gauge', $this->stats->usersPronouns()],
'licenses' => [

View File

@ -69,6 +69,14 @@ class Stats
return $query->count('users_state.user_id');
}
public function usersInfo(): int
{
return State::query()
->whereNotNull('user_info')
->whereNot('user_info', '')
->count();
}
public function forceActiveUsers(): int
{
return State::whereForceActive(true)->count();

View File

@ -287,6 +287,17 @@ class StatsTest extends TestCase
$this->assertEquals(1, $stats->usersState(false, false));
}
/**
* @covers \Engelsystem\Controllers\Metrics\Stats::usersInfo
*/
public function testUsersInfo(): void
{
$this->addUsers();
$stats = new Stats($this->database);
$this->assertEquals(1, $stats->usersInfo());
}
/**
* @covers \Engelsystem\Controllers\Metrics\Stats::forceActiveUsers
*/
@ -474,7 +485,7 @@ class StatsTest extends TestCase
$this->addUser(['arrived' => 1], ['pronoun' => 'unicorn'], ['language' => 'lo_RM', 'email_shiftinfo' => true]);
$this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL'], ['language' => 'lo_RM']);
$this->addUser(
['arrived' => 1, 'got_voucher' => 9, 'force_active' => true],
['arrived' => 1, 'got_voucher' => 9, 'force_active' => true, 'user_info' => 'Info'],
[],
['theme' => 1],
['drive_car' => true, 'drive_12t' => true]