Module:Sandbox/AnataBakka2

-- local p   = {} local lib      = require('Module:Feature') local json     = require('Module:JSON') local cmd      = require('Module:Maintenance data') local userError = require('Dev:User error') local IL       = require('Module:ImageLink')

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local stat       = args[1] or "as" local stat2      = args[2] or stat local stat3      = args[3] or stat local s          = '{| class="wikitable"\n|+Champions with the lowest or highest '..stat3..' before items, runes, or abilities\n! width="100pt" | Champion Level\n! colspan="2" width="200pt" | Bottom 5 champions\n|-\n! rowspan="10" | Level 1' s=s..getstats(1,stat,stat2,frame) s=s..'\n|-\n! colspan="5" height="5pt" |\n|-\n! rowspan="10" | Level 18' s=s..getstats(18,stat,stat2,frame) return s.."\n|}" end

function getstats(lvl,stat,stat2,frame) local patchid    = cmd.main{"PatchId"} local luadata    = loadData(patchid) local stats={} local s="" for champname, champdata in pairs(luadata) do       if (stat=="mp" or stat=="mp5") and pst2(champname,"resource",frame)~="" and pst2(champname,"resource",frame)~="" and string.lower(pst2(champname,"resource",frame))~="mana" then else base=tonumber(pst2(champname,stat.."_base",frame)) or tonumber(pst2(champname,stat,frame)) xlvl=tonumber(pst2(champname,stat.."_lvl",frame)) or 0 if stat=="as" then as_lvl1=tonumber(pst2(champname,"as_lvl1",frame)) or tonumber(pst2(champname,"as_base",frame)) table.insert(stats,{champname, as_lvl1+base*xlvl/100*(lvl-1)*(0.7025+0.0175*(lvl-1))}) else table.insert(stats,{champname, base+xlvl*(lvl-1)*(0.7025+0.0175*(lvl-1))}) end end end table.sort(stats, function(a, b) return a[2]<b[2] end) j=1 k=1 while j<=#stats do       if j==1 then s="\n| "..ci(stats[j][1],frame) if stats[j][2]~=stats[j+1][2] then s=s.."\n| "..fd(round(stats[j][2])).."\n" end else if stats[j][2]==stats[j-1][2] then s=s.." "..ci(stats[j][1],frame) if stats[j][2]~=stats[j+1][2] then s=s.."\n| "..fd(round(stats[j][2])).."\n" end else k=k+1 if k==6 then break else s=s.."\n|-\n| "..ci(stats[j][1],frame) if stats[j][2]~=stats[j+1][2] then s=s.."\n| "..fd(round(stats[j][2])).."\n" end end end end j=j+1 end j=#stats k=6 while j>=1 do       if j==#stats then s=s.."\n|-\n| "..ci(stats[j][1],frame) if stats[j][2]~=stats[j-1][2] then s=s.."\n| "..fd(round(stats[j][2])).."\n" end else if stats[j][2]==stats[j+1][2] then s=s.." "..ci(stats[j][1],frame) if stats[j][2]~=stats[j-1][2] then s=s.."\n| "..fd(round(stats[j][2])).."\n" end else k=k+1 if k==11 then break end s=s.."\n|-\n| "..ci(stats[j][1],frame) if stats[j][2]~=stats[j-1][2] then s=s.."\n| "..fd(round(stats[j][2])).."\n" end end end j=j-1 end return s end function loadData(patchid) if exists('Module:StatTable/data/' .. patchid) then return mw.loadData('Module:StatTable/data/' .. patchid) end return nil end

function exists(page) local sPage = page if sPage then local _, val = pcall(package.loaders[2], sPage) if type(val) == "function" or type(val) == "string" then return true end end return false end

function pst2(champion, stat, frame) return frame:expandTemplate{ title = 'Data '.. champion, args = {'pst2', stat} } end

function ci(champion, frame) return frame:expandTemplate{ title = "ci", args = {champion} } end

function fd(val) if string.find(val,"[%d]") == nil or string.find(val,"%.") == nil then return val end local a,b = val:match"([$d]*).([%d]*)" return a .. ". " .. b .. " " end

function round(val) local mult = 10^3 local round=math.floor(val * mult + 0.5) / mult return round end return p --