RogerDodger (talk | contribs) (Created page with "local G = require("Module:G") local p = {} local json = mw.title.makeTitle("User", "RogerDodger/archetypes.json"):getContent() local data = mw.text.jsonDecode(json) local la...") Â |
RogerDodger (talk | contribs) No edit summary  |
||
(12 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local data = mw.text.jsonDecode(json) | local data = mw.text.jsonDecode(json) | ||
local | local atypes = { "Poke", "Mixup", "Keepout", "Whiff punish", "Okizeme", "Pressure", "Defense", "Tricky" } | ||
local a_ranks = {} | |||
for _,fighter in ipairs(data["unsorted"]) do | |||
a_ranks[fighter] = {} | |||
end | |||
for _,label in ipairs(atypes) do | |||
for i,fighter in ipairs(data[label]) do | |||
a_ranks[fighter][label] = i | |||
end | |||
end | |||
local diffs = { "Dexterity", "Timing", "Memory" } | |||
local d_ranks = {} | |||
for _,fighter in ipairs(data["unsorted"]) do | |||
d_ranks[fighter] = {} | |||
end | |||
for _,label in ipairs(diffs) do | |||
for i,fighter in ipairs(data[label]) do | |||
d_ranks[fighter][label] = i | |||
end | |||
end | end | ||
p.all = function() | p.all = function() | ||
local ranks = | local makeTable = function(labels, ranks) | ||
local wikitable = mw.html.create('table'):addClass('punishers sortable') | |||
-- Headings | |||
local heads = mw.html.create('tr') | |||
heads:node(mw.html.create('th'):wikitext("Character")) | |||
for _,label in ipairs(labels) do | |||
heads:node(mw.html.create('th'):wikitext(label)) | |||
end | |||
heads:node(mw.html.create('th'):wikitext("Total")) | |||
wikitable:node(heads) | |||
-- Body | |||
for _,fighter in ipairs(data["unsorted"]) do | |||
local row = mw.html.create('tr') | |||
local n = 0 | |||
row:node(mw.html.create('td'):wikitext("[[" .. fighter .. "]]")) | |||
for _,label in ipairs(labels) do | |||
local i = ranks[fighter][label] | |||
n = n + i | |||
row:node(mw.html.create('td'):wikitext(i):addClass(G._main(i,1,50,true))) | |||
end | |||
row:node(mw.html.create('td'):wikitext(n)) | |||
wikitable:node(row) | |||
end | |||
return tostring(wikitable) | |||
end | |||
local a_radars = '' | |||
for _,fighter in ipairs(data["unsorted"]) do | for _,fighter in ipairs(data["unsorted"]) do | ||
a_radars = a_radars .. "{{Label|" .. fighter .. "|\n" | |||
.. p._radar(fighter) .. "}}\n" | |||
end | end | ||
for _ | local d_radars = '' | ||
for _,fighter in ipairs(data["unsorted"]) do | |||
d_radars = d_radars .. "{{Label|" .. fighter .. "|\n" | |||
.. p._radar_difficulty(fighter) .. "}}\n" | |||
end | end | ||
local | return | ||
makeTable(atypes, a_ranks) .. "\n\n" .. | |||
mw.getCurrentFrame():preprocess("{{Row|" .. a_radars .. "}}") .. "\n\n" .. | |||
"== Difficulty ==\n\n" .. | |||
makeTable(diffs, d_ranks) .. "\n\n" .. | |||
mw.getCurrentFrame():preprocess("{{Row|" .. d_radars .. "}}") | |||
end | |||
 | |||
p.radar = function(frame) | |||
local fighter = frame.args[1] | |||
local t = frame.args[2] or "a" | |||
if (string.sub(t, 1, 1) == "d") then | |||
return frame:preprocess( p._radar_difficulty(fighter) ) | |||
else | |||
return frame:preprocess( p._radar(fighter) ) | |||
end | |||
end | |||
 | |||
p._radar = function(fighter) | |||
local ranks = a_ranks[fighter] | |||
if ranks == nil then error("Unknown character: " .. fighter) end | |||
-- | -- Standardize | ||
local | local sum = 0 | ||
for _,label in ipairs(atypes) do | |||
for _,label in ipairs( | sum = sum + ranks[label] | ||
end | end | ||
local mu = sum / #atypes | |||
-- local sigma_sq = 0 | |||
-- for _,label in ipairs(atypes) do | |||
-- sigma_sq = sigma_sq + math.pow(mu - ranks[label], 2) | |||
-- end | |||
-- local sigma = math.sqrt(sigma_sq) | |||
local std = {} | |||
for _, | for _,label in ipairs(atypes) do | ||
-- std[label] = (ranks[label] - mu) / sigma | |||
std[label] = 1 - (ranks[label] - (mu - 25)) / 50 | |||
end | end | ||
return | -- -- Normalize | ||
-- local mn = math.huge | |||
-- local mx = -math.huge | |||
-- for _,label in ipairs(atypes) do | |||
-- if ranks[label] < mn then mn = ranks[label] end | |||
-- if ranks[label] > mx then mx = ranks[label] end | |||
-- end | |||
-- local norm = {} | |||
-- for _,label in ipairs(atypes) do | |||
-- norm[label] = 1 - (ranks[label] - mn) / (mx - mn) | |||
-- end | |||
local points = "" | |||
for _,label in ipairs(atypes) do | |||
points = points .. string.format("%.5f", std[label]) | |||
.. " " .. label .. "\n" | |||
end | |||
return "<radar size=\"280\">\n" .. points .. "</radar>" | |||
end | |||
 | |||
p._radar_difficulty = function(fighter) | |||
local ranks = d_ranks[fighter] | |||
local points = "" | |||
for _,label in ipairs(diffs) do | |||
points = points .. string.format( "%.5f", 1 - (ranks[label]-1)/49 ) | |||
.. " " .. label .. "\n" | |||
end | |||
return "<radar size=\"280\">\n" .. points .. "</radar>" | |||
end | end | ||
return p | return p |
Latest revision as of 17:56, 31 January 2022
Documentation for this module may be created at Module:Archetype/doc
local G = require("Module:G")
local p = {}
local json = mw.title.makeTitle("User", "RogerDodger/archetypes.json"):getContent()
local data = mw.text.jsonDecode(json)
local atypes = { "Poke", "Mixup", "Keepout", "Whiff punish", "Okizeme", "Pressure", "Defense", "Tricky" }
local a_ranks = {}
for _,fighter in ipairs(data["unsorted"]) do
a_ranks[fighter] = {}
end
for _,label in ipairs(atypes) do
for i,fighter in ipairs(data[label]) do
a_ranks[fighter][label] = i
end
end
local diffs = { "Dexterity", "Timing", "Memory" }
local d_ranks = {}
for _,fighter in ipairs(data["unsorted"]) do
d_ranks[fighter] = {}
end
for _,label in ipairs(diffs) do
for i,fighter in ipairs(data[label]) do
d_ranks[fighter][label] = i
end
end
p.all = function()
local makeTable = function(labels, ranks)
local wikitable = mw.html.create('table'):addClass('punishers sortable')
-- Headings
local heads = mw.html.create('tr')
heads:node(mw.html.create('th'):wikitext("Character"))
for _,label in ipairs(labels) do
heads:node(mw.html.create('th'):wikitext(label))
end
heads:node(mw.html.create('th'):wikitext("Total"))
wikitable:node(heads)
-- Body
for _,fighter in ipairs(data["unsorted"]) do
local row = mw.html.create('tr')
local n = 0
row:node(mw.html.create('td'):wikitext("[[" .. fighter .. "]]"))
for _,label in ipairs(labels) do
local i = ranks[fighter][label]
n = n + i
row:node(mw.html.create('td'):wikitext(i):addClass(G._main(i,1,50,true)))
end
row:node(mw.html.create('td'):wikitext(n))
wikitable:node(row)
end
return tostring(wikitable)
end
local a_radars = ''
for _,fighter in ipairs(data["unsorted"]) do
a_radars = a_radars .. "{{Label|" .. fighter .. "|\n"
.. p._radar(fighter) .. "}}\n"
end
local d_radars = ''
for _,fighter in ipairs(data["unsorted"]) do
d_radars = d_radars .. "{{Label|" .. fighter .. "|\n"
.. p._radar_difficulty(fighter) .. "}}\n"
end
return
makeTable(atypes, a_ranks) .. "\n\n" ..
mw.getCurrentFrame():preprocess("{{Row|" .. a_radars .. "}}") .. "\n\n" ..
"== Difficulty ==\n\n" ..
makeTable(diffs, d_ranks) .. "\n\n" ..
mw.getCurrentFrame():preprocess("{{Row|" .. d_radars .. "}}")
end
p.radar = function(frame)
local fighter = frame.args[1]
local t = frame.args[2] or "a"
if (string.sub(t, 1, 1) == "d") then
return frame:preprocess( p._radar_difficulty(fighter) )
else
return frame:preprocess( p._radar(fighter) )
end
end
p._radar = function(fighter)
local ranks = a_ranks[fighter]
if ranks == nil then error("Unknown character: " .. fighter) end
-- Standardize
local sum = 0
for _,label in ipairs(atypes) do
sum = sum + ranks[label]
end
local mu = sum / #atypes
-- local sigma_sq = 0
-- for _,label in ipairs(atypes) do
-- sigma_sq = sigma_sq + math.pow(mu - ranks[label], 2)
-- end
-- local sigma = math.sqrt(sigma_sq)
local std = {}
for _,label in ipairs(atypes) do
-- std[label] = (ranks[label] - mu) / sigma
std[label] = 1 - (ranks[label] - (mu - 25)) / 50
end
-- -- Normalize
-- local mn = math.huge
-- local mx = -math.huge
-- for _,label in ipairs(atypes) do
-- if ranks[label] < mn then mn = ranks[label] end
-- if ranks[label] > mx then mx = ranks[label] end
-- end
-- local norm = {}
-- for _,label in ipairs(atypes) do
-- norm[label] = 1 - (ranks[label] - mn) / (mx - mn)
-- end
local points = ""
for _,label in ipairs(atypes) do
points = points .. string.format("%.5f", std[label])
.. " " .. label .. "\n"
end
return "<radar size=\"280\">\n" .. points .. "</radar>"
end
p._radar_difficulty = function(fighter)
local ranks = d_ranks[fighter]
local points = ""
for _,label in ipairs(diffs) do
points = points .. string.format( "%.5f", 1 - (ranks[label]-1)/49 )
.. " " .. label .. "\n"
end
return "<radar size=\"280\">\n" .. points .. "</radar>"
end
return p