Skip to content

Commit

Permalink
feat: display statistics about genders used in the company (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Apr 18, 2021
1 parent 71c1e27 commit f628b7c
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ public function index(): Response
$company = InstanceHelper::getLoggedCompany();
$employee = InstanceHelper::getLoggedEmployee();

$genders = CompanyHRViewHelper::genderStats($company);
$eCoffees = CompanyHRViewHelper::eCoffees($company);
$statistics = CompanyViewHelper::information($company);

return Inertia::render('Company/HR/Index', [
'tab' => 'hr',
'eCoffees' => $eCoffees,
'statistics' => $statistics,
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
'genders' => $genders,
'notifications' => NotificationHelper::getNotifications($employee),
]);
}
}
48 changes: 48 additions & 0 deletions app/Http/ViewHelpers/Company/HR/CompanyHRViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Http\ViewHelpers\Company\HR;

use App\Models\User\Pronoun;
use App\Models\Company\Company;
use App\Models\Company\ECoffee;
use App\Models\Company\Employee;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class CompanyHRViewHelper
Expand Down Expand Up @@ -96,4 +99,49 @@ public static function eCoffees(Company $company): ?array
'number_of_sessions' => $numberOfSessions,
];
}

/**
* Get the statistics about all the genders used in the company, sorted
* by the gender used the most.
*
* @param Company $company
* @return array
*/
public static function genderStats(Company $company): array
{
$pronouns = Pronoun::addSelect([
'number_of_employees' => Employee::selectRaw('count(*)')
->whereColumn('pronoun_id', 'pronouns.id')
->where('company_id', $company->id),
])->get();

$pronouns = $pronouns->filter(function ($pronoun) {
return $pronoun->number_of_employees != 0;
});

$totalNumberOfEmployees = $company->employees()->count();
$totalNumberOfEmployeesWithoutPronoun = $company->employees()->whereNull('pronoun_id')->count();

$pronounCollection = collect();

// stat about employees without gender
$pronounCollection->push([
'id' => 0,
'label' => trans('account.pronoun_blank'),
'number_of_employees' => $totalNumberOfEmployeesWithoutPronoun,
'percent' => (int) round($totalNumberOfEmployeesWithoutPronoun * 100 / $totalNumberOfEmployees, 0),
]);

// stats about genders
foreach ($pronouns as $pronoun) {
$pronounCollection->push([
'id' => $pronoun->id,
'label' => trans($pronoun->translation_key),
'number_of_employees' => (int) $pronoun->number_of_employees,
'percent' => (int) round($pronoun->number_of_employees * 100 / $totalNumberOfEmployees, 0),
]);
}

return $pronounCollection->sortByDesc('percent')->values()->all();
}
}
10 changes: 9 additions & 1 deletion resources/js/Pages/Company/HR/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
</div>

<div class="fl w-third-l w-100 pl4-l">
2
<genders
:genders="genders"
/>
</div>

<div class="fl w-third-l w-100 pl4-l">
Expand All @@ -92,12 +94,14 @@
<script>
import Layout from '@/Shared/Layout';
import eCoffees from '@/Pages/Company/HR/Partials/eCoffees';
import Genders from '@/Pages/Company/HR/Partials/Genders';
import Tab from '@/Pages/Company/Partials/Tab';
export default {
components: {
Layout,
eCoffees,
Genders,
Tab,
},
Expand All @@ -114,6 +118,10 @@ export default {
type: Object,
default: null,
},
genders: {
type: Object,
default: null,
},
notifications: {
type: Array,
default: null,
Expand Down
65 changes: 65 additions & 0 deletions resources/js/Pages/Company/HR/Partials/Genders.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<style lang="scss" scoped>
.progress-bar {
border-radius: 3px;
overflow: hidden;
width: 100%;
span {
display: block;
}
}
.bar {
background: rgba(0,0,0,0.075);
width: 100%
}
.progress {
animation: loader 8s cubic-bezier(.45,.05,.55,.95) forwards;
background: #75b800;
color: #fff;
padding: 5px;
}
</style>

<template>
<div class="mb4">
<span class="db fw5 mb2 relative">
<span class="mr1">
👫
</span> Genders in the company
</span>

<div class="br3 bg-white box z-1 pa3 relative">
<!-- genders -->
<div v-for="gender in genders" :key="gender.id" class="mb3">
<div class="flex justify-between mb2">
<span class="fw5">
{{ gender.label }}
</span>
<span class="gray f6">
{{ gender.percent }}%
</span>
</div>
<div class="progress-bar mb2">
<span class="bar">
<span class="progress" :style="'width: ' + gender.percent + '%;'"></span>
</span>
</div>
</div>
</div>
</div>
</template>

<script>
export default {
props: {
genders: {
type: Object,
default: null,
},
},
};
</script>
1 change: 1 addition & 0 deletions resources/lang/en/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
'pronoun_ve_ver' => 've/ver',
'pronoun_xe_xem' => 'xe/xem',
'pronoun_ze_hir' => 'ze/hir',
'pronoun_blank' => 'No gender',

'questions_number_questions' => '{company} has {count} questions.',
'questions_blank' => 'Ask questions about your colleagues so they can know each other better.',
Expand Down
53 changes: 53 additions & 0 deletions tests/Unit/ViewHelpers/Company/HR/CompanyHRViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use Carbon\Carbon;
use Tests\TestCase;
use App\Models\User\Pronoun;
use App\Models\Company\Company;
use App\Models\Company\ECoffee;
use App\Models\Company\Employee;
use App\Models\Company\ECoffeeMatch;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Http\ViewHelpers\Company\HR\CompanyHRViewHelper;
Expand Down Expand Up @@ -96,4 +99,54 @@ public function it_gets_the_list_of_statistic_about_ecoffees_in_the_company(): v
$array
);
}

/** @test */
public function it_gets_the_stats_about_the_pronouns_used_in_the_company(): void
{
$company = Company::factory()->create();
Pronoun::all()->each(function (Pronoun $pronoun) {
$pronoun->delete();
});

$pronounMale = Pronoun::factory()->create([
'translation_key' => 'he/him',
]);
$pronounFemale = Pronoun::factory()->create([
'translation_key' => 'female',
]);
Employee::factory()->count(2)->create([
'company_id' => $company->id,
'pronoun_id' => $pronounMale->id,
]);
Employee::factory()->create([
'company_id' => $company->id,
'pronoun_id' => $pronounFemale->id,
]);

$array = CompanyHRViewHelper::genderStats($company);

$this->assertEquals(
[
0 => [
'id' => $pronounMale->id,
'label' => 'he/him',
'number_of_employees' => 2,
'percent' => 67,
],
1 => [
'id' => $pronounFemale->id,
'label' => 'female',
'number_of_employees' => 1,
'percent' => 33,
],
2 => [
'id' => 0,
'label' => 'No gender',
'number_of_employees' => 0,
'percent' => 0,
],
],
$array
);
}
}

0 comments on commit f628b7c

Please sign in to comment.