Module:Demographics Hun

require "Module:FormatNum" require "Module:OrderedPairs" require "Module:SortedKeys" require "Module:Compare" require "Module:Demographics Basics"

demographics.HunTrans = {}

function hun_trans(pop) return (pop .. "/hu|" .. demographics.HunTrans[pop]) end

function hun_convert(tabule,country) temp = {} for key,value in pairs(tabule[country]) do		temp[hun_trans(key)] = value end return temp end

function hun_generate(tabule,country,type) local totalled=total_table(tabule,country) local temp = hun_convert(tabule,country) local Base= "{| class=\"sortable wikitable\" style=\"background:white;\"\n! style=\"text-align: center; font-weight: bold;\" | " .. type .."\n! style=\"text-align: center; font-weight: bold;\" | Létszám\n! style=\"text-align: center; font-weight: bold;\" | Százalék\n" table.sort(temp,compare) for key,value in pairs(temp) do       if temp[key] ~= nil and temp[key] ~= 0 then if key ~= "O" and key ~= "Other" then Base = Base .. "|-\n| style=\"text-align: center;\" | " .. key .. "\n" else Base = Base .. "|-\n| style=\"text-align: center;\" | " .. "Egyéb" .. "\n" end Base = Base .. "| style=\"text-align: center;\" | " .. format_num(value,0) .. "\n" Base = Base .. "| style=\"text-align: center;\" | " .. (math.ceil(value/totalled*10000))/100 .. "%\n" end end Base = Base .. "|}"   return Base end

function hun_generate_historical(tabule,country,type) local Origin = {} local i = 1 for key,value in pairs(tabule[country]) do		Origin[i] = tabule[country][key] Origin[i]["OrgKey"] = tonumber(key) i = i + 1 end table.sort(Origin, function(a,b) return a["OrgKey"]<b["OrgKey"] end) local Base= "{| class=\"sortable wikitable\"\n! style=\"text-align: center; font-weight: bold;\" | Év\n! style=\"text-align: center; font-weight: bold;\" | Népesség\n! style=\"text-align: center; font-weight: bold;\" | ±%\n! style=\"text-align: center; font-weight: bold;\" | Megjegyzés\n|-\n" for key,value in pairs(Origin) do		if Origin[key] ~= nil and Origin[key] ~= 0 then Base = Base .. "|-\n" Base = Base .. "| style=\"text-align: center; font-weight: bold;\" |" .. Origin[key]["OrgKey"] .. "\n" Base = Base .. "| style=\"text-align: center;\" |" .. format_num(Origin[key][1],0) .. "\n" if key == 1 then Base = Base .. "| style=\"text-align: center;\" |" .. "-" .. "\n" else Base = Base .. "| style=\"text-align: center;\" |" .. Compare(Origin[key][1],Origin[key-1][1],true) .. "\n" end if Origin[key][2] ~= nil and Origin[key][2] ~= 0 then Base = Base .. "| style=\"text-align: center;\" |" .. Origin[key][2] .. "\n" else Base = Base .. "| style=\"text-align: center;\" | \n" end end end Base = Base .. "|}"	return Base end