add ifsg and drive confirmed stats to metrics

This commit is contained in:
Xu 2024-03-26 21:02:05 +01:00 committed by Igor Scheller
parent fcf23d3824
commit 6e76843db4
4 changed files with 76 additions and 33 deletions

View File

@ -68,14 +68,14 @@ class Controller extends BaseController
], ],
'users' => [ 'users' => [
'type' => 'gauge', 'type' => 'gauge',
['labels' => ['state' => 'incoming', 'working' => 'no'], 'value' ['labels' => ['state' => 'incoming', 'working' => 'no'],
=> $this->stats->usersState(false, false)], 'value' => $this->stats->usersState(false, false)],
['labels' => ['state' => 'incoming', 'working' => 'yes'], 'value' ['labels' => ['state' => 'incoming', 'working' => 'yes'],
=> $this->stats->usersState(true, false)], 'value' => $this->stats->usersState(true, false)],
['labels' => ['state' => 'arrived', 'working' => 'no'], 'value' ['labels' => ['state' => 'arrived', 'working' => 'no'],
=> $this->stats->usersState(false)], 'value' => $this->stats->usersState(false)],
['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value' ['labels' => ['state' => 'arrived', 'working' => 'yes'],
=> $this->stats->usersState(true)], 'value' => $this->stats->usersState(true)],
], ],
'users_info' => ['type' => 'gauge', $this->stats->usersInfo()], 'users_info' => ['type' => 'gauge', $this->stats->usersInfo()],
'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()], 'users_force_active' => ['type' => 'gauge', $this->stats->forceActiveUsers()],
@ -84,13 +84,24 @@ class Controller extends BaseController
'type' => 'gauge', 'type' => 'gauge',
'help' => 'The total number of licenses', 'help' => 'The total number of licenses',
['labels' => ['type' => 'has_car'], 'value' => $this->stats->licenses('has_car')], ['labels' => ['type' => 'has_car'], 'value' => $this->stats->licenses('has_car')],
['labels' => ['type' => 'forklift'], 'value' => $this->stats->licenses('forklift')], ['labels' => ['type' => 'forklift', 'confirmed' => 'no'],
['labels' => ['type' => 'car'], 'value' => $this->stats->licenses('car')], 'value' => $this->stats->licenses('forklift')],
['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')], ['labels' => ['type' => 'forklift', 'confirmed' => 'yes'],
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')], 'value' => $this->stats->licenses('forklift', true)],
['labels' => ['type' => '12t'], 'value' => $this->stats->licenses('12t')], ['labels' => ['type' => 'car', 'confirmed' => 'no'], 'value' => $this->stats->licenses('car')],
['labels' => ['type' => 'ifsg_light'], 'value' => $this->stats->licenses('ifsg_light')], ['labels' => ['type' => 'car', 'confirmed' => 'yes'], 'value' => $this->stats->licenses('car', true)],
['labels' => ['type' => 'ifsg'], 'value' => $this->stats->licenses('ifsg')], ['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' => [ 'users_email' => [
'type' => 'gauge', 'type' => 'gauge',

View File

@ -176,22 +176,25 @@ class Stats
->get(); ->get();
} }
public function licenses(string $license): int public function licenses(string $license, bool $confirmed = false): int
{ {
$mapping = [ $mapping = [
'has_car' => 'has_car', 'has_car' => ['has_car', null],
'forklift' => 'drive_forklift', 'forklift' => ['drive_forklift', 'drive_confirmed'],
'car' => 'drive_car', 'car' => ['drive_car', 'drive_confirmed'],
'3.5t' => 'drive_3_5t', '3.5t' => ['drive_3_5t', 'drive_confirmed'],
'7.5t' => 'drive_7_5t', '7.5t' => ['drive_7_5t', 'drive_confirmed'],
'12t' => 'drive_12t', '12t' => ['drive_12t', 'drive_confirmed'],
'ifsg_light' => 'ifsg_certificate_light', 'ifsg_light' => ['ifsg_certificate_light', 'ifsg_confirmed'],
'ifsg' => 'ifsg_certificate', 'ifsg' => ['ifsg_certificate', 'ifsg_confirmed'],
]; ];
$query = (new License()) $query = (new License())
->getQuery() ->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(); return $query->count();
} }

View File

@ -86,10 +86,26 @@ class ControllerTest extends TestCase
->with('metrics return') ->with('metrics return')
->willReturn($response); ->willReturn($response);
$stats->expects($this->exactly(8)) $stats->expects($this->exactly(15))
->method('licenses') ->method('licenses')
->withConsecutive(['has_car'], ['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12t'], ['ifsg_light'], ['ifsg']) ->withConsecutive(
->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1, 5, 4); ['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)) $stats->expects($this->exactly(4))
->method('usersState') ->method('usersState')
->withConsecutive([false, false], [true, false], [false], [true]) ->withConsecutive([false, false], [true, false], [false], [true])

View File

@ -129,12 +129,19 @@ class StatsTest extends TestCase
$stats = new Stats($this->database); $stats = new Stats($this->database);
$this->assertEquals(1, $stats->licenses('has_car')); $this->assertEquals(1, $stats->licenses('has_car'));
$this->assertEquals(1, $stats->licenses('forklift')); $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('3.5t'));
$this->assertEquals(0, $stats->licenses('7.5t')); $this->assertEquals(0, $stats->licenses('7.5t'));
$this->assertEquals(1, $stats->licenses('12t')); $this->assertEquals(0, $stats->licenses('12t'));
$this->assertEquals(0, $stats->licenses('ifsg_light')); $this->assertEquals(1, $stats->licenses('ifsg_light'));
$this->assertEquals(0, $stats->licenses('ifsg')); $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'], ['arrived' => 1, 'got_voucher' => 9, 'force_active' => true, 'user_info' => 'Info'],
[], [],
['theme' => 1], ['theme' => 1],
['drive_car' => true, 'drive_12t' => true] ['drive_car' => true, 'drive_12t' => true, 'drive_confirmed' => true, 'ifsg_certificate_light' => true]
); );
$this->addUser( $this->addUser(
['arrived' => 1, 'got_voucher' => 3], ['arrived' => 1, 'got_voucher' => 3],
['pronoun' => 'per'], ['pronoun' => 'per'],
['theme' => 1, 'email_human' => true], ['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, 'force_active' => true]);
$this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L'], ['theme' => 4]); $this->addUser(['arrived' => 1, 'active' => 1, 'got_shirt' => true], ['shirt_size' => 'L'], ['theme' => 4]);