Module:SummoningPoolStatistics

local cargo = mw.ext.cargo local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local p = {} local FOCUS_RATE = 0.03 local FIVE_RATE = 0.03 local FOUR_RATE = 0.58 local THREE_RATE = 0.36 local COLORS = {"Red", "Blue", "Green", "Colorless"}

function p.main(frame) local pool = cargo.query('SummoningAvailability,Units,WeaponTypes', 'Rarity,Color', {		join = 'SummoningAvailability._pageName=Units._pageName,Units.WeaponType=WeaponTypes.WikiName',		where = "Rarity IS NOT NULL AND IFNULL(Properties__full,) NOT LIKE '%enemy%' AND (NOW BETWEEN StartTime AND EndTime)" .. (frame.args[1] == 'intro' and ' AND NewHeroes' or ),		groupBy = 'Units.WikiName,Rarity',		limit = 1000,	}) for _, v in ipairs(pool) do		v.Rarity = tonumber(v.Rarity) end local poolByColor = List.group_by(pool, function (v) return v.Color end) local total3Heroes = Hash.generate(COLORS, function (col)		return List.count_if(poolByColor[col], function (v) return v.Rarity == 3 end)	end) local total4Heroes = Hash.generate(COLORS, function (col)		return List.count_if(poolByColor[col], function (v) return v.Rarity == 4 end)	end) local total5Heroes = Hash.generate(COLORS, function (col)		return List.count_if(poolByColor[col], function (v) return v.Rarity == 5 end)	end)

total3Heroes.Total = List.sum(Hash.values(total3Heroes)) total4Heroes.Total = List.sum(Hash.values(total4Heroes)) total5Heroes.Total = List.sum(Hash.values(total5Heroes)) local totalFocusHeroes = {["Red"] = 1, ["Blue"] = 1, ["Green"] = 1, ["Colorless"] = 1, ["Total"] = 4} local tbl = mw.html.create("table") :addClass("wikitable") :css("text-align","center") tbl:tag("th") :attr("colspan",2) :attr("rowspan",2) :addClass("unsortable") tbl:tag("th") :attr("colspan",4) :wikitext("Rarity") local r1 = tbl:tag("tr") r1:tag("th"):wikitext("5★ Focus") r1:tag("th"):wikitext("5★") r1:tag("th"):wikitext("4★") r1:tag("th"):wikitext("3★") local r2 = tbl:tag("tr") r2:tag("th") :wikitext("Appearance rate") :attr("rowspan",4) r2:tag("th"):wikitext("Red") r2:tag("td") :wikitext("0.75%") :attr("rowspan",4) r2:tag("td") :wikitext(string.format("%.3f", 3/total5Heroes["Total"]) .. "%") :attr("rowspan",4) r2:tag("td") :wikitext(string.format("%.3f", 58/total4Heroes["Total"]) .. "%") :attr("rowspan",4) r2:tag("td") :wikitext(string.format("%.3f", 36/total3Heroes["Total"]) .. "%") :attr("rowspan",4) tbl:tag("tr"):tag("th"):wikitext("Blue") tbl:tag("tr"):tag("th"):wikitext("Green") tbl:tag("tr"):tag("th"):wikitext("Colorless") local r6 = tbl:tag("tr") r6:tag("th") :wikitext("Unit count") :attr("rowspan",4) r6:tag("th"):wikitext("Red") r6:tag("td"):wikitext(1) r6:tag("td"):wikitext(total5Heroes["Red"]) r6:tag("td"):wikitext(total4Heroes["Red"]) r6:tag("td"):wikitext(total3Heroes["Red"]) local r7 = tbl:tag("tr") r7:tag("th"):wikitext("Blue") r7:tag("td"):wikitext(1) r7:tag("td"):wikitext(total5Heroes["Blue"]) r7:tag("td"):wikitext(total4Heroes["Blue"]) r7:tag("td"):wikitext(total3Heroes["Blue"]) local r8 = tbl:tag("tr") r8:tag("th"):wikitext("Green") r8:tag("td"):wikitext(1) r8:tag("td"):wikitext(total5Heroes["Green"]) r8:tag("td"):wikitext(total4Heroes["Green"]) r8:tag("td"):wikitext(total3Heroes["Green"])

local r9 = tbl:tag("tr") r9:tag("th"):wikitext("Colorless") r9:tag("td"):wikitext(1) r9:tag("td"):wikitext(total5Heroes["Colorless"]) r9:tag("td"):wikitext(total4Heroes["Colorless"]) r9:tag("td"):wikitext(total3Heroes["Colorless"]) local unitIs = {} --Chance for a random orb to be a certain color for k,color in ipairs(COLORS) do		unitIs[color] = (FOCUS_RATE * totalFocusHeroes[color] / totalFocusHeroes["Total"]) + (FIVE_RATE * total5Heroes[color] / total5Heroes["Total"]) + (FOUR_RATE * total4Heroes[color] / total4Heroes["Total"]) + (THREE_RATE * total3Heroes[color] / total3Heroes["Total"]) local row = tbl:tag("tr") if k == 1 then row:tag("th") :wikitext("Rate | Orb color") :attr("rowspan",4) end row:tag("th"):wikitext(color) row:tag("td"):wikitext(string.format("%.3f", FOCUS_RATE * 1 / totalFocusHeroes["Total"] / unitIs[color] * 100) .. "%") row:tag("td"):wikitext(string.format("%.3f", FIVE_RATE * 1 / total5Heroes["Total"] / unitIs[color] * 100) .. "%") row:tag("td"):wikitext(string.format("%.3f", FOUR_RATE * 1 / total4Heroes["Total"] / unitIs[color] * 100) .. "%") row:tag("td"):wikitext(string.format("%.3f", THREE_RATE * 1 / total3Heroes["Total"] / unitIs[color] * 100) .. "%") end for k,color in ipairs(COLORS) do		local row = tbl:tag("tr") if k == 1 then row:tag("th") :wikitext("Failure to appear") :attr("rowspan",4) end row:tag("th"):wikitext(color) row:tag("td") :attr("colspan",4) :wikitext(string.format("%.3f%%", (1-unitIs[color])^5 * 100)) end return tbl end

return p