Module:DemographicsGenerator

-- Basis -- {| class="sortable wikitable" style="background:white;" -- ! style="text-align: center; font-weight: bold;" | Race -- ! style="text-align: center; font-weight: bold;" | Amount -- ! style="text-align: center; font-weight: bold;" | Percentage -- |- -- | style="text-align: center;" | Half-Elves -- | style="text-align: center;" | 0 -- | style="text-align: center;" | %

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

local p={} function p.generate(frame) local function groupByRace(pop) return pop['race']['raceName'] end local groups = querier.query(groupByRace, 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( 'Race' ):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 groupByRace(pop) return pop['race']['raceName'] end local groups = querier.query(groupByRace, 0, 0, 0, 0, 0, frame.args[1], 0, 0) return generate_bar(groups,frame.args[2]) end return p