add ifsg and drive confirmed stats to metrics
This commit is contained in:
parent
fcf23d3824
commit
6e76843db4
|
@ -68,14 +68,14 @@ class Controller extends BaseController
|
|||
],
|
||||
'users' => [
|
||||
'type' => 'gauge',
|
||||
['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)],
|
||||
['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_info' => ['type' => 'gauge', $this->stats->usersInfo()],
|
||||
'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()],
|
||||
|
@ -84,13 +84,24 @@ class Controller extends BaseController
|
|||
'type' => 'gauge',
|
||||
'help' => 'The total number of licenses',
|
||||
['labels' => ['type' => 'has_car'], 'value' => $this->stats->licenses('has_car')],
|
||||
['labels' => ['type' => 'forklift'], 'value' => $this->stats->licenses('forklift')],
|
||||
['labels' => ['type' => 'car'], 'value' => $this->stats->licenses('car')],
|
||||
['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')],
|
||||
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
|
||||
['labels' => ['type' => '12t'], 'value' => $this->stats->licenses('12t')],
|
||||
['labels' => ['type' => 'ifsg_light'], 'value' => $this->stats->licenses('ifsg_light')],
|
||||
['labels' => ['type' => 'ifsg'], 'value' => $this->stats->licenses('ifsg')],
|
||||
['labels' => ['type' => 'forklift', 'confirmed' => 'no'],
|
||||
'value' => $this->stats->licenses('forklift')],
|
||||
['labels' => ['type' => 'forklift', 'confirmed' => 'yes'],
|
||||
'value' => $this->stats->licenses('forklift', true)],
|
||||
['labels' => ['type' => 'car', 'confirmed' => 'no'], 'value' => $this->stats->licenses('car')],
|
||||
['labels' => ['type' => 'car', 'confirmed' => 'yes'], 'value' => $this->stats->licenses('car', true)],
|
||||
['labels' => ['type' => '3.5t', 'confirmed' => 'no'], 'value' => $this->stats->licenses('3.5t')],
|
||||
['labels' => ['type' => '3.5t', 'confirmed' => 'yes'], 'value' => $this->stats->licenses('3.5t', true)],
|
||||
['labels' => ['type' => '7.5t', 'confirmed' => 'no'], 'value' => $this->stats->licenses('7.5t')],
|
||||
['labels' => ['type' => '7.5t', 'confirmed' => 'yes'], 'value' => $this->stats->licenses('7.5t', true)],
|
||||
['labels' => ['type' => '12t', 'confirmed' => 'no'], 'value' => $this->stats->licenses('12t')],
|
||||
['labels' => ['type' => '12t', 'confirmed' => 'yes'], 'value' => $this->stats->licenses('12t', true)],
|
||||
['labels' => ['type' => 'ifsg_light', 'confirmed' => 'no'],
|
||||
'value' => $this->stats->licenses('ifsg_light')],
|
||||
['labels' => ['type' => 'ifsg_light', 'confirmed' => 'yes'],
|
||||
'value' => $this->stats->licenses('ifsg_light', true)],
|
||||
['labels' => ['type' => 'ifsg', 'confirmed' => 'no'], 'value' => $this->stats->licenses('ifsg')],
|
||||
['labels' => ['type' => 'ifsg', 'confirmed' => 'yes'], 'value' => $this->stats->licenses('ifsg', true)],
|
||||
],
|
||||
'users_email' => [
|
||||
'type' => 'gauge',
|
||||
|
|
|
@ -176,22 +176,25 @@ class Stats
|
|||
->get();
|
||||
}
|
||||
|
||||
public function licenses(string $license): int
|
||||
public function licenses(string $license, bool $confirmed = false): int
|
||||
{
|
||||
$mapping = [
|
||||
'has_car' => 'has_car',
|
||||
'forklift' => 'drive_forklift',
|
||||
'car' => 'drive_car',
|
||||
'3.5t' => 'drive_3_5t',
|
||||
'7.5t' => 'drive_7_5t',
|
||||
'12t' => 'drive_12t',
|
||||
'ifsg_light' => 'ifsg_certificate_light',
|
||||
'ifsg' => 'ifsg_certificate',
|
||||
'has_car' => ['has_car', null],
|
||||
'forklift' => ['drive_forklift', 'drive_confirmed'],
|
||||
'car' => ['drive_car', 'drive_confirmed'],
|
||||
'3.5t' => ['drive_3_5t', 'drive_confirmed'],
|
||||
'7.5t' => ['drive_7_5t', 'drive_confirmed'],
|
||||
'12t' => ['drive_12t', 'drive_confirmed'],
|
||||
'ifsg_light' => ['ifsg_certificate_light', 'ifsg_confirmed'],
|
||||
'ifsg' => ['ifsg_certificate', 'ifsg_confirmed'],
|
||||
];
|
||||
|
||||
$query = (new License())
|
||||
->getQuery()
|
||||
->where($mapping[$license], true);
|
||||
->where($mapping[$license][0], true);
|
||||
if (!is_null($mapping[$license][1])) {
|
||||
$query->where($mapping[$license][1], $confirmed);
|
||||
}
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
|
|
@ -86,10 +86,26 @@ class ControllerTest extends TestCase
|
|||
->with('metrics return')
|
||||
->willReturn($response);
|
||||
|
||||
$stats->expects($this->exactly(8))
|
||||
$stats->expects($this->exactly(15))
|
||||
->method('licenses')
|
||||
->withConsecutive(['has_car'], ['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12t'], ['ifsg_light'], ['ifsg'])
|
||||
->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1, 5, 4);
|
||||
->withConsecutive(
|
||||
['has_car'],
|
||||
['forklift'],
|
||||
['forklift'],
|
||||
['car'],
|
||||
['car', true],
|
||||
['3.5t'],
|
||||
['3.5t', true],
|
||||
['7.5t'],
|
||||
['7.5t', true],
|
||||
['12t'],
|
||||
['12t', true],
|
||||
['ifsg_light'],
|
||||
['ifsg_light', true],
|
||||
['ifsg'],
|
||||
['ifsg', true],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1, 5, 4, 3, 5, 9, 2, 1, 7, 8);
|
||||
$stats->expects($this->exactly(4))
|
||||
->method('usersState')
|
||||
->withConsecutive([false, false], [true, false], [false], [true])
|
||||
|
|
|
@ -129,12 +129,19 @@ class StatsTest extends TestCase
|
|||
$stats = new Stats($this->database);
|
||||
$this->assertEquals(1, $stats->licenses('has_car'));
|
||||
$this->assertEquals(1, $stats->licenses('forklift'));
|
||||
$this->assertEquals(2, $stats->licenses('car'));
|
||||
$this->assertEquals(1, $stats->licenses('car'));
|
||||
$this->assertEquals(0, $stats->licenses('3.5t'));
|
||||
$this->assertEquals(0, $stats->licenses('7.5t'));
|
||||
$this->assertEquals(1, $stats->licenses('12t'));
|
||||
$this->assertEquals(0, $stats->licenses('ifsg_light'));
|
||||
$this->assertEquals(0, $stats->licenses('12t'));
|
||||
$this->assertEquals(1, $stats->licenses('ifsg_light'));
|
||||
$this->assertEquals(0, $stats->licenses('ifsg'));
|
||||
$this->assertEquals(0, $stats->licenses('forklift', true));
|
||||
$this->assertEquals(1, $stats->licenses('car', true));
|
||||
$this->assertEquals(0, $stats->licenses('3.5t', true));
|
||||
$this->assertEquals(0, $stats->licenses('7.5t', true));
|
||||
$this->assertEquals(1, $stats->licenses('12t', true));
|
||||
$this->assertEquals(0, $stats->licenses('ifsg_light', true));
|
||||
$this->assertEquals(1, $stats->licenses('ifsg', true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,13 +525,19 @@ class StatsTest extends TestCase
|
|||
['arrived' => 1, 'got_voucher' => 9, 'force_active' => true, 'user_info' => 'Info'],
|
||||
[],
|
||||
['theme' => 1],
|
||||
['drive_car' => true, 'drive_12t' => true]
|
||||
['drive_car' => true, 'drive_12t' => true, 'drive_confirmed' => true, 'ifsg_certificate_light' => true]
|
||||
);
|
||||
$this->addUser(
|
||||
['arrived' => 1, 'got_voucher' => 3],
|
||||
['pronoun' => 'per'],
|
||||
['theme' => 1, 'email_human' => true],
|
||||
['has_car' => true, 'drive_forklift' => true, 'drive_car' => true]
|
||||
[
|
||||
'has_car' => true,
|
||||
'drive_forklift' => true,
|
||||
'drive_car' => true,
|
||||
'ifsg_certificate' => true,
|
||||
'ifsg_confirmed' => 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'], ['theme' => 4]);
|
||||
|
|
Loading…
Reference in New Issue