Friday, March 6, 2026 • Welcome to the 100% Nonsense-Free Zone! • Log in
🛍️ Shop AMAZON! 🛒 Shop BEST BUY!

# ---- 3️⃣ Compute derived metrics -------------------------------- density = info.area_km2 > 0 ? info.population / info.area_km2 : missing

# ---------------------------------------------------------------- # 2️⃣ Helper functions # ---------------------------------------------------------------- # Turn a dictionary of languages (e.g. "spa"=>"Spanish") into a vector of strings. languages_from_dict(dict::Dict) = collect(values(dict))

Wraps a `CountryInfo` together with some derived metrics. """ struct CountryReport info::CountryInfo density::Float64 # pop / km² gdp_per_capita::UnionMissing,Float64 economic_weight::UnionMissing,Float64 end

Runs `analyze_country` on every element of `codes` and returns a DataFrame. """ function batch_analyze(codes::VectorString; gdp_table=nothing) rows = [] for c in codes try rpt = analyze_country(c; gdp_table=gdp_table) push!(rows, ( name = rpt.info.name, iso2 = rpt.info.iso2, iso3 = rpt.info.iso3, pop = rpt.info.population, area_km2 = rpt.info.area_km2, density = rpt.density, gdp_per_cap = rpt.gdp_per_capita, econ_weight = rpt.economic_weight )) catch e @warn "Failed for $c: $e" end end return DataFrame(rows) end

# Optional GDP integration gdp_per_capita = missing econ_weight = missing if gdp_table !== nothing if haskey(gdp_table, info.iso3) gdp_per_capita = gdp_table[info.iso3] econ_weight = gdp_per_capita * info.population else @warn "GDP per‑capita not found for ISO‑3 code $(info.iso3)." end end

Returns a `CountryReport`. """ function analyze_country(name_or_code::AbstractString; gdp_table=nothing) # ---- 1️⃣ Pull the JSON payload --------------------------------- url = "https://restcountries.com/v3.1/name/" * HTTP.escapeuri(name_or_code) resp = HTTP.get(url; timeout=15)

You can extend any of the steps (e.g., add more fields, plug in a different data source, or compute extra statistics). # -------------------------------------------------------------- # Country analysis feature for Julia # -------------------------------------------------------------- using HTTP using JSON3 using DataFrames # optional, only needed if you want tabular output using Statistics # for mean, median, etc. using Printf # for nice formatting

Light
Dark
🎯