Module:User:Soulskourer/SPSgeneric

local cargo = mw.ext.cargo local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local p = {} local COLORS = {'Red', 'Blue', 'Green', 'Colorless'}

function p.main(frame)

local focusRed = 1 local focusBlue = 1 local focusGreen = 1 local focusColorless = 1 local totfocusHeroes = focusRed + focusBlue + focusGreen + focusColorless local excludeRed = 0 local excludeBlue = 0 local excludeGreen = 0 local excludeColorless = 0 local excludeTotal = excludeRed + excludeBlue + excludeGreen + excludeColorless

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.reduce(Hash.values(total3Heroes), function (x, y) return x + y end, 0) total4Heroes.Total = List.reduce(Hash.values(total4Heroes), function (x, y) return x + y end, 0) total5Heroes.Total = List.reduce(Hash.values(total5Heroes), function (x, y) return x + y end, 0) local focusHeroes = { ["Red"] = 3*focusRed/totfocusHeroes, ["Blue"] = 3*focusBlue/totfocusHeroes, ["Green"] = 3*focusGreen/totfocusHeroes, ["Colorless"] = 3*focusColorless/totfocusHeroes} local pity5Heroes = { ["Red"] = total5Heroes["Red"] - excludeRed, ["Blue"] = total5Heroes["Blue"] - excludeBlue, ["Green"] = total5Heroes["Green"] - excludeGreen, ["Colorless"] = total5Heroes["Colorless"] - excludeColorless, ["Total"] = total5Heroes["Total"] - excludeTotal} local tbl = mw.html.create("table") :addClass("wikitable") :addClass("unsortable") :css("text-align","center") tbl:tag("th") :attr("colspan",6) :wikitext("Generic 4H 1C Each Banner 10/4") local r0 = tbl:tag("tr") r0:tag("th") :attr("colspan",2) :attr("rowspan",2) r0: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 (Total)") :attr("rowspan",4) r2:tag("th"):wikitext("Red") r2:tag("td") :wikitext(string.format(focusHeroes["Red"]) .. "%") r2:tag("td"):wikitext(string.format("%.3f", 3 * pity5Heroes["Red"] / pity5Heroes["Total"]) .. "%") r2:tag("td") :wikitext(string.format("%.3f", 58 * total4Heroes["Red"] / total4Heroes["Total"]) .. "%") r2:tag("td") :wikitext(string.format("%.3f", 36 * total3Heroes["Red"] / total3Heroes["Total"]) .. "%") local r3 = tbl:tag("tr") r3:tag("th"):wikitext("Blue") r3:tag("td") :wikitext(string.format(focusHeroes["Blue"]) .. "%") r3:tag("td"):wikitext(string.format("%.3f", 3 * pity5Heroes["Blue"] / pity5Heroes["Total"]) .. "%") r3:tag("td") :wikitext(string.format("%.3f", 58 * total4Heroes["Blue"] / total4Heroes["Total"]) .. "%") r3:tag("td") :wikitext(string.format("%.3f", 36 * total3Heroes["Blue"] / total3Heroes["Total"]) .. "%") local r4 = tbl:tag("tr") r4:tag("th"):wikitext("Green") r4:tag("td") :wikitext(string.format(focusHeroes["Green"]) .. "%") r4:tag("td"):wikitext(string.format("%.3f", 3 * pity5Heroes["Green"] / pity5Heroes["Total"]) .. "%") r4:tag("td") :wikitext(string.format("%.3f", 58 * total4Heroes["Green"] / total4Heroes["Total"]) .. "%") r4:tag("td") :wikitext(string.format("%.3f", 36 * total3Heroes["Green"] / total3Heroes["Total"]) .. "%") local r5 = tbl:tag("tr") r5:tag("th"):wikitext("Colorless") r5:tag("td") :wikitext(string.format(focusHeroes["Colorless"]) .. "%") r5:tag("td"):wikitext(string.format("%.3f", 3 * pity5Heroes["Colorless"] / pity5Heroes["Total"]) .. "%") r5:tag("td") :wikitext(string.format("%.3f", 58 * total4Heroes["Colorless"] / total4Heroes["Total"]) .. "%") r5:tag("td") :wikitext(string.format("%.3f", 36 * total3Heroes["Colorless"] / total3Heroes["Total"]) .. "%") local r6 = tbl:tag("tr") r6:tag("th") :wikitext("Unit count") :attr("rowspan",5) r6:tag("th"):wikitext("Red") r6:tag("td"):wikitext(focusRed) r6:tag("td"):wikitext(pity5Heroes["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(focusBlue) r7:tag("td"):wikitext(pity5Heroes["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(focusGreen) r8:tag("td"):wikitext(pity5Heroes["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(focusColorless) r9:tag("td"):wikitext(pity5Heroes["Colorless"]) r9:tag("td"):wikitext(total4Heroes["Colorless"]) r9:tag("td"):wikitext(total3Heroes["Colorless"]) local r9p5 = tbl:tag("tr") r9p5:tag("th"):wikitext("Total") r9p5:tag("td"):wikitext(totfocusHeroes) r9p5:tag("td"):wikitext(pity5Heroes["Total"]) r9p5:tag("td"):wikitext(total4Heroes["Total"]) r9p5:tag("td"):wikitext(total3Heroes["Total"]) local r10 = tbl:tag("tr") r10:tag("th") :wikitext("Rate for Orb color") :attr("rowspan",4) r10:tag("th"):wikitext("Red") local unitIsRed = (focusHeroes["Red"] + (3 * pity5Heroes["Red"] / pity5Heroes["Total"]) + (58 * total4Heroes["Red"] / total4Heroes["Total"]) + (36 * total3Heroes["Red"] / total3Heroes["Total"])) r10:tag("td"):wikitext(string.format("%.2f", focusHeroes["Red"] / unitIsRed * 100) .. "%") r10:tag("td"):wikitext(string.format("%.2f", 3 * pity5Heroes["Red"] / pity5Heroes["Total"] / unitIsRed * 100) .. "%") r10:tag("td"):wikitext(string.format("%.1f", 58 * total4Heroes["Red"] / total4Heroes["Total"] / unitIsRed * 100) .. "%") r10:tag("td"):wikitext(string.format("%.1f", 36 * total3Heroes["Red"] / total3Heroes["Total"] / unitIsRed * 100) .. "%") local r11 = tbl:tag("tr") local unitIsBlue = (focusHeroes["Blue"] + (3 * pity5Heroes["Blue"] / pity5Heroes["Total"]) + (58 * total4Heroes["Blue"] / total4Heroes["Total"]) + (36 * total3Heroes["Blue"] / total3Heroes["Total"])) r11:tag("th"):wikitext("Blue") r11:tag("td"):wikitext(string.format("%.2f", focusHeroes["Blue"] / unitIsBlue * 100) .. "%") r11:tag("td"):wikitext(string.format("%.2f", 3 * pity5Heroes["Blue"] / pity5Heroes["Total"] / unitIsBlue * 100) .. "%") r11:tag("td"):wikitext(string.format("%.1f", 58 * total4Heroes["Blue"] / total4Heroes["Total"] / unitIsBlue * 100) .. "%") r11:tag("td"):wikitext(string.format("%.1f", 36 * total3Heroes["Blue"] / total3Heroes["Total"] / unitIsBlue * 100) .. "%") local r12 = tbl:tag("tr") local unitIsGreen = (focusHeroes["Green"] + (3 * pity5Heroes["Green"] / pity5Heroes["Total"]) + (58 * total4Heroes["Green"] / total4Heroes["Total"]) + (36 * total3Heroes["Green"] / total3Heroes["Total"])) r12:tag("th"):wikitext("Green") r12:tag("td"):wikitext(string.format("%.2f", focusHeroes["Green"] / unitIsGreen * 100) .. "%") r12:tag("td"):wikitext(string.format("%.2f", 3 * pity5Heroes["Green"] / pity5Heroes["Total"] / unitIsGreen * 100) .. "%") r12:tag("td"):wikitext(string.format("%.1f", 58 * total4Heroes["Green"] / total4Heroes["Total"] / unitIsGreen * 100) .. "%") r12:tag("td"):wikitext(string.format("%.1f", 36 * total3Heroes["Green"] / total3Heroes["Total"] / unitIsGreen * 100) .. "%") local r13 = tbl:tag("tr") local unitIsColorless = (focusHeroes["Colorless"] + (3 * pity5Heroes["Colorless"] / pity5Heroes["Total"]) + (58 * total4Heroes["Colorless"] / total4Heroes["Total"]) + (36 * total3Heroes["Colorless"] / total3Heroes["Total"])) r13:tag("th"):wikitext("Colorless") r13:tag("td"):wikitext(string.format("%.2f", focusHeroes["Colorless"] / unitIsColorless * 100) .. "%") r13:tag("td"):wikitext(string.format("%.2f", 3 * pity5Heroes["Colorless"] / pity5Heroes["Total"] / unitIsColorless * 100) .. "%") r13:tag("td"):wikitext(string.format("%.1f", 58 * total4Heroes["Colorless"] / total4Heroes["Total"] / unitIsColorless * 100) .. "%") r13:tag("td"):wikitext(string.format("%.1f", 36 * total3Heroes["Colorless"] / total3Heroes["Total"] / unitIsColorless * 100) .. "%") local r14 = tbl:tag("tr") r14:tag("th") :wikitext("Failure to appear") :attr("rowspan",4) r14:tag("th"):wikitext("Red") r14:tag("td") :attr("colspan",4) :wikitext(string.format("%.3f%%", ((100-unitIsRed)/100)^5 * 100))

local r15 = tbl:tag("tr") r15:tag("th"):wikitext("Blue") r15:tag("td") :attr("colspan",4) :wikitext(string.format("%.3f%%", ((100-unitIsBlue)/100)^5 * 100))

local r16 = tbl:tag("tr") r16:tag("th"):wikitext("Green") r16:tag("td") :attr("colspan",4) :wikitext(string.format("%.3f%%", ((100-unitIsGreen)/100)^5 * 100))

local r17 = tbl:tag("tr") r17:tag("th"):wikitext("Colorless") r17:tag("td") :attr("colspan",4) :wikitext(string.format("%.3f%%", ((100-unitIsColorless)/100)^5 * 100))

return tbl end

return p