Module:SpeedChart

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

function p._speedChart

local tables = 'HeroMaxStats' local queryFields = "_pageName,Spd" local boonQueryArgs = { where = 'Variation="Boon" and HeroMaxStats.Rarity=5', groupBy = '_pageName', limit = '500' } local baneQueryArgs = { where = 'Variation="Bane" and HeroMaxStats.Rarity=5', groupBy = '_pageName', limit = '500' } local neutQueryArgs = { where = 'Variation="Neut" and HeroMaxStats.Rarity=5', groupBy = '_pageName', limit = '500' } local speedBoonQuery = cargo.query(tables, queryFields, boonQueryArgs) local speedBaneQuery = cargo.query(tables, queryFields, baneQueryArgs) local speedNeutQuery = cargo.query(tables, queryFields, neutQueryArgs) local maxBaseSpeed = getMaxSpeed(speedBoonQuery) local minBaseSpeed = getMinSpeed(speedBaneQuery)

-- 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('Baned Units') :css('width', '32%')

tbl:tag('th') :wikitext('Speed') :css('width', '2%')

tbl:tag('th') :wikitext('Neutral Units') :css('width', '32%')

tbl:tag('th') :wikitext('Speed') :css('width', '2%')

tbl:tag('th') :wikitext('Booned Units') :css('width', '32%')

local speedCounter = maxBaseSpeed

while speedCounter > minBaseSpeed-1 do   local tr = tbl:tag('tr')

local herotdbane = tr:tag('td') -- Go through all the baned heroes for _, hero in ipairs(speedBaneQuery) do		if tonumber(hero.Spd) == speedCounter then herotdbane:tag('div') :css('display', 'inline-block') :wikitext(Util.getHeroIcon(hero._pageName, '40px')) end end

tr:tag('td') :wikitext(speedCounter)

local herotdneut = tr:tag('td') -- Go through all the neutral heroes for _, hero in ipairs(speedNeutQuery) do		if tonumber(hero.Spd) == speedCounter then herotdneut:tag('div') :css('display', 'inline-block') :wikitext(Util.getHeroIcon(hero._pageName, '40px')) end end

tr:tag('td') :wikitext(speedCounter)

local herotdboon = tr:tag('td') -- Go through all the booned heroes for _, hero in ipairs(speedBoonQuery) do		if tonumber(hero.Spd) == speedCounter then herotdboon:tag('div') :css('display', 'inline-block') :wikitext(Util.getHeroIcon(hero._pageName, '40px')) end end speedCounter = speedCounter - 1 end

return tostring(tbl) end

function getMaxSpeed(query) local maxSpd = 0 for _, hero in ipairs(query) do   if hero.Spd ~= nil and hero.Spd ~= '-' then local speed = tonumber(hero.Spd) if speed > maxSpd then maxSpd = speed end end end return maxSpd end

function getMinSpeed(query) local minSpd = 9999 for _, hero in ipairs(query) do   if hero.Spd ~= nil and hero.Spd ~= '-' then local speed = tonumber(hero.Spd) if speed < minSpd then minSpd = speed end end end return minSpd end

function p.speedChart(frame) return p._speedChart end

return (require "Module:Deprecated").module(p, "Module:SpeedChart")