Skip to content

Commit c2bddc3

Browse files
committed
Merge branch 'master' of github.com:com-480-data-visualization/DataRizz
2 parents 2123490 + 5bdbc83 commit c2bddc3

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

website/js/fair-distribution.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@
526526

527527
function findSimilarGdpMedalCountry(country) {
528528
const base = getCountryIndicators(country);
529-
if (!base.gdp && !base.population) return null;
529+
530+
const hasBaseGDP = Number.isFinite(base.gdp) && base.gdp > 0;
531+
const hasBasePopulation = Number.isFinite(base.population) && base.population > 0;
532+
533+
if (!hasBaseGDP && !hasBasePopulation) return null;
530534

531535
const countries = getAvailableCountries(state.season, state.year);
532536

@@ -540,21 +544,32 @@
540544

541545
const indicators = getCountryIndicators(candidate);
542546

547+
const hasCandidateGDP =
548+
Number.isFinite(indicators.gdp) && indicators.gdp > 0;
549+
550+
const hasCandidatePopulation =
551+
Number.isFinite(indicators.population) && indicators.population > 0;
552+
553+
// skip medal-winning countries that cannot be used for the fair formula
554+
if (!hasCandidateGDP || !hasCandidatePopulation) return null;
555+
543556
let distance = 0;
544557
let terms = 0;
545558

546-
if (base.gdp && indicators.gdp) {
559+
if (hasBaseGDP) {
547560
distance += Math.abs(Math.log(indicators.gdp) - Math.log(base.gdp));
548561
terms++;
549562
}
550-
if (base.population && indicators.population) {
563+
564+
if (hasBasePopulation) {
551565
distance += Math.abs(Math.log(indicators.population) - Math.log(base.population));
552566
terms++;
553567
}
554568

555-
if (terms === 0) return null;
556-
557-
return { country: candidate, distance: distance / terms };
569+
return {
570+
country: candidate,
571+
distance: distance / terms
572+
};
558573
})
559574
.filter(Boolean)
560575
.sort((a, b) => d3.ascending(a.distance, b.distance));

0 commit comments

Comments
 (0)