Difference between revisions of "Module:Mine Religion"

From Ways of Darkness
Jump to navigation Jump to search
 
Line 75: Line 75:
  
 
function generate_infobox_markup_hu(race,l)
 
function generate_infobox_markup_hu(race,l)
     local database = {}
+
    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 = {}
 
     local args = {}
 +
    args["population"] = "kb.  <b>" .. format_num(total,0) .. "</b>"
 
     local temp = ""
 
     local temp = ""
    database[race] = MineDatabase(demographics.religion(),race)
 
    local total = total_table(database,race)
 
    args["population"] = "c.  <b>" .. format_num(total,0) .. "</b>"
 
    local sortedKeys = getKeysSortedByValue(database[race], function(a, b) return a > b end)
 
 
     local i = l
 
     local i = l
 
     for _, key in ipairs(sortedKeys) do
 
     for _, key in ipairs(sortedKeys) do
Line 87: Line 92:
 
         args[temp]  = "{{CountryFlagThing/hu|" .. key .. "}}"
 
         args[temp]  = "{{CountryFlagThing/hu|" .. key .. "}}"
 
         temp = "pop" .. i
 
         temp = "pop" .. i
         args[temp] = "c. <b>" .. format_num(database[race][key],0) .. "</b>"
+
         args[temp] = "kb. <b>" .. format_num(database[key],0) .. "</b>"
 
         i = i + 1
 
         i = i + 1
 
     end
 
     end

Latest revision as of 17:55, 28 July 2020

Test:

  • {{#invoke:Mine Religion|main|Church of Titanius}}
  • CountryQuantityPercentage
    Etrand4,446,85057.99%
    Artaburro298,6003.89%
    Etrancoast476,9006.21%
    Froturn2,445,70031.89%

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 .. " = {{CountryFlagThing|" .. key .. "}}\n"
        temp = temp .. "|pop" .. i .. " = c. <b>" .. format_num(database[key],0) .. "</b>\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.  <b>" .. format_num(total,0) .. "</b>"
    local temp = ""
    local i = l
    for _, key in ipairs(sortedKeys) do
    	temp = "region" .. i
        args[temp]  = "{{CountryFlagThing|" .. key .. "}}"
        temp = "pop" .. i
        args[temp] = "c. <b>" .. format_num(database[key],0) .. "</b>"
        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.  <b>" .. format_num(total,0) .. "</b>"
    local temp = ""
    local i = l
    for _, key in ipairs(sortedKeys) do
    	temp = "region" .. i
        args[temp]  = "{{CountryFlagThing/hu|" .. key .. "}}"
        temp = "pop" .. i
        args[temp] = "kb. <b>" .. format_num(database[key],0) .. "</b>"
        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