Module:Archetype: Difference between revisions

From Wavu Wiki, the 🌊 wavy Tekken wiki
No edit summary
No edit summary
 
(8 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 labels = { "Poke", "Mixup", "Okiwaza", "Whiff punish", "Okizeme", "Pressure", "Defense" }
local atypes = { "Poke", "Mixup", "Keepout", "Whiff punish", "Okizeme", "Pressure", "Defense", "Tricky" }
local ranks = {}
local a_ranks = {}
for _,fighter in ipairs(data["unsorted"]) do
for _,fighter in ipairs(data["unsorted"]) do
ranks[fighter] = {}
a_ranks[fighter] = {}
end
end
for _,label in ipairs(labels) do
for _,label in ipairs(atypes) do
for i,fighter in ipairs(data[label]) do
for i,fighter in ipairs(data[label]) do
ranks[fighter][label] = i
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
end


p.all = function()
p.all = function()
local wikitable = mw.html.create('table'):addClass('punishers sortable')
local makeTable = function(labels, ranks)
local wikitable = mw.html.create('table'):addClass('punishers sortable')
-- Headings
local heads = mw.html.create('tr')
-- Headings
heads:node(mw.html.create('th'):wikitext("Character"))
local heads = mw.html.create('tr')
for _,label in ipairs(labels) do
heads:node(mw.html.create('th'):wikitext("Character"))
heads:node(mw.html.create('th'):wikitext(label))
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
end
heads:node(mw.html.create('th'):wikitext("Total"))
wikitable:node(heads)
-- Body
local a_radars = ''
for _,fighter in ipairs(data["unsorted"]) do
for _,fighter in ipairs(data["unsorted"]) do
local row = mw.html.create('tr')
a_radars = a_radars .. "{{Label|" .. fighter .. "|\n"
local n = 0
.. p._radar(fighter) .. "}}\n"
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
end
local radars = ''
local d_radars = ''
for fighter,_ in ranks do
for _,fighter in ipairs(data["unsorted"]) do
radars = radars .. p._radar(fighter) .. "\n"
d_radars = d_radars .. "{{Label|" .. fighter .. "|\n"
.. p._radar_difficulty(fighter) .. "}}\n"
end
end
return wikitable .. "\n\n" .. "{{Row|" .. radars .. "}}"
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
end


p.radar = function(frame)  
p.radar = function(frame)  
local fighter = frame.args[1]
local fighter = frame.args[1]
return p._radar(fighter)
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
end


p._radar = function(fighter)
p._radar = function(fighter)
local archetype = ranks[fighter]
local ranks = a_ranks[fighter]
if archetype == nil then error("Unknown character: " .. fighter) end
if ranks == nil then error("Unknown character: " .. fighter) end
mw.logObject(archetype)
-- 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 = ""
local points = ""
for _,label in ipairs(labels) do
for _,label in ipairs(diffs) do
points = points .. string.format("%.5f", 1 - ((archetype[label] - 1) / 49)) .. " " .. label .. "\n"
points = points .. string.format( "%.5f", 1 - (ranks[label]-1)/49 )
.. " " .. label .. "\n"
end
end
return "{{Label|" .. fighter .. "|\n<radar size=\"280\">\n" .. points .. "</radar>}}"
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