Metrics: Added user enabled email targets and comments counts
This commit is contained in:
parent
9dd2525e93
commit
c0c1dab711
|
@ -107,6 +107,11 @@ class Controller extends BaseController
|
||||||
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
|
['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
|
||||||
['labels' => ['type' => '12.5t'], 'value' => $this->stats->licenses('12.5t')],
|
['labels' => ['type' => '12.5t'], 'value' => $this->stats->licenses('12.5t')],
|
||||||
],
|
],
|
||||||
|
'users_email' => [
|
||||||
|
'type' => 'gauge',
|
||||||
|
['labels' => ['type' => 'system'], 'value' => $this->stats->email('system')],
|
||||||
|
['labels' => ['type' => 'humans'], 'value' => $this->stats->email('humans')],
|
||||||
|
],
|
||||||
'users_working' => [
|
'users_working' => [
|
||||||
'type' => 'gauge',
|
'type' => 'gauge',
|
||||||
['labels' => ['freeloader' => false], $this->stats->currentlyWorkingUsers(false)],
|
['labels' => ['freeloader' => false], $this->stats->currentlyWorkingUsers(false)],
|
||||||
|
@ -152,6 +157,7 @@ class Controller extends BaseController
|
||||||
['labels' => ['type' => 'news'], 'value' => $this->stats->announcements(false)],
|
['labels' => ['type' => 'news'], 'value' => $this->stats->announcements(false)],
|
||||||
['labels' => ['type' => 'meeting'], 'value' => $this->stats->announcements(true)],
|
['labels' => ['type' => 'meeting'], 'value' => $this->stats->announcements(true)],
|
||||||
],
|
],
|
||||||
|
'comments' => ['type' => 'gauge', $this->stats->comments()],
|
||||||
'questions' => [
|
'questions' => [
|
||||||
'type' => 'gauge',
|
'type' => 'gauge',
|
||||||
['labels' => ['state' => 'answered'], 'value' => $this->stats->questions(true)],
|
['labels' => ['state' => 'answered'], 'value' => $this->stats->questions(true)],
|
||||||
|
|
|
@ -10,6 +10,7 @@ use Engelsystem\Models\EventConfig;
|
||||||
use Engelsystem\Models\LogEntry;
|
use Engelsystem\Models\LogEntry;
|
||||||
use Engelsystem\Models\Message;
|
use Engelsystem\Models\Message;
|
||||||
use Engelsystem\Models\News;
|
use Engelsystem\Models\News;
|
||||||
|
use Engelsystem\Models\NewsComment;
|
||||||
use Engelsystem\Models\Question;
|
use Engelsystem\Models\Question;
|
||||||
use Engelsystem\Models\User\PasswordReset;
|
use Engelsystem\Models\User\PasswordReset;
|
||||||
use Engelsystem\Models\User\PersonalData;
|
use Engelsystem\Models\User\PersonalData;
|
||||||
|
@ -88,6 +89,27 @@ class Stats
|
||||||
return State::whereForceActive(true)->count();
|
return State::whereForceActive(true)->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function email(string $type): int
|
||||||
|
{
|
||||||
|
switch ($type) {
|
||||||
|
case 'system':
|
||||||
|
$query = Settings::whereEmailShiftinfo(true);
|
||||||
|
break;
|
||||||
|
case 'humans':
|
||||||
|
$query = Settings::whereEmailHuman(true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->count();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of currently working users
|
* The number of currently working users
|
||||||
*
|
*
|
||||||
|
@ -364,6 +386,15 @@ class Stats
|
||||||
return $query->count();
|
return $query->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function comments(): int
|
||||||
|
{
|
||||||
|
return NewsComment::query()
|
||||||
|
->count();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool|null $answered
|
* @param bool|null $answered
|
||||||
* @return int
|
* @return int
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Engelsystem\Controllers\Metrics\Stats;
|
||||||
use Engelsystem\Models\LogEntry;
|
use Engelsystem\Models\LogEntry;
|
||||||
use Engelsystem\Models\Message;
|
use Engelsystem\Models\Message;
|
||||||
use Engelsystem\Models\News;
|
use Engelsystem\Models\News;
|
||||||
|
use Engelsystem\Models\NewsComment;
|
||||||
use Engelsystem\Models\Question;
|
use Engelsystem\Models\Question;
|
||||||
use Engelsystem\Models\User\PasswordReset;
|
use Engelsystem\Models\User\PasswordReset;
|
||||||
use Engelsystem\Models\User\PersonalData;
|
use Engelsystem\Models\User\PersonalData;
|
||||||
|
@ -112,13 +113,12 @@ class StatsTest extends TestCase
|
||||||
$themes = $stats->themes();
|
$themes = $stats->themes();
|
||||||
$this->assertCount(3, $themes);
|
$this->assertCount(3, $themes);
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
['theme' => 0, 'count' => 7],
|
['theme' => 0, 'count' => 6],
|
||||||
['theme' => 1, 'count' => 1],
|
['theme' => 1, 'count' => 2],
|
||||||
['theme' => 4, 'count' => 1],
|
['theme' => 4, 'count' => 1],
|
||||||
], $themes->toArray());
|
], $themes->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Controllers\Metrics\Stats::announcements
|
* @covers \Engelsystem\Controllers\Metrics\Stats::announcements
|
||||||
*/
|
*/
|
||||||
|
@ -137,6 +137,27 @@ class StatsTest extends TestCase
|
||||||
$this->assertEquals(1, $stats->announcements(true));
|
$this->assertEquals(1, $stats->announcements(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\Metrics\Stats::comments
|
||||||
|
*/
|
||||||
|
public function testComments()
|
||||||
|
{
|
||||||
|
$user = $this->addUser();
|
||||||
|
|
||||||
|
$news = new News(['title' => 'Test', 'text' => 'Foo Bar', 'user_id' => $user->id]);
|
||||||
|
$news->save();
|
||||||
|
|
||||||
|
foreach (['Test', 'Another text!'] as $text) {
|
||||||
|
$comment = new NewsComment(['text' => $text]);
|
||||||
|
$comment->news()->associate($news);
|
||||||
|
$comment->user()->associate($user);
|
||||||
|
$comment->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$stats = new Stats($this->database);
|
||||||
|
$this->assertEquals(2, $stats->comments());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Controllers\Metrics\Stats::questions
|
* @covers \Engelsystem\Controllers\Metrics\Stats::questions
|
||||||
*/
|
*/
|
||||||
|
@ -177,6 +198,19 @@ class StatsTest extends TestCase
|
||||||
$this->assertEquals(2, $stats->forceActiveUsers());
|
$this->assertEquals(2, $stats->forceActiveUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\Metrics\Stats::email
|
||||||
|
*/
|
||||||
|
public function testEmail()
|
||||||
|
{
|
||||||
|
$this->addUsers();
|
||||||
|
|
||||||
|
$stats = new Stats($this->database);
|
||||||
|
$this->assertEquals(0, $stats->email('not-available-option'));
|
||||||
|
$this->assertEquals(2, $stats->email('system'));
|
||||||
|
$this->assertEquals(3, $stats->email('humans'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Controllers\Metrics\Stats::messages
|
* @covers \Engelsystem\Controllers\Metrics\Stats::messages
|
||||||
*/
|
*/
|
||||||
|
@ -267,12 +301,12 @@ class StatsTest extends TestCase
|
||||||
protected function addUsers()
|
protected function addUsers()
|
||||||
{
|
{
|
||||||
$this->addUser();
|
$this->addUser();
|
||||||
$this->addUser([], ['shirt_size' => 'L']);
|
$this->addUser([], ['shirt_size' => 'L'], ['email_human' => true, 'email_shiftinfo' => true]);
|
||||||
$this->addUser(['arrived' => 1]);
|
$this->addUser(['arrived' => 1], [], ['email_human' => true]);
|
||||||
$this->addUser(['arrived' => 1], [], ['language' => 'lo_RM']);
|
$this->addUser(['arrived' => 1], [], ['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' => 2], ['shirt_size' => 'XXL'], ['language' => 'lo_RM']);
|
||||||
$this->addUser(['arrived' => 1, 'got_voucher' => 9, 'force_active' => true], [], ['theme' => 1]);
|
$this->addUser(['arrived' => 1, 'got_voucher' => 9, 'force_active' => true], [], ['theme' => 1]);
|
||||||
$this->addUser(['arrived' => 1, 'got_voucher' => 3], ['theme' => 10]);
|
$this->addUser(['arrived' => 1, 'got_voucher' => 3], [], ['theme' => 1, 'email_human' => 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]);
|
||||||
}
|
}
|
||||||
|
@ -281,8 +315,10 @@ class StatsTest extends TestCase
|
||||||
* @param array $state
|
* @param array $state
|
||||||
* @param array $personalData
|
* @param array $personalData
|
||||||
* @param array $settings
|
* @param array $settings
|
||||||
|
*
|
||||||
|
* @return User
|
||||||
*/
|
*/
|
||||||
protected function addUser(array $state = [], $personalData = [], $settings = [])
|
protected function addUser(array $state = [], $personalData = [], $settings = []): User
|
||||||
{
|
{
|
||||||
$name = 'user_' . Str::random(5);
|
$name = 'user_' . Str::random(5);
|
||||||
|
|
||||||
|
@ -307,12 +343,14 @@ class StatsTest extends TestCase
|
||||||
$settings = new Settings(array_merge([
|
$settings = new Settings(array_merge([
|
||||||
'language' => 'te_ST',
|
'language' => 'te_ST',
|
||||||
'theme' => 0,
|
'theme' => 0,
|
||||||
'email_human' => '',
|
'email_human' => false,
|
||||||
'email_shiftinfo' => '',
|
'email_shiftinfo' => false,
|
||||||
], $settings));
|
], $settings));
|
||||||
$settings->user()
|
$settings->user()
|
||||||
->associate($user)
|
->associate($user)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue