Module:A2020Usagi

local MF = require 'Module:MF'.main1 local p = {}

local INDEX_TO_WHITEWING = {"Est: Springtime Flier","Catria: Spring Whitewing","Palla: Eldest Bun-Bun","Narcian: Vernal General"}

local votes = mw.loadData("Module:A2020Usagi/data")

p.main = function local tbl = mw.html.create("table") :addClass("wikitable") :addClass("sortable") :css("text-align","center")

tbl:tag("th"):wikitext("Rank") tbl:tag("th"):wikitext("Whitewing") tbl:tag("th"):wikitext("Votes") local votecounts = {0,0,0,0} for _,vote in pairs(votes) do		votecounts[vote] = votecounts[vote] + 1 end for i=1,#votecounts do		votecounts[i] = {i, votecounts[i]} end table.sort(votecounts, function(a, b) return a[2] > b[2] end) local sum = 0 local lastRank local lastVote for i=1,#votecounts do		local whitewing_index = votecounts[i][1] local votes = votecounts[i][2] sum = sum + votes local tr = tbl:tag("tr") if votes == lastVote then tr:tag("td"):wikitext(lastRank) else tr:tag("td"):wikitext(i) lastRank = i		end lastVote = votes local whiteWing = INDEX_TO_WHITEWING[whitewing_index] tr:tag("td"):wikitext(" "..whiteWing.."") tr:tag("td"):wikitext(votes) end return tostring(tbl) .. "Total votes: " .. sum end

return p