Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #1271

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading