Passed
Push — main ( ad76dd...bc3fc8 )
by Jonathan
12:59
created
app/Module/Sosa/Http/RequestHandlers/SosaStatistics.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -38,142 +38,142 @@
 block discarded – undo
38 38
  */
39 39
 class SosaStatistics implements RequestHandlerInterface
40 40
 {
41
-    use ViewResponseTrait;
42
-
43
-    private ?SosaModule $module;
44
-    private RelationshipService $relationship_service;
45
-
46
-    /**
47
-     * Constructor for AncestorsList Request Handler
48
-     *
49
-     * @param ModuleService $module_service
50
-     */
51
-    public function __construct(ModuleService $module_service, RelationshipService $relationship_service)
52
-    {
53
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
54
-        $this->relationship_service = $relationship_service;
55
-    }
56
-
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
-     */
61
-    public function handle(ServerRequestInterface $request): ResponseInterface
62
-    {
63
-        if ($this->module === null) {
64
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
-        }
66
-
67
-        $tree = Validator::attributes($request)->tree();
68
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
69
-
70
-        /** @var SosaStatisticsService $sosa_stats_service */
71
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72
-
73
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
74
-            'module_name'       =>  $this->module->name(),
75
-            'title'             =>  I18N::translate('Sosa Statistics'),
76
-            'tree'              =>  $tree,
77
-            'theme'             =>  app(ModuleThemeInterface::class),
78
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
79
-            'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
80
-            'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
81
-            'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
82
-            'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
83
-            'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
84
-            'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
85
-            'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3),
86
-            'relationship_service'  =>  $this->relationship_service,
87
-        ]);
88
-    }
89
-
90
-    /**
91
-     * Retrieve and compute the global statistics of ancestors for the tree.
92
-     * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
93
-     *
94
-     * @param SosaStatisticsService $sosa_stats_service
95
-     * @return array<string, int|float>
96
-     */
97
-    private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
98
-    {
99
-        $ancestors_count = $sosa_stats_service->totalAncestors();
100
-        $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
101
-        $individual_count = $sosa_stats_service->totalIndividuals();
102
-
103
-        return [
104
-            'sosa_count'    =>  $ancestors_count,
105
-            'distinct_count'    =>  $ancestors_distinct_count,
106
-            'sosa_rate' =>  $this->safeDivision(
107
-                BigInteger::of($ancestors_distinct_count),
108
-                BigInteger::of($individual_count)
109
-            ),
110
-            'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
111
-        ];
112
-    }
113
-
114
-    /**
115
-     * Retrieve and compute the statistics of ancestors by generations.
116
-     * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
117
-     *
118
-     * @param SosaStatisticsService $sosa_stats_service
119
-     * @return array<int, array<string, int|float>>
120
-     */
121
-    private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
122
-    {
123
-        $stats_by_gen = $sosa_stats_service->statisticsByGenerations();
124
-
125
-        $generation_stats = array();
126
-
127
-        foreach ($stats_by_gen as $gen => $stats_gen) {
128
-            $gen_diff = $gen > 1 ?
129
-                (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
-                1;
131
-            $generation_stats[$gen] = array(
132
-                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
-                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
134
-                'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
-                'known' => (int) $stats_gen['sosaCount'],
136
-                'perc_known' => $this->safeDivision(
137
-                    BigInteger::of((int) $stats_gen['sosaCount']),
138
-                    BigInteger::of(2)->power($gen - 1)
139
-                ),
140
-                'missing' => $gen > 1 ?
141
-                    2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
-                    0,
143
-                'perc_missing' => $gen > 1 ?
144
-                    1 - $this->safeDivision(
145
-                        BigInteger::of((int) $stats_gen['sosaCount']),
146
-                        BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
-                    ) :
148
-                    0,
149
-                'total_known' => (int) $stats_gen['sosaTotalCount'],
150
-                'perc_total_known' => $this->safeDivision(
151
-                    BigInteger::of((int) $stats_gen['sosaTotalCount']),
152
-                    BigInteger::of(2)->power($gen)->minus(1)
153
-                ),
154
-                'different' => $gen_diff,
155
-                'perc_different' => $this->safeDivision(
156
-                    BigInteger::of($gen_diff),
157
-                    BigInteger::of((int) $stats_gen['sosaCount'])
158
-                ),
159
-                'total_different' => (int) $stats_gen['diffSosaTotalCount']
160
-            );
161
-        }
162
-
163
-        return $generation_stats;
164
-    }
165
-
166
-    /**
167
-     * Return the result of a division, and a default value if denominator is 0
168
-     *
169
-     * @param BigInteger $p Numerator
170
-     * @param BigInteger $q Denominator
171
-     * @param int $scale Rounding scale
172
-     * @param float $default Value if denominator is 0
173
-     * @return float
174
-     */
175
-    private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float
176
-    {
177
-        return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat();
178
-    }
41
+	use ViewResponseTrait;
42
+
43
+	private ?SosaModule $module;
44
+	private RelationshipService $relationship_service;
45
+
46
+	/**
47
+	 * Constructor for AncestorsList Request Handler
48
+	 *
49
+	 * @param ModuleService $module_service
50
+	 */
51
+	public function __construct(ModuleService $module_service, RelationshipService $relationship_service)
52
+	{
53
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
54
+		$this->relationship_service = $relationship_service;
55
+	}
56
+
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
+	 */
61
+	public function handle(ServerRequestInterface $request): ResponseInterface
62
+	{
63
+		if ($this->module === null) {
64
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
+		}
66
+
67
+		$tree = Validator::attributes($request)->tree();
68
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
69
+
70
+		/** @var SosaStatisticsService $sosa_stats_service */
71
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72
+
73
+		return $this->viewResponse($this->module->name() . '::statistics-page', [
74
+			'module_name'       =>  $this->module->name(),
75
+			'title'             =>  I18N::translate('Sosa Statistics'),
76
+			'tree'              =>  $tree,
77
+			'theme'             =>  app(ModuleThemeInterface::class),
78
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
79
+			'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
80
+			'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
81
+			'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
82
+			'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
83
+			'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
84
+			'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
85
+			'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3),
86
+			'relationship_service'  =>  $this->relationship_service,
87
+		]);
88
+	}
89
+
90
+	/**
91
+	 * Retrieve and compute the global statistics of ancestors for the tree.
92
+	 * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
93
+	 *
94
+	 * @param SosaStatisticsService $sosa_stats_service
95
+	 * @return array<string, int|float>
96
+	 */
97
+	private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
98
+	{
99
+		$ancestors_count = $sosa_stats_service->totalAncestors();
100
+		$ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
101
+		$individual_count = $sosa_stats_service->totalIndividuals();
102
+
103
+		return [
104
+			'sosa_count'    =>  $ancestors_count,
105
+			'distinct_count'    =>  $ancestors_distinct_count,
106
+			'sosa_rate' =>  $this->safeDivision(
107
+				BigInteger::of($ancestors_distinct_count),
108
+				BigInteger::of($individual_count)
109
+			),
110
+			'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
111
+		];
112
+	}
113
+
114
+	/**
115
+	 * Retrieve and compute the statistics of ancestors by generations.
116
+	 * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
117
+	 *
118
+	 * @param SosaStatisticsService $sosa_stats_service
119
+	 * @return array<int, array<string, int|float>>
120
+	 */
121
+	private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
122
+	{
123
+		$stats_by_gen = $sosa_stats_service->statisticsByGenerations();
124
+
125
+		$generation_stats = array();
126
+
127
+		foreach ($stats_by_gen as $gen => $stats_gen) {
128
+			$gen_diff = $gen > 1 ?
129
+				(int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
+				1;
131
+			$generation_stats[$gen] = array(
132
+				'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
+				'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
134
+				'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
+				'known' => (int) $stats_gen['sosaCount'],
136
+				'perc_known' => $this->safeDivision(
137
+					BigInteger::of((int) $stats_gen['sosaCount']),
138
+					BigInteger::of(2)->power($gen - 1)
139
+				),
140
+				'missing' => $gen > 1 ?
141
+					2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
+					0,
143
+				'perc_missing' => $gen > 1 ?
144
+					1 - $this->safeDivision(
145
+						BigInteger::of((int) $stats_gen['sosaCount']),
146
+						BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
+					) :
148
+					0,
149
+				'total_known' => (int) $stats_gen['sosaTotalCount'],
150
+				'perc_total_known' => $this->safeDivision(
151
+					BigInteger::of((int) $stats_gen['sosaTotalCount']),
152
+					BigInteger::of(2)->power($gen)->minus(1)
153
+				),
154
+				'different' => $gen_diff,
155
+				'perc_different' => $this->safeDivision(
156
+					BigInteger::of($gen_diff),
157
+					BigInteger::of((int) $stats_gen['sosaCount'])
158
+				),
159
+				'total_different' => (int) $stats_gen['diffSosaTotalCount']
160
+			);
161
+		}
162
+
163
+		return $generation_stats;
164
+	}
165
+
166
+	/**
167
+	 * Return the result of a division, and a default value if denominator is 0
168
+	 *
169
+	 * @param BigInteger $p Numerator
170
+	 * @param BigInteger $q Denominator
171
+	 * @param int $scale Rounding scale
172
+	 * @param float $default Value if denominator is 0
173
+	 * @return float
174
+	 */
175
+	private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float
176
+	{
177
+		return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat();
178
+	}
179 179
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/AncestorsList.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -34,48 +34,48 @@
 block discarded – undo
34 34
  */
35 35
 class AncestorsList implements RequestHandlerInterface
36 36
 {
37
-    use ViewResponseTrait;
37
+	use ViewResponseTrait;
38 38
 
39
-    private ?SosaModule $module;
39
+	private ?SosaModule $module;
40 40
 
41
-    /**
42
-     * Constructor for AncestorsList Request Handler
43
-     *
44
-     * @param ModuleService $module_service
45
-     */
46
-    public function __construct(ModuleService $module_service)
47
-    {
48
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
49
-    }
41
+	/**
42
+	 * Constructor for AncestorsList Request Handler
43
+	 *
44
+	 * @param ModuleService $module_service
45
+	 */
46
+	public function __construct(ModuleService $module_service)
47
+	{
48
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
-     */
55
-    public function handle(ServerRequestInterface $request): ResponseInterface
56
-    {
57
-        if ($this->module === null) {
58
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
-        }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
+	 */
55
+	public function handle(ServerRequestInterface $request): ResponseInterface
56
+	{
57
+		if ($this->module === null) {
58
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
+		}
60 60
 
61
-        $tree = Validator::attributes($request)->tree();
62
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
61
+		$tree = Validator::attributes($request)->tree();
62
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
63 63
 
64
-        /** @var SosaStatisticsService $sosa_stats_service */
65
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
64
+		/** @var SosaStatisticsService $sosa_stats_service */
65
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
66 66
 
67
-        $current_gen = Validator::queryParams($request)->integer(
68
-            'gen',
69
-            Validator::attributes($request)->integer('gen', 0)
70
-        );
67
+		$current_gen = Validator::queryParams($request)->integer(
68
+			'gen',
69
+			Validator::attributes($request)->integer('gen', 0)
70
+		);
71 71
 
72
-        return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
73
-            'module_name'       =>  $this->module->name(),
74
-            'title'             =>  I18N::translate('Sosa Ancestors'),
75
-            'tree'              =>  $tree,
76
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
77
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
78
-            'current_gen'       =>  $current_gen
79
-        ]);
80
-    }
72
+		return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
73
+			'module_name'       =>  $this->module->name(),
74
+			'title'             =>  I18N::translate('Sosa Ancestors'),
75
+			'tree'              =>  $tree,
76
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
77
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
78
+			'current_gen'       =>  $current_gen
79
+		]);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/MissingAncestorsList.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -37,89 +37,89 @@
 block discarded – undo
37 37
  */
38 38
 class MissingAncestorsList implements RequestHandlerInterface
39 39
 {
40
-    use ViewResponseTrait;
41
-
42
-    /**
43
-     * @var SosaModule|null $module
44
-     */
45
-    private $module;
46
-
47
-    /**
48
-     * @var SosaRecordsService $sosa_record_service
49
-     */
50
-    private $sosa_record_service;
51
-
52
-    /**
53
-     * Constructor for MissingAncestorsList Request Handler
54
-     *
55
-     * @param ModuleService $module_service
56
-     * @param SosaRecordsService $sosa_record_service
57
-     */
58
-    public function __construct(
59
-        ModuleService $module_service,
60
-        SosaRecordsService $sosa_record_service
61
-    ) {
62
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
63
-        $this->sosa_record_service = $sosa_record_service;
64
-    }
65
-
66
-    /**
67
-     * {@inheritDoc}
68
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
-     */
70
-    public function handle(ServerRequestInterface $request): ResponseInterface
71
-    {
72
-        if ($this->module === null) {
73
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
-        }
75
-
76
-        $tree = Validator::attributes($request)->tree();
77
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
78
-
79
-        /** @var SosaStatisticsService $sosa_stats_service */
80
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81
-
82
-        $current_gen =  Validator::queryParams($request)->integer(
83
-            'gen',
84
-            Validator::attributes($request)->integer('gen', 0)
85
-        );
86
-
87
-        $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
89
-            return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90
-        });
91
-
92
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
93
-            $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
-            if ($indi !== null && $indi->canShowName()) {
95
-                return new MissingAncestor(
96
-                    $indi,
97
-                    (int) $value->majs_sosa,
98
-                    $value->majs_fat_id === null,
99
-                    $value->majs_mot_id === null
100
-                );
101
-            }
102
-            return null;
103
-        })->filter();
104
-
105
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
106
-            return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107
-        });
108
-
109
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
110
-            'module_name'       =>  $this->module->name(),
111
-            'title'             =>  I18N::translate('Missing Ancestors'),
112
-            'tree'              =>  $tree,
113
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
114
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
115
-            'current_gen'       =>  $current_gen,
116
-            'list_missing'      =>  $list_missing,
117
-            'nb_missing_diff'   =>  $nb_missing_diff,
118
-            'nb_missing_shown'  =>  $nb_missing_shown,
119
-            'gen_completeness'  =>
120
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
121
-            'gen_potential'     =>
122
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
123
-        ]);
124
-    }
40
+	use ViewResponseTrait;
41
+
42
+	/**
43
+	 * @var SosaModule|null $module
44
+	 */
45
+	private $module;
46
+
47
+	/**
48
+	 * @var SosaRecordsService $sosa_record_service
49
+	 */
50
+	private $sosa_record_service;
51
+
52
+	/**
53
+	 * Constructor for MissingAncestorsList Request Handler
54
+	 *
55
+	 * @param ModuleService $module_service
56
+	 * @param SosaRecordsService $sosa_record_service
57
+	 */
58
+	public function __construct(
59
+		ModuleService $module_service,
60
+		SosaRecordsService $sosa_record_service
61
+	) {
62
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
63
+		$this->sosa_record_service = $sosa_record_service;
64
+	}
65
+
66
+	/**
67
+	 * {@inheritDoc}
68
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
+	 */
70
+	public function handle(ServerRequestInterface $request): ResponseInterface
71
+	{
72
+		if ($this->module === null) {
73
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
+		}
75
+
76
+		$tree = Validator::attributes($request)->tree();
77
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
78
+
79
+		/** @var SosaStatisticsService $sosa_stats_service */
80
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81
+
82
+		$current_gen =  Validator::queryParams($request)->integer(
83
+			'gen',
84
+			Validator::attributes($request)->integer('gen', 0)
85
+		);
86
+
87
+		$list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
+		$nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
89
+			return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90
+		});
91
+
92
+		$list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
93
+			$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
+			if ($indi !== null && $indi->canShowName()) {
95
+				return new MissingAncestor(
96
+					$indi,
97
+					(int) $value->majs_sosa,
98
+					$value->majs_fat_id === null,
99
+					$value->majs_mot_id === null
100
+				);
101
+			}
102
+			return null;
103
+		})->filter();
104
+
105
+		$nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
106
+			return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107
+		});
108
+
109
+		return $this->viewResponse($this->module->name() . '::list-missing-page', [
110
+			'module_name'       =>  $this->module->name(),
111
+			'title'             =>  I18N::translate('Missing Ancestors'),
112
+			'tree'              =>  $tree,
113
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
114
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
115
+			'current_gen'       =>  $current_gen,
116
+			'list_missing'      =>  $list_missing,
117
+			'nb_missing_diff'   =>  $nb_missing_diff,
118
+			'nb_missing_shown'  =>  $nb_missing_shown,
119
+			'gen_completeness'  =>
120
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
121
+			'gen_potential'     =>
122
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
123
+		]);
124
+	}
125 125
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/SosaMissingDatatablesExtenderCollector.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
  * @extends AbstractHookCollector<SosaMissingDatatablesExtenderInterface>
26 26
  */
27 27
 class SosaMissingDatatablesExtenderCollector extends AbstractHookCollector implements
28
-    SosaMissingDatatablesExtenderInterface
28
+	SosaMissingDatatablesExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Columns extender for tables of missing ancestors');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Columns extender for tables of missing ancestors');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Add additional columns to tables of missing ancestors');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Add additional columns to tables of missing ancestors');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return SosaMissingDatatablesExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return SosaMissingDatatablesExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns()
60
-     */
61
-    public function sosaMissingColumns(iterable $records): array
62
-    {
63
-        $result = [];
64
-        foreach ($this->hooks() as $hook) {
65
-            $result += $hook->sosaMissingColumns($records);
66
-        }
67
-        return $result;
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns()
60
+	 */
61
+	public function sosaMissingColumns(iterable $records): array
62
+	{
63
+		$result = [];
64
+		foreach ($this->hooks() as $hook) {
65
+			$result += $hook->sosaMissingColumns($records);
66
+		}
67
+		return $result;
68
+	}
69 69
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/SosaFamilyDatatablesExtenderCollector.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
  * @extends AbstractHookCollector<SosaFamilyDatatablesExtenderInterface>
26 26
  */
27 27
 class SosaFamilyDatatablesExtenderCollector extends AbstractHookCollector implements
28
-    SosaFamilyDatatablesExtenderInterface
28
+	SosaFamilyDatatablesExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Columns extender for tables of ancestors’ families');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Columns extender for tables of ancestors’ families');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Add additional columns to tables of ancestors’ families');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Add additional columns to tables of ancestors’ families');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return SosaFamilyDatatablesExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return SosaFamilyDatatablesExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaFamilyDatatablesExtenderInterface::sosaFamilyColumns()
60
-     */
61
-    public function sosaFamilyColumns(iterable $records): array
62
-    {
63
-        $result = [];
64
-        foreach ($this->hooks() as $hook) {
65
-            $result += $hook->sosaFamilyColumns($records);
66
-        }
67
-        return $result;
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaFamilyDatatablesExtenderInterface::sosaFamilyColumns()
60
+	 */
61
+	public function sosaFamilyColumns(iterable $records): array
62
+	{
63
+		$result = [];
64
+		foreach ($this->hooks() as $hook) {
65
+			$result += $hook->sosaFamilyColumns($records);
66
+		}
67
+		return $result;
68
+	}
69 69
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/SosaIndividualDatatablesExtenderCollector.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
  * @extends AbstractHookCollector<SosaIndividualDatatablesExtenderInterface>
26 26
  */
27 27
 class SosaIndividualDatatablesExtenderCollector extends AbstractHookCollector implements
28
-    SosaIndividualDatatablesExtenderInterface
28
+	SosaIndividualDatatablesExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Columns extender for tables of ancestors');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Columns extender for tables of ancestors');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Add additional columns to tables of ancestors');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Add additional columns to tables of ancestors');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return SosaIndividualDatatablesExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return SosaIndividualDatatablesExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaIndividualDatatablesExtenderInterface::sosaIndividualColumns()
60
-     */
61
-    public function sosaIndividualColumns(iterable $records): array
62
-    {
63
-        $result = [];
64
-        foreach ($this->hooks() as $hook) {
65
-            $result += $hook->sosaIndividualColumns($records);
66
-        }
67
-        return $result;
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaIndividualDatatablesExtenderInterface::sosaIndividualColumns()
60
+	 */
61
+	public function sosaIndividualColumns(iterable $records): array
62
+	{
63
+		$result = [];
64
+		foreach ($this->hooks() as $hook) {
65
+			$result += $hook->sosaIndividualColumns($records);
66
+		}
67
+		return $result;
68
+	}
69 69
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/FactSourceTextExtenderCollector.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -27,56 +27,56 @@
 block discarded – undo
27 27
  */
28 28
 class FactSourceTextExtenderCollector extends AbstractHookCollector implements FactSourceTextExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Text extender for source citations’ title');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Text extender for source citations’ title');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Extends the title of source citations with additional text or icons.');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Extends the title of source citations with additional text or icons.');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return FactSourceTextExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return FactSourceTextExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend()
60
-     */
61
-    public function factSourcePrepend(Tree $tree, $fact): string
62
-    {
63
-        return $this->hooks()
64
-            ->map(
65
-                fn(FactSourceTextExtenderInterface $hook) =>
66
-                    $hook->factSourcePrepend($tree, $fact)
67
-            )->implode('');
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend()
60
+	 */
61
+	public function factSourcePrepend(Tree $tree, $fact): string
62
+	{
63
+		return $this->hooks()
64
+			->map(
65
+				fn(FactSourceTextExtenderInterface $hook) =>
66
+					$hook->factSourcePrepend($tree, $fact)
67
+			)->implode('');
68
+	}
69 69
 
70
-    /**
71
-     * {@inheritDoc}
72
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend()
73
-     */
74
-    public function factSourceAppend(Tree $tree, $fact): string
75
-    {
76
-        return $this->hooks()
77
-            ->map(
78
-                fn(FactSourceTextExtenderInterface $hook) =>
79
-                    $hook->factSourcePrepend($tree, $fact)
80
-            )->implode('');
81
-    }
70
+	/**
71
+	 * {@inheritDoc}
72
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend()
73
+	 */
74
+	public function factSourceAppend(Tree $tree, $fact): string
75
+	{
76
+		return $this->hooks()
77
+			->map(
78
+				fn(FactSourceTextExtenderInterface $hook) =>
79
+					$hook->factSourcePrepend($tree, $fact)
80
+			)->implode('');
81
+	}
82 82
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/FamilyDatatablesExtenderCollector.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
  * @extends AbstractHookCollector<FamilyDatatablesExtenderInterface>
26 26
  */
27 27
 class FamilyDatatablesExtenderCollector extends AbstractHookCollector implements
28
-    FamilyDatatablesExtenderInterface
28
+	FamilyDatatablesExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Columns extender for tables of families');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Columns extender for tables of families');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Add additional columns to tables of families');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Add additional columns to tables of families');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return FamilyDatatablesExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return FamilyDatatablesExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\FamilyDatatablesExtenderInterface::familyColumns()
60
-     */
61
-    public function familyColumns(iterable $records): array
62
-    {
63
-        $result = [];
64
-        foreach ($this->hooks() as $hook) {
65
-            $result += $hook->familyColumns($records);
66
-        }
67
-        return $result;
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\FamilyDatatablesExtenderInterface::familyColumns()
60
+	 */
61
+	public function familyColumns(iterable $records): array
62
+	{
63
+		$result = [];
64
+		foreach ($this->hooks() as $hook) {
65
+			$result += $hook->familyColumns($records);
66
+		}
67
+		return $result;
68
+	}
69 69
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/IndividualDatatablesExtenderCollector.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
  * @extends AbstractHookCollector<IndividualDatatablesExtenderInterface>
26 26
  */
27 27
 class IndividualDatatablesExtenderCollector extends AbstractHookCollector implements
28
-    IndividualDatatablesExtenderInterface
28
+	IndividualDatatablesExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Columns extender for tables of individuals');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Columns extender for tables of individuals');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Add additional columns to tables of individuals');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Add additional columns to tables of individuals');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return IndividualDatatablesExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return IndividualDatatablesExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\IndividualDatatablesExtenderInterface::individualColumns()
60
-     */
61
-    public function individualColumns(iterable $records): array
62
-    {
63
-        $result = [];
64
-        foreach ($this->hooks() as $hook) {
65
-            $result += $hook->individualColumns($records);
66
-        }
67
-        return $result;
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\IndividualDatatablesExtenderInterface::individualColumns()
60
+	 */
61
+	public function individualColumns(iterable $records): array
62
+	{
63
+		$result = [];
64
+		foreach ($this->hooks() as $hook) {
65
+			$result += $hook->individualColumns($records);
66
+		}
67
+		return $result;
68
+	}
69 69
 }
Please login to merge, or discard this patch.