Module:Demographics Basics

function total_table(table,country) local temp = 0 if table[country] == nil then return 0 elseif table[country] == 0 then return 0 else for i in pairs(table[country]) do temp=temp+table[country][i] end return temp end end

function fetch_table(table,country,race) if table[country] == nil then return 0 elseif table[country] == 0 then return 0 end if table[country][race] == nil then return 0 elseif table[country][race] == 0 then return 0 else return table[country][race] end end

function generate(table,country,type) local totalled=total_table(table,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;\" | Amount\n! style=\"text-align: center; font-weight: bold;\" | Percentage\n" for key,value in orderedPairs(table[country]) do       if table[country][key] ~= nil and table[country][key] ~= 0 then Base = Base .. "|-\n| style=\"text-align: center;\" | " .. key .. "\n" 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