Module:Demographics Religion

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

function p.total(frame) local data = p.filterpops(0, 0, 0, 0, 0, frame.args[1], 0, 0) local total = 0 for k,v in pairs(data) do   	total = total + v['quantity'] end return total end function p.main(frame) local data = p.filterpops(0, frame.args[2], 0, 0, 0, frame.args[1], 0, 0) local total = 0 for k,v in pairs(data) do   	total = total + v['quantity'] end return total end function p.generate(frame) local function groupByReligion(pop) return pop['religion']['religionName'] end local groups = p.query(groupByReligion, 0, 0, 0, 0, 0, frame.args[1], 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( 'Religion' ):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 p.generate_bar(frame) local function groupByReligion(pop) return pop['religion']['religionName'] end local groups = p.query(groupByReligion, 0, 0, 0, 0, 0, frame.args[1], 0, 0) return generate_bar(groups,frame.args[2]) end return p