No edit summary |
No edit summary |
||
(24 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. |
+ | function p.main(pagename) |
− | local args = getArgs (frame) |
||
− | local pagename = args.pagename or mw.title.getCurrentTitle().text |
||
local caption = 'Power Grid' |
local caption = 'Power Grid' |
||
local info = list_of_power_grids[pagename] |
local info = list_of_power_grids[pagename] |
||
− | local |
+ | local i |
local value |
local value |
||
− | local |
+ | local category |
+ | local list = {} |
||
+ | local PlotData = {} |
||
local output_categories = {} |
local output_categories = {} |
||
− | local output = |
+ | local output = '' |
if info ~= nil |
if info ~= nil |
||
then |
then |
||
+ | output = {} |
||
− | table.insert(output, '{{DEFAULTSORT:'..standard.name_for_sorting({pagename})..'|noerror}}') |
||
table.insert(output_categories, 'Power Grid Added') |
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 |
for i = 1,6 do |
||
− | + | table.insert(output, p.get_color(i, info[i+7])) |
|
− | table.insert(output, value) |
||
− | output_categories = h.join_tables(output_categories, categories) |
||
end |
end |
||
+ | |||
− | |||
+ | value, category = p.get_TextData(info) |
||
− | if info[8] ~= nil |
||
+ | 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 |
then |
||
+ | list = h.explode('@@@', value) |
||
− | explanation = tostring(mw.html.create('td'):attr('colspan', '8'):css('width', '350px'):wikitext('* '..info[8])) |
||
+ | for i = 1, #list do |
||
− | explanation = tostring(mw.html.create('tr'):wikitext(explanation)) |
||
+ | value = list[i] |
||
− | end |
||
+ | if h.exists(value) |
||
− | |||
+ | then value = h.Link(value) |
||
− | if info[7] ~= nil |
||
− | + | end |
|
− | caption = caption..'<ref>'.. |
+ | caption = caption..'<ref>'..value..'</ref>' |
+ | end |
||
table.insert(output_categories, 'Power Grid Complete') |
table.insert(output_categories, 'Power Grid Complete') |
||
else |
else |
||
table.insert(output_categories, 'Power Grid Reference Needed') |
table.insert(output_categories, 'Power Grid Reference Needed') |
||
end |
end |
||
+ | |||
caption = mw.html.create('caption') |
caption = mw.html.create('caption') |
||
− | :css('color', 'white') |
||
− | :css('background-color', 'gray') |
||
:css('font-weight', 'bold') |
:css('font-weight', 'bold') |
||
:wikitext(caption) |
:wikitext(caption) |
||
caption = tostring(caption) |
caption = tostring(caption) |
||
+ | |||
− | |||
output = mw.html.create('table') |
output = mw.html.create('table') |
||
− | + | :attr('align', 'right') |
|
− | + | :css('border', '1px solid gray') |
|
+ | :wikitext(caption..'<tr><td>'..output..'</td></tr>') |
||
− | :attr('cellpadding', '0') |
||
− | --:css('clear', 'both') |
||
− | :css('background-color', 'white') |
||
− | :css('border', '1px solid gray') |
||
− | :wikitext(caption..table.concat(output)..explanation) |
||
end |
end |
||
+ | |||
− | |||
− | return |
+ | return tostring(output), output_categories |
end |
end |
||
− | |||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
+ | function p.get_color(n, legend) |
||
− | -- used in Template:Official Power Grid |
||
+ | local colors = {'rgb(0.663, 0.663, 0.663)', -- darkgray |
||
− | function p.main(frame) |
||
+ | 'rgb(0.118, 0.565, 1)', -- dodgerblue |
||
− | local args = getArgs (frame) |
||
+ | 'rgb(1, 0.388, 0.278)', -- tomato |
||
− | local pagename = mw.title.getCurrentTitle().subpageText |
||
+ | 'rgb(0.235, 0.702, 0.443)', -- mediumseagreen |
||
− | local explanation = args.Explanation |
||
+ | 'rgb(1, 0.647, 0)', -- orange |
||
− | local reference = args.Reference |
||
+ | 'rgb(0.535,0.484,0.844)', -- Moody Blue |
||
− | local caption = 'Power Grid' |
||
+ | 'rgb(0.933,0.509,0.933)', -- violet |
||
− | local value |
||
+ | } |
||
− | local categories |
||
+ | local output = ' id:color'..n..' value:'..colors[n] |
||
− | 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( |
+ | if not h.isempty(legend) |
+ | then output = output..' legend:'..string.gsub(legend, ' ', '_') |
||
− | then |
||
− | caption = caption..'<ref>'..reference..'</ref>' |
||
− | table.insert(output_categories, 'Power Grid Complete') |
||
− | else |
||
− | table.insert(output_categories, 'Power Grid Reference Needed') |
||
end |
end |
||
− | caption = mw.html.create('caption') |
||
− | :css('color', 'white') |
||
− | :css('background-color', 'gray') |
||
− | :css('font-weight', 'bold') |
||
− | --:css('font-style', 'italic') |
||
− | :wikitext(caption) |
||
− | caption = tostring(caption) |
||
+ | return output |
||
− | 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 |
end |
||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
− | function p. |
+ | function p.get_text_and_category(row_number, value) |
+ | local hor = {'115', '149', '183', '216', '250', '286', '319'} |
||
− | local value1 |
||
+ | local ver = {'233', '204', '176', '146', '116', '87'} |
||
− | local value2 = nil |
||
+ | local category = '' |
||
− | local label = design.lua_add_tooltip(description[row_number].label, description[row_number].tooltip) |
||
− | local |
+ | local output = '' |
− | local output |
||
+ | if value ~= 0 |
||
− | if string.find(values, '-', 1, true) ~= nil |
||
− | then |
+ | then |
+ | category = description[row_number].values[value].category |
||
− | value1, value2 = string.match(values, '(%d)%-(%d)') |
||
+ | output = ' pos:('..hor[value]..', '..ver[row_number]..') text:' |
||
− | value1 = tonumber(value1) |
||
+ | output = output..'"'..h.LinkToCategory(category, value)..'"' |
||
− | value2 = tonumber(value2) |
||
− | if explanation ~= nil |
||
− | then label = label .. '*' |
||
− | end |
||
− | else value1 = tonumber(values) |
||
end |
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) |
||
− | value1, output_categories = p.add_td(value1, value2, row_number) |
||
− | output = tostring( mw.html.create('tr'):wikitext( label..value1 ) ) |
||
− | return output, |
+ | return output, category |
end |
end |
||
+ | |||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
− | function p. |
+ | function p.get_values(value) |
− | 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 color1 = 'darkgray' |
||
− | local color2 = 'royalblue' |
||
local i |
local i |
||
− | local |
+ | local values = {} |
− | local |
+ | local output = {} |
− | local tooltip1 |
||
− | local tooltip2 |
||
− | local output_categories = {} |
||
− | local output = {'', '', '', '', '', '', ''} |
||
+ | if string.find(value, '-') == nil |
||
− | category1 = description[row_number].values[value1].category |
||
+ | then output = {tonumber(value), 0, 0, 0, 0, 0} |
||
− | tooltip1 = design.lua_add_tooltip(value1, description[row_number].values[value1].tooltip) |
||
+ | else |
||
− | tooltip1 = tostring( mw.html.create('span'):css('color', 'white'):wikitext(tooltip1) ) |
||
+ | values = mw.text.split(value, '-') |
||
− | table.insert(output_categories, category1) |
||
+ | for i = 1, 6 do |
||
− | category1 = h.LinkToCategory(category1, tooltip1) |
||
+ | table.insert(output, tonumber(values[i]) or 0 ) |
||
− | if not h.isempty(value2) |
||
− | + | end |
|
− | category2 = description[row_number].values[value2].category |
||
− | tooltip2 = design.lua_add_tooltip(value2, description[row_number].values[value2].tooltip) |
||
− | tooltip2 = tostring( mw.html.create('span'):css('color', 'white'):wikitext(tooltip2) ) |
||
− | table.insert(output_categories, category2) |
||
− | category2 = h.LinkToCategory(category2, tooltip2) |
||
− | end |
||
− | |||
− | for i = 1, 7 do |
||
− | tooltip = design.lua_add_tooltip(i, description[row_number][i]) |
||
− | output[i] = cell('', 'transparent') |
||
− | if i < value1 |
||
− | then output[i] = cell('', color1) |
||
− | elseif i == value1 |
||
− | then output[i] = cell(category1, color1) |
||
− | elseif value2 ~= nil |
||
− | then |
||
− | if i < value2 |
||
− | then output[i] = cell('', color2) |
||
− | elseif i == value2 |
||
− | then output[i] = cell(category2, color2) |
||
− | end |
||
− | end |
||
end |
end |
||
− | return |
+ | return output |
end |
end |
||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
− | function p. |
+ | function p.get_TextData(info) |
+ | local values = {} |
||
− | local label = design.lua_add_tooltip(description[row_number].label, description[row_number].tooltip) |
||
+ | local value |
||
+ | local category |
||
+ | local i |
||
+ | local j |
||
local output_categories = {} |
local output_categories = {} |
||
local output = {} |
local output = {} |
||
+ | table.insert(output, 'TextData =') |
||
− | if string.find(values, '-', 1, true) ~= nil |
||
+ | for i = 1, 6 do |
||
− | then |
||
− | + | values = p.get_values(info[i]) |
|
− | + | for j = 1, 6 do |
|
+ | value, category = p.get_text_and_category(i, values[j]) |
||
− | output[i] = tonumber(output[i]) |
||
+ | table.insert(output_categories, category) |
||
− | end |
||
+ | table.insert(output, value) |
||
− | if explanation ~= nil |
||
+ | end |
||
− | then label = label .. '*' |
||
− | end |
||
− | else output = {tonumber(values)} |
||
end |
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_td2(output, row_number) |
||
− | output = tostring( mw.html.create('tr'):wikitext( label..output ) ) |
||
return output, output_categories |
return output, output_categories |
||
Line 242: | Line 164: | ||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
− | function p. |
+ | function p.get_PlotData(info) |
− | local function |
+ | local function sort(a, b) |
− | return |
+ | return a[1] > b[1] |
− | :css('width', '30px') |
||
− | :css('text-align', 'center') |
||
− | :css('border-bottom', '1px solid gray') |
||
− | :css('background-color', color) |
||
− | :wikitext(text) |
||
− | ) |
||
end |
end |
||
− | local |
+ | local values = {} |
− | 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'} |
||
local i |
local i |
||
local j |
local j |
||
− | local |
+ | local PlotData = {} |
− | local |
+ | local output = {} |
+ | |||
− | local category |
||
+ | table.insert(output, 'PlotData =') |
||
− | local filled = {false, false, false, false, false, false, false} |
||
+ | for i = 1,6 do |
||
− | local output_categories = {} |
||
+ | values = p.get_values(info[i]) |
||
− | local output = {'', '', '', '', '', '', ''} |
||
+ | PlotData = {} |
||
− | |||
− | + | for j = 1, 6 do |
|
+ | if values[j] ~= 0 |
||
− | output[i] = cell('', 'transparent') |
||
+ | then table.insert(PlotData, {values[j], ' bar:bar'..i..' from:0 till:'..values[j]..' color:color'..j}) |
||
− | end |
||
+ | 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 |
||
+ | table.sort(PlotData, sort) |
||
− | end |
||
+ | for j = 1, #PlotData do |
||
− | |||
+ | table.insert(output, PlotData[j][2]) |
||
− | 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 |
||
end |
end |
||
− | return |
+ | return output |
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