|
740 | 740 |
|
741 | 741 | function findSimilarGdpMedalCountry(country) { |
742 | 742 | const base = getCountryIndicators(country); |
743 | | - if (!base.gdp) return null; |
| 743 | + if (!base.gdp && !base.population) return null; |
744 | 744 |
|
745 | 745 | const countries = getAvailableCountries(state.season, state.year); |
746 | 746 |
|
|
753 | 753 | if (totalMedals === 0) return null; |
754 | 754 |
|
755 | 755 | const indicators = getCountryIndicators(candidate); |
756 | | - if (!indicators.gdp) return null; |
757 | 756 |
|
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 }; |
762 | 772 | }) |
763 | 773 | .filter(Boolean) |
764 | 774 | .sort((a, b) => d3.ascending(a.distance, b.distance)); |
|
861 | 871 | ${data.similarCountry ? ` |
862 | 872 | <div class="fair-warning fair-warning--lg"> |
863 | 873 | 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. |
865 | 875 | </div> |
866 | 876 | ` : medalOrder.map(medal => { |
867 | 877 | const value = data.actual[medal] || 0; |
|
0 commit comments