Marvel Database
Advertisement

/* Marvel Heroes and Villains

Based on the website http://marvel.wikia.com/Main_Page
with popularity data from http://observationdeck.io9.com/something-i-found-marvel-character-popularity-poll-cb-1568108064 
and power grid data from http://marvel.wikia.com/Power_Grid#Power
Collected by: https://www.khanacademy.org/profile/Mentrasto/
*/

CREATE TABLE marvels (ID INTEGER PRIMARY KEY,

   name TEXT,
   popularity INTEGER,
   alignment TEXT,
   gender TEXT, 
   height_m NUMERIC,
   weight_kg NUMERIC,
   hometown TEXT,
   intelligence INTEGER,
   strength INTEGER,
   speed INTEGER,
   durability INTEGER,
   energy_Projection INTEGER,
   fighting_Skills INTEGER);

INSERT INTO marvels VALUES(1,Hermes, Good, 1.80, 235.50, Olympus, 4, 5, 7, 3, 1, 5);

Insert INTO marvels Value(2,Artemis,Good,1.75,190.70,Olympus, 3, 5, 3, 6, 5);

Insert INTO marvels Values(3,Apollo, Good, 1.83, 235.50, Olympus, 3, 5, 4, 3, 6, 3);

Insert INTO marvels Values(4,Aphrodite, Good, 1.68.30, 172.60, Olympus, 3, 4, 3, 3, 6, 1);

INSERT INTO marvels values(5,Persephone, Good, 1.75,185.70,' 'Olympus' ', 3, 4, 2, 3, 6, 1);


local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs
local labels = {'Intelligence', 'Strength', 'Speed', 'Durability', 'Energy Projection', 'Fighting Skills'}
local description = mw.loadData('Module:Power Grid/Description')
local list_of_power_grids = mw.loadData('Module:Power Grid/List')

--------------------------------------------------------------------------------
function p.main(pagename)
	local caption = 'Power Grid'
	local info = list_of_power_grids[pagename]
	local i
	local value
	local category
	local list = {}
	local PlotData = {}
	local output_categories = {}
	local output = ''

	if  info ~= nil
		then
			output = {}
			table.insert(output_categories, 'Power Grid Added')

			table.insert(output, 'ImageSize = width:350 height:250')
			table.insert(output, 'Period = from:0 till:7')
			table.insert(output, 'AlignBars  = justify')
			table.insert(output, 'TimeAxis = orientation:horizontal format:yyyy')
			table.insert(output, 'PlotArea = left:100 bottom:80 top:0 right:10')
			if info[8] ~= nil or info[9] ~= nil or info[10] ~= nil or info[11] ~= nil or info[12] ~= nil or info[13] ~= nil or info[14] ~= nil
				then table.insert(output, 'Legend = orientation:vertical left:20 top:70')
			end
			table.insert(output, 'BarData =')
			for i = 1, 6 do
				table.insert(output, ' bar:bar'..i..'  text:"'..labels[i]..'"')
			end

			table.insert(output, 'Colors =')
			for i = 1,6 do
				table.insert(output, p.get_color(i, info[i+7]))
			end

			value, category = p.get_TextData(info)
			output = h.join_tables(output, value)
			output_categories = h.join_tables(output_categories, category)
			
			value, category = p.get_PlotData(info)
			output = h.join_tables(output, value)
			output_categories = h.join_tables(output_categories, category)

			output = '<timeline>'..mw.text.listToText(output, '\n', '\n')..'</timeline>'

			value = info[7]
			if value ~= nil
				then 
					list = h.explode('@@@', value)
					for i = 1, #list do
						value = list[i]
						if h.exists(value)
							then value = h.Link(value)
						end
						caption = caption..'<ref>'..value..'</ref>'
					end
					table.insert(output_categories, 'Power Grid Complete')
				else 
					table.insert(output_categories, 'Power Grid Reference Needed')
			end
			
			caption = mw.html.create('caption')
						:css('font-weight', 'bold')
						:wikitext(caption)
			caption = tostring(caption)

			output = mw.html.create('table')
					:attr('align', 'right')
					:css('border', '1px solid gray')
					:wikitext(caption..'<tr><td>'..output..'</td></tr>')
	end
	
	return tostring(output), output_categories
end


--------------------------------------------------------------------------------
function p.get_color(n, legend)
	local colors = {'rgb(0.663, 0.663, 0.663)', -- darkgray 
					'rgb(0.118, 0.565, 1)', -- dodgerblue
					'rgb(1,     0.388, 0.278)', -- tomato
					'rgb(0.235, 0.702, 0.443)', -- mediumseagreen
					'rgb(1,     0.647, 0)', -- orange
					'rgb(0.535,0.484,0.844)', -- Moody Blue 
					'rgb(0.933,0.509,0.933)', -- violet
		}
	local output = ' id:color'..n..' value:'..colors[n]
	
	if not h.isempty(legend)
		then output = output..' legend:'..string.gsub(legend, ' ', '_')
	end
	
	return output
end


--------------------------------------------------------------------------------
function p.get_text_and_category(row_number, value)
	local hor = {'115', '149', '183', '216', '250', '286', '319'}
	local ver = {'233', '204', '176', '146', '116', '87'}
	local category = ''
	local output = ''
	
	if value ~= 0
		then
			category = description[row_number].values[value].category
			output = ' pos:('..hor[value]..', '..ver[row_number]..') text:'
			output = output..'"'..h.LinkToCategory(category, value)..'"'
	end
	
	return output, category
end


--------------------------------------------------------------------------------
function p.get_values(value)
	local i
	local values = {}
	local output = {}
	
	if string.find(value, '-') == nil
		then output = {tonumber(value), 0, 0, 0, 0, 0}
		else
			values = mw.text.split(value, '-')
			for i = 1, 6 do
				table.insert(output, tonumber(values[i]) or 0 )
			end
	end

	return output
end


--------------------------------------------------------------------------------
function p.get_TextData(info)
	local values = {}
	local value
	local category
	local i
	local j
	local output_categories = {}
	local output = {}
	
	table.insert(output, 'TextData =')
	for i = 1, 6 do
		values = p.get_values(info[i])
		for j = 1, 6 do
			value, category = p.get_text_and_category(i, values[j])
			table.insert(output_categories, category)
			table.insert(output, value)
		end
	end
	
	return output, output_categories
end


--------------------------------------------------------------------------------
function p.get_PlotData(info)
	local function sort(a, b)
		return a[1] > b[1]
	end
	local values = {}
	local i
	local j
	local PlotData = {}
	local output = {}
	
	table.insert(output, 'PlotData =')
	for i = 1,6 do
		values = p.get_values(info[i])
		PlotData = {}
		for j = 1, 6 do
			if values[j] ~= 0
				then table.insert(PlotData, {values[j], ' bar:bar'..i..' from:0 till:'..values[j]..' color:color'..j})
			end
		end
		table.sort(PlotData, sort)
		for j = 1, #PlotData do
			table.insert(output, PlotData[j][2])
		end
	end

	return output
end

return p
Advertisement