Introduction
Introduction
The basic idea is to compare medal-winning relative to various measurements of "size" of countries in the 2024 Paris Olympics.
Wolfram is surprisingly not very robust at mapping IOC country codes to country entities. I am sorry to say it. I am surprised, too. The Olympics have been going on for some while since `CountryData[]` and Wolfram Alpha have been around. I would think by now it would be easy-peasy to submit an IOC three-letter code and get the country. Perhaps it is, but I failed to find an easy way. Please enlighten me if you can.
I was also surprised to find it so difficult to get complete medal tallies. Well, maybe not so surprised. My internet-scraping skills are pretty bad. I found one source on Kaggle. You'll need a (free) account to keep the data up-to-date. I'll use the date as of 4 Aug 2024.
Country code mapping
Country code mapping
There are many sources for country codes. The site olympics.com is not one of them, apparently. Go figure.
In[]:=
countrycodes=Import["https://apps.who.int/gho/athena/data/xmart.csv?target=COUNTRY&profile=xmart","Dataset",HeaderLines->1];
In[]:=
iocToEntity=Quiet[Join[Association@Map[#ISO->Check[CountryData[#ISO],CountryData[StringTrim@StringDelete[#DisplayString,"("~~___~~")"]]]&,Rest@Normal@countrycodes],Association@Map[If[#IOC=!="",#IOC->Check[CountryData[#ISO],Check[CountryData[StringTrim@StringDelete[#DisplayString,"("~~___~~")"]],Replace[Echo@WolframAlpha["country "<>#IOC//Echo,"WolframResult"],{e_Entity}:>e]]],Nothing]&,Rest@Normal@countrycodes],<|"TPE"->CountryData["Taiwan"]|>],CountryData::notent];
»
country MGO
»
Missing[NoResult]
»
country PSE
»
I ignore MGO (Montenegro).
Medal tallies
Medal tallies
I used the data at https://www.kaggle.com/datasets/piterfm/paris-2024-olympic-summer-games?resource=download&select=medals_total.csvIt is freely available under the license https://creativecommons.org/licenses/by-nc-sa/4.0/You will need to create an otherwise-free account at kaggle.com if you want to keep your data up-to-date. (I don't consider it "free access" to be required to provide bits of my data to gain access; however, you do not have to pay any money.)
Here is the data as of 04-Aug-2024:
In[]:=
medaldata={{"country_code","Gold Medal","Silver Medal","Bronze Medal","Total"},{"USA",19,26,26,71},{"CHN",19,15,11,45},{"FRA",12,14,18,44},{"AUS",12,11,8,31},{"GBR",10,12,15,37},{"KOR",10,7,7,24},{"JPN",9,5,10,24},{"ITA",7,10,5,22},{"NED",6,5,4,15},{"CAN",5,4,8,17},{"GER",5,4,2,11},{"HUN",3,3,2,8},{"ROU",3,3,1,7},{"IRL",3,0,3,6},{"NZL",2,4,1,7},{"SWE",2,3,2,7},{"UKR",2,1,3,6},{"CRO",2,1,1,4},{"BEL",2,0,3,5},{"HKG",2,0,2,4},{"AZE",2,0,0,2},{"PHI",2,0,0,2},{"SRB",2,0,0,2},{"BRA",1,4,5,10},{"ISR",1,4,1,6},{"AIN",1,3,0,4},{"ESP",1,2,5,8},{"GEO",1,2,1,4},{"SUI",1,1,4,6},{"KAZ",1,1,2,4},{"RSA",1,1,2,4},{"TPE",1,0,2,3},{"UZB",1,0,2,3},{"CZE",1,0,1,2},{"GUA",1,0,1,2},{"ALG",1,0,0,1},{"ARG",1,0,0,1},{"CHI",1,0,0,1},{"DMA",1,0,0,1},{"ECU",1,0,0,1},{"LCA",1,0,0,1},{"SLO",1,0,0,1},{"UGA",1,0,0,1},{"JAM",0,2,1,3},{"MEX",0,2,1,3},{"PRK",0,2,1,3},{"GRE",0,1,4,5},{"POL",0,1,3,4},{"KOS",0,1,1,2},{"TUR",0,1,1,2},{"ARM",0,1,0,1},{"DEN",0,1,0,1},{"ETH",0,1,0,1},{"FIJ",0,1,0,1},{"MGL",0,1,0,1},{"TUN",0,1,0,1},{"IND",0,0,3,3},{"TJK",0,0,3,3},{"DOM",0,0,2,2},{"MDA",0,0,2,2},{"AUT",0,0,1,1},{"CPV",0,0,1,1},{"CUB",0,0,1,1},{"EGY",0,0,1,1},{"LTU",0,0,1,1},{"MAS",0,0,1,1},{"POR",0,0,1,1},{"SVK",0,0,1,1}};
And here is an interactive dataset that is sorted in descending order, according to user-selected criteria: medal category relative to various measurements of the size of the country. There many measurements available through CountryData[]. I selected only a few. The quantity of arable land seemed to me to signify the inherent capacity of a country to feed its athletes, and athletes need a lot of food! Well, perhaps some countries have the capacity to import a lot food to make for a deficiency in arable land. Anyway, add whatever measurements tickle your fancy!
medalassoc=#[[1]]AssociationThread[Rest@medaldata[[1]]Rest@#]&/@Rest@medaldata//Association;DynamicModule[{column="Total",divisor="Population",scale=10^6},Panel[Column[{Row[{"Sort by: ",SetterBar[Dynamic@column,Keys[medalassoc[[1]]]]}],Row[{"Divide by: ",SetterBar[Dynamic@divisor,{None,"Population","GDP","ArableLandArea"}]}],Row[{"Scale by: ",SetterBar[Dynamic@scale,10^#HoldForm[10^#]&/@Range[0,12,3]]}],Dynamic[With[{cat=column},KeyValueMap[If[MissingQ[iocToEntity[#1]],Nothing,Tooltip[Style[iocToEntity[#1]["Name"],FontFamily"Source Sans Pro",13,ShowStringCharactersFalse],CountryData[iocToEntity[#1],divisor]]MapThread[Tooltip[#1,Row[{#2,If[#2==1," medal"," medals"]}]]&,{QuantityMagnitude[ If[scale==1&&divisor===None,scale,N@scale]#2/If[divisor===None,1,CountryData[iocToEntity[#1],divisor]]],#2}]]&,medalassoc]//Association//SortBy[-First@Slot[cat]&]//Dataset],TrackedSymbols{column,divisor,scale}]},BaseStyle{"Source Sans Pro",12}]]]
Caveat: The dynamic dataset sometimes aborts on wolframcloud.com. It behaves much better on my desktop (laptop) Mathematica.
It is not clear how to compare relative capacity. There are limitations on the number of entrants into the Olympics on each country. China and the US do not get to enter a number of athletes relative to their sizes. On the other hand, they do enter more athletes than much smaller countries. And they have much larger pools to draw from, making it more likely that they have athletes that can finish in the top three. Anyway, it's fun to see how things stack up with different relative measures.
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
Relative Olympic medal rankings
by Michael Rogers
Wolfram Community, STAFF PICKS, August 5, 2024
https://community.wolfram.com/groups/-/m/t/3240881
by Michael Rogers
Wolfram Community, STAFF PICKS, August 5, 2024
https://community.wolfram.com/groups/-/m/t/3240881