Module:Mine Race

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, race, 0, 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 i = l   local database = p.query(groupByCountry, race, 0, 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 temp = temp .. "|population" .. " =c. '''" .. format_num(total) .. "'''\n" for _, key in ipairs(sortedKeys) do       temp = temp .. "|region" .. i .. " = \n" temp = temp .. "|pop" .. i .. " = c. '''" .. format_num(database[race][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, race, 0, 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 = {} local temp = "" args["population"] = "c. '''" .. format_num(total,0) .. "'''"   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 database = {} local args = {} local temp = "" database[race] = MineDatabase(demographics.race,race) local total = total_table(database,race) args["population"] = "c. '''" .. format_num(total,0) .. "'''"   local sortedKeys = getKeysSortedByValue(database[race], function(a, b) return a > b end) local i = l   for _, key in ipairs(sortedKeys) do temp = "region" .. i       args[temp]  = "" temp = "pop" .. i       args[temp] = "c. '''" .. format_num(database[race][key],0) .. "'''"       i = i + 1 end return args end function getTotal(race) local function groupByCountry(pop) return pop['area']['region']['country']['countryName'] end local database = p.query(groupByCountry, race, 0, 0, 0, 0, 0, 0, 0) local total = 0 for k,v in pairs(database) do   total = total + v    end return total end

local p = {} function p.main(frame) return mineout(demographics.race,frame.args[1]) end function p.total(frame) --return TotalMineDatabase(demographics.race,frame.args[1]) return getTotal(frame.args[1]) end function p.infobox(frame) return frame:expandTemplate{title = 'Infobox race',generate_infobox_markup(frame.args[1],frame.args[2])} end return p