Module:Demographics/Pops

From Ways of Darkness
Jump to navigation Jump to search

Documentation for this module may be created at Module:Demographics/Pops/doc

local pops_json = mw.title.new( 'Demographics/Pops.json', 'Module' )
local pops_data = mw.text.jsonDecode( pops_json:getContent() )
local religion_json = mw.title.new( 'Demographics/Religions.json', 'Module' )
local religion_data = mw.text.jsonDecode( religion_json:getContent() )
local races_json = mw.title.new( 'Demographics/Races.json', 'Module' )
local races_data = mw.text.jsonDecode( races_json:getContent() )
local occupations_json = mw.title.new( 'Demographics/Occupations.json', 'Module' )
local occupations_data = mw.text.jsonDecode( occupations_json:getContent() )
local agegroups_json = mw.title.new( 'Demographics/AgeGroups.json', 'Module' )
local agegroups_data = mw.text.jsonDecode( agegroups_json:getContent() )
local areas = require( 'Module:Demographics/Areas' )
local p = {}

for i, row in ipairs(pops_data['pops']) do
	if row['quantity'] > 0 then
	row['area'] = areas[row['areaID']]
	row['areaID'] = nil
	row['religion'] = religion_data['religions'][row['religionID']]
	row['religionID'] = nil
	row['race'] = races_data['races'][row['raceId']]
	row['raceId'] = nil
	row['occupation'] = occupations_data['occupations'][row['occupationID']]
	row['occupationID'] = nil
	row['agegroup'] = agegroups_data['agegroups'][row['agegroupID']]
	row['agegroupID'] = nil
	table.insert(p, row)
	end
end

return p
-- Don't forget to use this - http://www.convertcsv.com/csv-to-json.htm - to convert your tables to JSON, mkay?