Metrics: Added not arrived users
This commit is contained in:
parent
1d3509ba3c
commit
57373c846a
|
@ -68,9 +68,14 @@ class Controller extends BaseController
|
|||
],
|
||||
'users' => [
|
||||
'type' => 'gauge',
|
||||
['labels' => ['state' => 'incoming'], 'value' => $this->stats->newUsers()],
|
||||
['labels' => ['state' => 'arrived', 'working' => 'no'], 'value' => $this->stats->arrivedUsers(false)],
|
||||
['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value' => $this->stats->arrivedUsers(true)],
|
||||
['labels' => ['state' => 'incoming', 'working' => 'no'], 'value'
|
||||
=> $this->stats->usersState(false, false)],
|
||||
['labels' => ['state' => 'incoming', 'working' => 'yes'], 'value'
|
||||
=> $this->stats->usersState(true, false)],
|
||||
['labels' => ['state' => 'arrived', 'working' => 'no'], 'value'
|
||||
=> $this->stats->usersState(false)],
|
||||
['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value'
|
||||
=> $this->stats->usersState(true)],
|
||||
],
|
||||
'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()],
|
||||
'users_pronouns' => ['type' => 'gauge', $this->stats->usersPronouns()],
|
||||
|
@ -194,8 +199,8 @@ class Controller extends BaseController
|
|||
$this->checkAuth(true);
|
||||
|
||||
$data = [
|
||||
'user_count' => $this->stats->newUsers() + $this->stats->arrivedUsers(),
|
||||
'arrived_user_count' => $this->stats->arrivedUsers(),
|
||||
'user_count' => $this->stats->usersState() + $this->stats->usersState(null, false),
|
||||
'arrived_user_count' => $this->stats->usersState(),
|
||||
'done_work_hours' => round($this->stats->workSeconds(true) / 60 / 60, 0),
|
||||
'users_in_action' => $this->stats->currentlyWorkingUsers(),
|
||||
];
|
||||
|
|
|
@ -36,13 +36,13 @@ class Stats
|
|||
}
|
||||
|
||||
/**
|
||||
* The number of not arrived users
|
||||
* The number of users that arrived/not arrived and/or did some work
|
||||
*
|
||||
* @param bool|null $working
|
||||
*/
|
||||
public function arrivedUsers(bool $working = null): int
|
||||
public function usersState(bool $working = null, bool $arrived = true): int
|
||||
{
|
||||
$query = State::whereArrived(true);
|
||||
$query = State::whereArrived($arrived);
|
||||
|
||||
if (!is_null($working)) {
|
||||
$query
|
||||
|
@ -69,14 +69,6 @@ class Stats
|
|||
return $query->count('users_state.user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of not arrived users
|
||||
*/
|
||||
public function newUsers(): int
|
||||
{
|
||||
return State::whereArrived(false)->count();
|
||||
}
|
||||
|
||||
public function forceActiveUsers(): int
|
||||
{
|
||||
return State::whereForceActive(true)->count();
|
||||
|
|
|
@ -90,10 +90,10 @@ class ControllerTest extends TestCase
|
|||
->method('licenses')
|
||||
->withConsecutive(['has_car'], ['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12t'], ['ifsg_light'], ['ifsg'])
|
||||
->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1, 5, 4);
|
||||
$stats->expects($this->exactly(2))
|
||||
->method('arrivedUsers')
|
||||
->withConsecutive([false], [true])
|
||||
->willReturnOnConsecutiveCalls(7, 43);
|
||||
$stats->expects($this->exactly(4))
|
||||
->method('usersState')
|
||||
->withConsecutive([false, false], [true, false], [false], [true])
|
||||
->willReturnOnConsecutiveCalls(7, 43, 42, 10);
|
||||
$stats->expects($this->exactly(2))
|
||||
->method('currentlyWorkingUsers')
|
||||
->withConsecutive([false], [true])
|
||||
|
@ -123,7 +123,6 @@ class ControllerTest extends TestCase
|
|||
[LogLevel::DEBUG]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(0, 1, 0, 5, 999, 4, 55, 3);
|
||||
$this->setExpects($stats, 'newUsers', null, 9);
|
||||
$this->setExpects($stats, 'worklogSeconds', null, 39 * 60 * 60);
|
||||
$this->setExpects($stats, 'vouchers', null, 17);
|
||||
$this->setExpects($stats, 'tshirts', null, 3);
|
||||
|
@ -192,7 +191,7 @@ class ControllerTest extends TestCase
|
|||
$response->expects($this->once())
|
||||
->method('withContent')
|
||||
->with(json_encode([
|
||||
'user_count' => 13,
|
||||
'user_count' => 20,
|
||||
'arrived_user_count' => 10,
|
||||
'done_work_hours' => 99,
|
||||
'users_in_action' => 5,
|
||||
|
@ -210,8 +209,7 @@ class ControllerTest extends TestCase
|
|||
->method('workSeconds')
|
||||
->with(true)
|
||||
->willReturn((int) (60 * 60 * 99.47));
|
||||
$this->setExpects($stats, 'newUsers', null, 3);
|
||||
$this->setExpects($stats, 'arrivedUsers', null, 10, $this->exactly(2));
|
||||
$this->setExpects($stats, 'usersState', null, 10, $this->exactly(3));
|
||||
$this->setExpects($stats, 'currentlyWorkingUsers', null, 5);
|
||||
|
||||
$controller = new Controller($response, $engine, $config, $request, $stats, $version);
|
||||
|
|
|
@ -32,21 +32,10 @@ class StatsTest extends TestCase
|
|||
{
|
||||
use HasDatabase;
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::__construct
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::newUsers
|
||||
*/
|
||||
public function testNewUsers(): void
|
||||
{
|
||||
$this->addUsers();
|
||||
|
||||
$stats = new Stats($this->database);
|
||||
$this->assertEquals(2, $stats->newUsers());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::vouchers
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::vouchersQuery
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::__construct
|
||||
*/
|
||||
public function testVouchers(): void
|
||||
{
|
||||
|
@ -280,18 +269,22 @@ class StatsTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::arrivedUsers
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::usersState
|
||||
*/
|
||||
public function testArrivedUsers(): void
|
||||
public function testUsersState(): void
|
||||
{
|
||||
$this->addUsers();
|
||||
ShiftEntry::factory()->create(['user_id' => 3]);
|
||||
ShiftEntry::factory()->create(['user_id' => 4]);
|
||||
ShiftEntry::factory()->create(['user_id' => 1]);
|
||||
|
||||
$stats = new Stats($this->database);
|
||||
$this->assertEquals(7, $stats->arrivedUsers());
|
||||
$this->assertEquals(5, $stats->arrivedUsers(false));
|
||||
$this->assertEquals(2, $stats->arrivedUsers(true));
|
||||
$this->assertEquals(7, $stats->usersState());
|
||||
$this->assertEquals(5, $stats->usersState(false));
|
||||
$this->assertEquals(2, $stats->usersState(true));
|
||||
$this->assertEquals(2, $stats->usersState(null, false));
|
||||
$this->assertEquals(1, $stats->usersState(true, false));
|
||||
$this->assertEquals(1, $stats->usersState(false, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue