Skip to content

Commit

Permalink
Refactor/simplify statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Jan 29, 2025
1 parent 65c7a26 commit 408e187
Show file tree
Hide file tree
Showing 50 changed files with 99 additions and 1,552 deletions.
32 changes: 1 addition & 31 deletions app/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@
use Fisharebest\Webtrees\Statistics\Repository\GedcomRepository;
use Fisharebest\Webtrees\Statistics\Repository\HitCountRepository;
use Fisharebest\Webtrees\Statistics\Repository\IndividualRepository;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\BrowserRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\EventRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\FamilyDatesRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\FavoritesRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\GedcomRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\HitCountRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\IndividualRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\LatestUserRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\MediaRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\MessageRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\NewsRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\PlaceRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ServerRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\UserRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository;
use Fisharebest\Webtrees\Statistics\Repository\MediaRepository;
use Fisharebest\Webtrees\Statistics\Repository\MessageRepository;
Expand All @@ -73,22 +58,7 @@
* These are primarily used for embedded keywords on HTML blocks, but
* are also used elsewhere in the code.
*/
class Statistics implements
GedcomRepositoryInterface,
IndividualRepositoryInterface,
EventRepositoryInterface,
MediaRepositoryInterface,
UserRepositoryInterface,
ServerRepositoryInterface,
BrowserRepositoryInterface,
HitCountRepositoryInterface,
LatestUserRepositoryInterface,
FavoritesRepositoryInterface,
NewsRepositoryInterface,
MessageRepositoryInterface,
ContactRepositoryInterface,
FamilyDatesRepositoryInterface,
PlaceRepositoryInterface
class Statistics
{
private Tree $tree;

Expand Down
9 changes: 0 additions & 9 deletions app/Statistics/Google/ChartAge.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class ChartAge

private CenturyService $century_service;

/**
* @param CenturyService $century_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, Tree $tree)
{
$this->century_service = $century_service;
Expand Down Expand Up @@ -90,11 +86,6 @@ private function queryRecords(): Collection
]);
}

/**
* General query on ages.
*
* @return string
*/
public function chartAge(): string
{
$out = [];
Expand Down
13 changes: 0 additions & 13 deletions app/Statistics/Google/ChartBirth.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class ChartBirth

private ColorService $color_service;

/**
* @param CenturyService $century_service
* @param ColorService $color_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, ColorService $color_service, Tree $tree)
{
$this->century_service = $century_service;
Expand Down Expand Up @@ -75,14 +70,6 @@ private function queryRecords(): Collection
]);
}

/**
* Create a chart of birth places.
*
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
*/
public function chartBirth(string|null $color_from = null, string|null $color_to = null): string
{
$color_from ??= 'ffffff';
Expand Down
9 changes: 0 additions & 9 deletions app/Statistics/Google/ChartChildren.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class ChartChildren

private CenturyService $century_service;

/**
* @param CenturyService $century_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, Tree $tree)
{
$this->century_service = $century_service;
Expand Down Expand Up @@ -72,11 +68,6 @@ private function queryRecords(): Collection
]);
}

/**
* Creates a children per family chart.
*
* @return string
*/
public function chartChildren(): string
{
$data = [
Expand Down
16 changes: 3 additions & 13 deletions app/Statistics/Google/ChartCommonGiven.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,16 @@ class ChartCommonGiven
{
private ColorService $color_service;

/**
* @param ColorService $color_service
*/
public function __construct(ColorService $color_service)
{
$this->color_service = $color_service;
}

/**
* Create a chart of common given names.
*
* @param int $tot_indi The total number of individuals
* @param array<int> $given The list of common given names
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
* @param array<int> $given
*/
public function chartCommonGiven(
int $tot_indi,
int $total_individuals,
array $given,
string|null $color_from = null,
string|null $color_to = null
Expand All @@ -77,7 +67,7 @@ public function chartCommonGiven(

$data[] = [
I18N::translate('Other'),
$tot_indi - $tot
$total_individuals - $tot
];

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
Expand Down
17 changes: 3 additions & 14 deletions app/Statistics/Google/ChartCommonSurname.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class ChartCommonSurname

private SurnameTraditionInterface $surname_tradition;

/**
* @param ColorService $color_service
* @param SurnameTraditionInterface $surname_tradition
*/
public function __construct(ColorService $color_service, SurnameTraditionInterface $surname_tradition)
{
$this->surname_tradition = $surname_tradition;
Expand Down Expand Up @@ -99,17 +95,10 @@ private function getTopNameAndCount(array $surns): array
}

/**
* Create a chart of common surnames.
*
* @param int $tot_indi The total number of individuals
* @param array<array<int>> $all_surnames The list of common surnames
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
* @param array<array<int>> $all_surnames
*/
public function chartCommonSurnames(
int $tot_indi,
int $total_individuals,
array $all_surnames,
string|null $color_from = null,
string|null $color_to = null
Expand All @@ -135,7 +124,7 @@ public function chartCommonSurnames(

$data[] = [
I18N::translate('Other'),
$tot_indi - $tot
$total_individuals - $tot
];

$colors = $this->color_service->interpolateRgb($color_from, $color_to, count($data) - 1);
Expand Down
13 changes: 0 additions & 13 deletions app/Statistics/Google/ChartDeath.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class ChartDeath

private ColorService $color_service;

/**
* @param CenturyService $century_service
* @param ColorService $color_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, ColorService $color_service, Tree $tree)
{
$this->century_service = $century_service;
Expand Down Expand Up @@ -75,14 +70,6 @@ private function queryRecords(): Collection
]);
}

/**
* Create a chart of death places.
*
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
*/
public function chartDeath(string|null $color_from = null, string|null $color_to = null): string
{
$color_from ??= 'ffffff';
Expand Down
39 changes: 8 additions & 31 deletions app/Statistics/Google/ChartDistribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use Fisharebest\Webtrees\DB;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\IndividualRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\IndividualRepository;
use Fisharebest\Webtrees\Statistics\Service\CountryService;
use Fisharebest\Webtrees\Tree;
use Illuminate\Database\Query\Builder;
Expand All @@ -41,22 +41,17 @@ class ChartDistribution

private CountryService $country_service;

private IndividualRepositoryInterface $individual_repository;
private IndividualRepository $individual_repository;

/**
* @var array<string>
*/
private array $country_to_iso3166;

/**
* @param Tree $tree
* @param CountryService $country_service
* @param IndividualRepositoryInterface $individual_repository
*/
public function __construct(
Tree $tree,
CountryService $country_service,
IndividualRepositoryInterface $individual_repository
IndividualRepository $individual_repository
) {
$this->tree = $tree;
$this->country_service = $country_service;
Expand All @@ -67,8 +62,6 @@ public function __construct(
}

/**
* Returns the country names for each language.
*
* @return array<string>
*/
private function getIso3166Countries(): array
Expand Down Expand Up @@ -125,9 +118,7 @@ private function createChartData(array $places): array
}

/**
* @param Tree $tree
*
* @return array<int>
* @return array<string,int>
*/
private function countIndividualsByCountry(Tree $tree): array
{
Expand Down Expand Up @@ -161,10 +152,7 @@ private function countIndividualsByCountry(Tree $tree): array
}

/**
* @param Tree $tree
* @param string $surname
*
* @return array<int>
* @return array<string,int>
*/
private function countSurnamesByCountry(Tree $tree, string $surname): array
{
Expand Down Expand Up @@ -200,10 +188,7 @@ private function countSurnamesByCountry(Tree $tree, string $surname): array
}

/**
* @param Tree $tree
* @param string $fact
*
* @return array<int>
* @return array<string,int>
*/
private function countFamilyEventsByCountry(Tree $tree, string $fact): array
{
Expand All @@ -226,10 +211,7 @@ private function countFamilyEventsByCountry(Tree $tree, string $fact): array
}

/**
* @param Tree $tree
* @param string $fact
*
* @return array<int>
* @return array<string,int>
*/
private function countIndividualEventsByCountry(Tree $tree, string $fact): array
{
Expand All @@ -252,10 +234,7 @@ private function countIndividualEventsByCountry(Tree $tree, string $fact): array
}

/**
* @param Builder $query
* @param string $fact
*
* @return array<int>
* @return array<string,int>
*/
private function filterEventPlaces(Builder $query, string $fact): array
{
Expand All @@ -282,8 +261,6 @@ private function filterEventPlaces(Builder $query, string $fact): array
* @param string $chart_shows The type of chart map to show
* @param string $chart_type The type of chart to show
* @param string $surname The surname for surname based distribution chart
*
* @return string
*/
public function chartDistribution(
string $chart_shows = 'world',
Expand Down
7 changes: 0 additions & 7 deletions app/Statistics/Google/ChartDivorce.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class ChartDivorce

private ColorService $color_service;

/**
* @param CenturyService $century_service
* @param ColorService $color_service
* @param Tree $tree
*/
public function __construct(CenturyService $century_service, ColorService $color_service, Tree $tree)
{
$this->century_service = $century_service;
Expand Down Expand Up @@ -80,8 +75,6 @@ private function queryRecords(): Collection
*
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
*/
public function chartDivorce(string|null $color_from = null, string|null $color_to = null): string
{
Expand Down
Loading

0 comments on commit 408e187

Please sign in to comment.