No edit summary |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
local h = require("Module:HF") |
local h = require("Module:HF") |
||
− | local design = require('Module:Design') |
||
− | local standard = require('Module:StandardizedName') |
||
local getArgs = require('Dev:Arguments').getArgs |
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 description = mw.loadData('Module:Power Grid/Description') |
||
local list_of_power_grids = mw.loadData('Module:Power Grid/List') |
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 |
||
+ | |||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
Line 28: | Line 102: | ||
+ | -------------------------------------------------------------------------------- |
||
function p.get_text_and_category(row_number, value) |
function p.get_text_and_category(row_number, value) |
||
local hor = {'115', '149', '183', '216', '250', '286', '319'} |
local hor = {'115', '149', '183', '216', '250', '286', '319'} |
||
Line 45: | Line 120: | ||
+ | -------------------------------------------------------------------------------- |
||
function p.get_values(value) |
function p.get_values(value) |
||
local i |
local i |
||
Line 63: | Line 139: | ||
+ | -------------------------------------------------------------------------------- |
||
function p.get_TextData(info) |
function p.get_TextData(info) |
||
local values = {} |
local values = {} |
||
Line 86: | Line 163: | ||
+ | -------------------------------------------------------------------------------- |
||
function p.get_PlotData(info) |
function p.get_PlotData(info) |
||
local function sort(a, b) |
local function sort(a, b) |
||
Line 112: | Line 190: | ||
return output |
return output |
||
− | end |
||
− | |||
− | |||
− | function p.lua_main2(pagename) |
||
− | local caption = 'Power Grid' |
||
− | local info = list_of_power_grids[pagename] |
||
− | local explanation = '' |
||
− | local i |
||
− | local j |
||
− | local value |
||
− | local category |
||
− | local values = {} |
||
− | local PlotData = {} |
||
− | local output_categories = {} |
||
− | local output = {} |
||
− | |||
− | if info ~= nil |
||
− | then |
||
− | table.insert(output_categories, 'Power Grid Added') |
||
− | |||
− | --table.insert(output, '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..'|noerror}}') |
||
− | 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 |
||
− | then |
||
− | table.insert(output, 'Legend = orientation:vertical left:20 top:70') |
||
− | end |
||
− | table.insert(output, 'BarData =') |
||
− | table.insert(output, ' bar:bar1 text:"Intelligence"') |
||
− | table.insert(output, ' bar:bar2 text:"Strength"') |
||
− | table.insert(output, ' bar:bar3 text:"Speed"') |
||
− | table.insert(output, ' bar:bar4 text:"Durability"') |
||
− | table.insert(output, ' bar:bar5 text:"Energy Projection"') |
||
− | table.insert(output, ' bar:bar6 text:"Fighting Skills"') |
||
− | |||
− | 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) |
||
− | |||
− | value = info[7] |
||
− | if value ~= nil |
||
− | then |
||
− | if h.exists(value) |
||
− | then value = h.Link(value) |
||
− | end |
||
− | caption = caption..'<ref>'..value..'</ref>' |
||
− | table.insert(output_categories, 'Power Grid Complete') |
||
− | else |
||
− | table.insert(output_categories, 'Power Grid Reference Needed') |
||
− | end |
||
− | caption = mw.html.create('caption') |
||
− | :css('color', 'white') |
||
− | :css('background-color', 'gray') |
||
− | :css('font-weight', 'bold') |
||
− | :wikitext(caption) |
||
− | caption = tostring(caption) |
||
− | --[[ |
||
− | output = mw.html.create('table') |
||
− | :attr('align', 'right') |
||
− | :attr('cellspacing', '0') |
||
− | :attr('cellpadding', '0') |
||
− | :css('clear', 'both') |
||
− | --:css('background-color', 'white') |
||
− | :css('border', '1px solid gray') |
||
− | :wikitext(caption..'<timeline>'..table.concat(output)..'</timeline>'..explanation) |
||
− | ]]-- |
||
− | output = '<timeline>'..mw.text.listToText(output, '\n', '\n')..'</timeline>' |
||
− | end |
||
− | |||
− | return tostring(output), output_categories |
||
− | end |
||
− | |||
− | |||
− | -------------------------------------------------------------------------------- |
||
− | function p.lua_main(pagename) |
||
− | local caption = 'Power Grid' |
||
− | local info = list_of_power_grids[pagename] |
||
− | local explanation = '' |
||
− | local value |
||
− | local categories |
||
− | local output_categories = {} |
||
− | local output = {} |
||
− | |||
− | if info ~= nil |
||
− | then |
||
− | table.insert(output, '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..'|noerror}}') |
||
− | table.insert(output_categories, 'Power Grid Added') |
||
− | |||
− | for i = 1,6 do |
||
− | value, categories = p.add_tr(i, tostring(info[i]), info[8]) |
||
− | table.insert(output, value) |
||
− | output_categories = h.join_tables(output_categories, categories) |
||
− | end |
||
− | |||
− | if info[8] ~= nil |
||
− | then |
||
− | explanation = tostring(mw.html.create('td'):attr('colspan', '8'):css('width', '350px'):wikitext('* '..info[8])) |
||
− | explanation = tostring(mw.html.create('tr'):wikitext(explanation)) |
||
− | end |
||
− | |||
− | value = info[7] |
||
− | if value ~= nil |
||
− | then |
||
− | if h.exists(value) |
||
− | then value = h.Link(value) |
||
− | end |
||
− | caption = caption..'<ref>'..value..'</ref>' |
||
− | table.insert(output_categories, 'Power Grid Complete') |
||
− | else |
||
− | table.insert(output_categories, 'Power Grid Reference Needed') |
||
− | end |
||
− | caption = mw.html.create('caption') |
||
− | :css('color', 'white') |
||
− | :css('background-color', 'gray') |
||
− | :css('font-weight', 'bold') |
||
− | :wikitext(caption) |
||
− | caption = tostring(caption) |
||
− | |||
− | output = mw.html.create('table') |
||
− | :attr('align', 'right') |
||
− | :attr('cellspacing', '0') |
||
− | :attr('cellpadding', '0') |
||
− | :css('clear', 'both') |
||
− | --:css('background-color', 'white') |
||
− | :css('border', '1px solid gray') |
||
− | :wikitext(caption..table.concat(output)..explanation) |
||
− | end |
||
− | |||
− | return tostring(output), output_categories |
||
− | end |
||
− | |||
− | |||
− | function p.main2(frame) |
||
− | local args = getArgs (frame) |
||
− | local pagename = args.pagename or mw.title.getCurrentTitle().text |
||
− | local output_categories = {} |
||
− | local output = {} |
||
− | output, output_categories = p.lua_main(pagename) |
||
− | return frame:preprocess(output)..h.add_categories(output_categories) |
||
− | end |
||
− | |||
− | |||
− | |||
− | -------------------------------------------------------------------------------- |
||
− | -- used in Template:Official Power Grid |
||
− | function p.main(frame) |
||
− | local args = getArgs (frame) |
||
− | local pagename = mw.title.getCurrentTitle().subpageText |
||
− | local explanation = args.Explanation |
||
− | local reference = args.Reference |
||
− | local caption = 'Power Grid' |
||
− | local value |
||
− | local categories |
||
− | local output_categories = {} |
||
− | local output = {} |
||
− | |||
− | table.insert(output, '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..'|noerror}}') |
||
− | table.insert(output_categories, 'Power Grid Added') |
||
− | |||
− | for i = 1,6 do |
||
− | value, categories = p.add_tr(i, args[description[i].label], explanation) |
||
− | table.insert(output, value) |
||
− | output_categories = h.join_tables(output_categories, categories) |
||
− | end |
||
− | |||
− | if not h.isempty(explanation) |
||
− | then |
||
− | explanation = tostring(mw.html.create('td'):attr('colspan', '8'):css('width', '350px'):wikitext('* '..explanation)) |
||
− | explanation = tostring(mw.html.create('tr'):wikitext(explanation)) |
||
− | else |
||
− | explanation = '' |
||
− | end |
||
− | |||
− | if not h.isempty(reference) |
||
− | then |
||
− | caption = caption..'<ref>'..reference..'</ref>' |
||
− | table.insert(output_categories, 'Power Grid Complete') |
||
− | else |
||
− | table.insert(output_categories, 'Power Grid Reference Needed') |
||
− | end |
||
− | caption = mw.html.create('caption') |
||
− | :css('color', 'white') |
||
− | :css('background-color', 'gray') |
||
− | :css('font-weight', 'bold') |
||
− | :wikitext(caption) |
||
− | caption = tostring(caption) |
||
− | |||
− | output = mw.html.create('table') |
||
− | :attr('align', 'right') |
||
− | :attr('cellspacing', '0') |
||
− | :attr('cellpadding', '0') |
||
− | :css('clear', 'both') |
||
− | --:css('background-color', 'white') |
||
− | :css('border', '1px solid gray') |
||
− | :wikitext(caption..table.concat(output)..explanation) |
||
− | return frame:preprocess(tostring(output))..h.add_categories(output_categories) |
||
− | end |
||
− | |||
− | |||
− | -------------------------------------------------------------------------------- |
||
− | function p.add_tr(row_number, values, explanation) |
||
− | local label = design.lua_add_tooltip(description[row_number].label, description[row_number].tooltip) |
||
− | local output_categories = {} |
||
− | local output = {} |
||
− | |||
− | if string.find(values, '-', 1, true) ~= nil |
||
− | then |
||
− | output = mw.text.split(values, '-') |
||
− | for i = 1, #output do |
||
− | output[i] = tonumber(output[i]) |
||
− | end |
||
− | if explanation ~= nil |
||
− | then label = label .. '*' |
||
− | end |
||
− | else output = {tonumber(values)} |
||
− | end |
||
− | label = mw.html.create('td') |
||
− | :css('color', 'black') |
||
− | :css('text-align', 'left') |
||
− | :css('width', '140px') |
||
− | :css('padding', '0px 0px 0px 5px') |
||
− | :wikitext(label) |
||
− | label = tostring(label) |
||
− | output, output_categories = p.add_td(output, row_number) |
||
− | output = tostring( mw.html.create('tr'):wikitext( label..output ) ) |
||
− | |||
− | return output, output_categories |
||
− | end |
||
− | |||
− | |||
− | -------------------------------------------------------------------------------- |
||
− | function p.add_td(values, row_number) |
||
− | local function cell(text, color) |
||
− | return tostring(mw.html.create('td') |
||
− | :css('width', '30px') |
||
− | :css('text-align', 'center') |
||
− | :css('border-bottom', '1px solid gray') |
||
− | :css('background-color', color) |
||
− | :wikitext(text) |
||
− | ) |
||
− | end |
||
− | local function tooltip(value, row_number) |
||
− | local output = design.lua_add_tooltip(value, description[row_number].values[value].tooltip) |
||
− | return tostring( mw.html.create('span'):css('color', 'white'):wikitext(output) ) |
||
− | end |
||
− | --local colors = {'darkgray', 'dodgerblue', 'tomato', 'mediumseagreen', 'orange', 'mediumpurple'} |
||
− | --local colors = {'rgba(169, 169, 169, 1)', 'rgba(30, 144, 255, 1)', 'rgba(255, 99, 71, 1)', 'rgba(60, 179, 113, 1)', 'rgba(255, 165, 0, 1)', 'rgba(147, 112, 219, 1)'} |
||
− | local colors = {'#A9A9A9', '#1E90FF', '#FF6347', '#3CB371', '#FFA500', '#9370DB'} |
||
− | local i |
||
− | local j |
||
− | local value1 |
||
− | local value2 |
||
− | local category |
||
− | local filled = {false, false, false, false, false, false, false} |
||
− | local output_categories = {} |
||
− | local output = {'', '', '', '', '', '', ''} |
||
− | |||
− | for i = 1,7 do |
||
− | output[i] = cell('', 'transparent') |
||
− | end |
||
− | value1 = values[1] |
||
− | for i = 1,7 do |
||
− | if i < value1 |
||
− | then |
||
− | output[i] = cell('', colors[1]) |
||
− | filled[i] = true |
||
− | elseif i == value1 |
||
− | then |
||
− | category = description[row_number].values[value1].category |
||
− | table.insert(output_categories, category) |
||
− | category = h.LinkToCategory(category, tooltip(value1, row_number)) |
||
− | output[i] = cell(category, colors[1]) |
||
− | filled[i] = true |
||
− | end |
||
− | end |
||
− | |||
− | for j = 2, #colors do |
||
− | for i = 1, 7 do |
||
− | value2 = values[j] |
||
− | if not h.isempty(value2) |
||
− | then |
||
− | if i < value2 and value2 < value1 |
||
− | then |
||
− | output[i] = cell('', colors[j]) |
||
− | filled[i] = true |
||
− | end |
||
− | if i < value2 and filled[i] == false |
||
− | then |
||
− | output[i] = cell('', colors[j]) |
||
− | filled[i] = true |
||
− | end |
||
− | if i == value2 |
||
− | then |
||
− | category = description[row_number].values[value2].category |
||
− | table.insert(output_categories, category) |
||
− | category = h.LinkToCategory(category, tooltip(value2, row_number)) |
||
− | output[i] = cell(category, colors[j]) |
||
− | filled[i] = true |
||
− | end |
||
− | end |
||
− | end |
||
− | end |
||
− | |||
− | return table.concat(output), output_categories |
||
end |
end |
||
Latest revision as of 13:58, 26 August 2021
/* 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