Skip to content

Commit c528ce5

Browse files
committed
fix: change the computation of fairness of non-winning countries to take into account both GDP and Population
1 parent b6c3d19 commit c528ce5

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

website/js/fair-distribution.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@
740740

741741
function findSimilarGdpMedalCountry(country) {
742742
const base = getCountryIndicators(country);
743-
if (!base.gdp) return null;
743+
if (!base.gdp && !base.population) return null;
744744

745745
const countries = getAvailableCountries(state.season, state.year);
746746

@@ -753,12 +753,22 @@
753753
if (totalMedals === 0) return null;
754754

755755
const indicators = getCountryIndicators(candidate);
756-
if (!indicators.gdp) return null;
757756

758-
return {
759-
country: candidate,
760-
distance: Math.abs(Math.log(indicators.gdp) - Math.log(base.gdp))
761-
};
757+
let distance = 0;
758+
let terms = 0;
759+
760+
if (base.gdp && indicators.gdp) {
761+
distance += Math.abs(Math.log(indicators.gdp) - Math.log(base.gdp));
762+
terms++;
763+
}
764+
if (base.population && indicators.population) {
765+
distance += Math.abs(Math.log(indicators.population) - Math.log(base.population));
766+
terms++;
767+
}
768+
769+
if (terms === 0) return null;
770+
771+
return { country: candidate, distance: distance / terms };
762772
})
763773
.filter(Boolean)
764774
.sort((a, b) => d3.ascending(a.distance, b.distance));
@@ -861,7 +871,7 @@
861871
${data.similarCountry ? `
862872
<div class="fair-warning fair-warning--lg">
863873
No medals for ${country}. Fair values are estimated from ${data.similarCountry},
864-
a medal-winning country with similar GDP.
874+
a medal-winning country with similar GDP and population.
865875
</div>
866876
` : medalOrder.map(medal => {
867877
const value = data.actual[medal] || 0;

0 commit comments

Comments
 (0)