Module:User:Fallenkenkaku

local p = {} local cargo = mw.ext.cargo local util = require('Module:Util')

function p.testChart(frame) local args = frame.args local mode = args[1] local tables = 'HeroMaxStats=s,Heroes=h,HeroMaxStats=t' local queryFields = "s._pageName=Hero,s.Def=NeutDef,s.Res=NeutRes,t.Def=BoonDef,t.Res=BoonRes,MAX(s.Res)=Mit,MAX(s.Res)=Which,h.MoveType=MoveType" local queryArgs = { where = 's.Variation="Neut" AND t.Variation="Boon" AND t.Rarity=5 AND s.Rarity=5', groupBy = 's._pageName, s._pageName', join = 's._pageName=h._pageName, s._pageName=t._pageName, h._pageName=t._pageName ', limit = '500' } local mitigationQuery = cargo.query(tables, queryFields, queryArgs) for _, hero in pairs(mitigationQuery) do  local defString = ' Def' local resString = ' Res' local sameString = ' Both' if mode == 'sum' then hero.Mit = math.max(tonumber(hero.NeutDef) + tonumber(hero.BoonRes), tonumber(hero.BoonDef) + tonumber(hero.NeutRes)) if tonumber(hero.NeutDef) + tonumber(hero.BoonRes) > tonumber(hero.BoonDef) + tonumber(hero.NeutRes) then hero.Which = '+Res' elseif tonumber(hero.NeutDef) + tonumber(hero.BoonRes) < tonumber(hero.BoonDef) + tonumber(hero.NeutRes) then hero.Which = '+Def' else hero.Which = '' end elseif mode == 'min' then if tonumber(hero.Def) < tonumber(hero.Res) then hero.Mit = tonumber(hero.Def) hero.Which = defString elseif tonumber(hero.Def) > tonumber(hero.Res) then hero.Mit = tonumber(hero.Res) hero.Which = resString else hero.Mit = tonumber(hero.Def) hero.Which = sameString end elseif mode == 'max' then if tonumber(hero.Def) > tonumber(hero.Res) then hero.Mit = tonumber(hero.Def) hero.Which = defString elseif tonumber(hero.Def) < tonumber(hero.Res) then hero.Mit = tonumber(hero.Res) hero.Which = resString else hero.Mit = tonumber(hero.Def) hero.Which = sameString end end end local maxMit = getMaxMit(mitigationQuery) local minMit = getMinMit(mitigationQuery)

-- Initialize the table local tbl = mw.html.create('table') :addClass('wikitable default sortable') :css('text-align','center') :css('margin','auto') :css('font-weight', '700') :css('width', '100%')

-- Add table headers tbl:tag('th') :wikitext('Mitigation') :css('width', '8%')

tbl:tag('th') :wikitext('Armored') :css('width', '23%')

tbl:tag('th') :wikitext('Cavalry') :css('width', '23%')

tbl:tag('th') :wikitext('Flying') :css('width', '23%')

tbl:tag('th') :wikitext('Infantry') :css('width', '23%')

local mitCounter = maxMit

while mitCounter > minMit-1 do   local tr = tbl:tag('tr') tr:tag('td') :wikitext(mitCounter) local herotdarm = tr:tag('td') local herotdcav = tr:tag('td') local herotdfly = tr:tag('td') local herotdinf = tr:tag('td') -- Go through all the heroes for _, hero in ipairs(mitigationQuery) do	if tonumber(hero.Mit) == mitCounter then if hero.MoveType == 'Armored' then herotdarm:tag('div') :css('display', 'inline-block') :wikitext( tostring(frame:expandTemplate{ title = 'Template:TierListUnitBox', args = { hero.Hero } }) ) :wikitext( hero.Which ) elseif hero.MoveType == 'Cavalry' then herotdcav:tag('div') :css('display', 'inline-block') :wikitext( tostring(frame:expandTemplate{ title = 'Template:TierListUnitBox', args = { hero.Hero } }) ) :wikitext( hero.Which ) elseif hero.MoveType == 'Flying' then herotdfly:tag('div') :css('display', 'inline-block') :wikitext( tostring(frame:expandTemplate{ title = 'Template:TierListUnitBox', args = { hero.Hero } }) ) :wikitext( hero.Which ) elseif hero.MoveType == 'Infantry' then herotdinf:tag('div') :css('display', 'inline-block') :wikitext( tostring(frame:expandTemplate{ title = 'Template:TierListUnitBox', args = { hero.Hero } }) ) :wikitext( hero.Which ) end end end

mitCounter = mitCounter - 1 end

return tostring(tbl) end

function getMaxMit(query) local maxMit = 0 for _, hero in ipairs(query) do   if hero.Mit ~= nil and hero.Mit ~= '-' then local mitigation = tonumber(hero.Mit) if mitigation > maxMit then maxMit = mitigation end end end return maxMit end

function getMinMit(query) local minMit = 9999 for _, hero in ipairs(query) do   if hero.Mit ~= nil and hero.Mit ~= '-' then local mitigation = tonumber(hero.Mit) if mitigation < minMit then minMit = mitigation end end end return minMit end

return p