Module:Mine Religion

require "Module:Database Miner" require "Module:Demographics Basics" require "Module:Demographics Database" require "Module:FormatNum" local p = require( 'Module:Demographics/PopQuery' )

function mineout(tabula,race) local function groupByCountry(pop) return pop['area']['region']['country']['countryName'] end local groups = p.query(groupByCountry, 0, race, 0, 0, 0, 0, 0, 0) local total = 0 for _,v in pairs(groups) do   	total = total + v    end local tab = mw.html.create( 'table' ) tab:addClass( 'wikitable sortable' ) tab:tag( 'tr' ) :tag( 'th' ):wikitext( 'Country' ):done :tag( 'th' ):wikitext( 'Quantity' ):done :tag( 'th' ):wikitext( 'Percentage' ):done

for i, row in pairs(groups) do		tab:tag( 'tr' ) :tag( 'td' ):wikitext( "" .. i .. "" ):done :tag( 'td' ):wikitext( format_num(row,0) ):done :tag( 'td' ):wikitext( (math.floor(row/total*10000) / 100) .. '%' ):done end return tab end

function generate_infobox_data(race,l) local function groupByCountry(pop) return pop['area']['region']['country']['countryName'] end local temp = "" local database = p.query(groupByCountry, 0, race, 0, 0, 0, 0, 0, 0) local total = 0 for k,v in pairs(database) do   total = total + v    end local sortedKeys = getKeysSortedByValue(database, function(a, b) return a > b end) local i = l   for _, key in ipairs(sortedKeys) do        temp = temp .. "|region" .. i .. " = \n" temp = temp .. "|pop" .. i .. " = c. '''" .. format_num(database[key],0) .. "'''\n" i = i + 1 end return temp end

function generate_infobox_markup(race,l) local function groupByCountry(pop) return pop['area']['region']['country']['countryName'] end local database = p.query(groupByCountry, 0, race, 0, 0, 0, 0, 0, 0) local sortedKeys = getKeysSortedByValue(database, function(a, b) return a > b end) local total = 0 for k,v in pairs(database) do   total = total + v    end local args = {} args["population"] = "c. '''" .. format_num(total,0) .. "'''"   local temp = "" local i = l   for _, key in ipairs(sortedKeys) do temp = "region" .. i       args[temp]  = "" temp = "pop" .. i       args[temp] = "c. '''" .. format_num(database[key],0) .. "'''"       i = i + 1 end return args end

function generate_infobox_markup_hu(race,l) local function groupByCountry(pop) return pop['area']['region']['country']['countryName'] end local database = p.query(groupByCountry, 0, race, 0, 0, 0, 0, 0, 0) local sortedKeys = getKeysSortedByValue(database, function(a, b) return a > b end) local total = 0 for k,v in pairs(database) do   total = total + v    end local args = {} args["population"] = "kb. '''" .. format_num(total,0) .. "'''"   local temp = "" local i = l   for _, key in ipairs(sortedKeys) do temp = "region" .. i       args[temp]  = "" temp = "pop" .. i       args[temp] = "kb. '''" .. format_num(database[key],0) .. "'''"       i = i + 1 end return args end

function p.main(frame) return mineout(demographics.religion,frame.args[1]) end function p.infobox(frame) return frame:expandTemplate{title = 'Infobox religious group',generate_infobox_markup(frame.args[1],frame.args[2])} end return p