Julia Pais Anal [cracked] -
# 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
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 julia pais anal
# ---- 2️⃣ Build the CountryInfo struct --------------------------- info = CountryInfo( get(data["name"], "common", "unknown"), get(data["name"], "official", "unknown"), get(data, "cca2", "??"), get(data, "cca3", "???"), get(data, "population", 0), get(data, "area", 0.0), get(data, "capital", String[]), get(data, "region", "unknown"), get(data, "subregion", "unknown"), languages_from_dict(get(data, "languages", Dict())), currencies_from_dict(get(data, "currencies", Dict())), get(data["flags"], "png", "") ) ( name = rpt.info.name
if resp.status != 200 error("Could not fetch data for \"$(name_or_code)\" (HTTP $(resp.status)).") end iso2 = rpt.info.iso2
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
return CountryReport(info, density, gdp_per_capita, econ_weight) end
Fetches basic data for the given country from the REST Countries API, computes population density, and (optionally) merges a GDP‑per‑capita value from a user‑provided `gdp_table`.