Skip to content

Commit

Permalink
Merge pull request #1271 from UN-OCHA/berliner/HPC-9988
Browse files Browse the repository at this point in the history
HPC-9988: Get the number of affected countries for the global key figures by counting the unique countries of GHO plans for a given year
  • Loading branch information
berliner authored Dec 20, 2024
2 parents c730ee7 + 6402d12 commit 8f8a81a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getData(string $source_key = 'data') {
'expectedReach' => 'Expected reach',
];
$caseload_values = $this->getPlanQuery()->getCaseloadTotalValues($types);
$affected_countries = $this->getPlanQuery()->getNumerOfGhoCountries();
return [
'total_funding' => $funding,
'total_requirements' => $requirements,
Expand All @@ -72,6 +73,7 @@ public function getData(string $source_key = 'data') {
'people_reached' => $caseload_values['reached'],
'people_reached_percent' => CommonHelper::calculateRatio($caseload_values['reached_custom'], $caseload_values['target_custom']),
'people_expected_reach' => $caseload_values['expectedReach'],
'countries_affected' => $affected_countries,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,44 @@ public function getPlans($filter = TRUE) {
return $this->plans;
}

/**
* Get the caseload total values for the supplied types.
*
* @return int
* The number of unique countries of all GHO plans.
*/
public function getNumerOfGhoCountries() {
// Get the plans, but make sure they are not filtered for visibility. The
// number of affected countries will appear only in the key figures
// element, where we want the number of countries for all GHO plans
// independently of whether specific plans are hidden from global pages or
// not.
$plans = $this->getPlans(FALSE);
if (empty($plans)) {
return 0;
}

$countries = [];
foreach ($plans as $plan) {
// Only include plans with isPartOfGho=true.
if (!$plan->isPartOfGho()) {
continue;
}
$plan_countries = $plan->getCountries();
if (empty($plan_countries)) {
continue;
}
foreach ($plan_countries as $plan_country) {
if (array_key_exists($plan_country->id(), $countries)) {
continue;
}
$countries[$plan_country->id()] = $plan_country;
}
}

return count($countries);
}

/**
* Get the caseload total values for the supplied types.
*
Expand Down

0 comments on commit 8f8a81a

Please sign in to comment.