local public = local private =
-- Removes leading and trailing spaces from stringsfunction private.trimWhitespace(str) local whitespace = local _start = 1 while (whitespace[str:sub(_start, _start)]) do _start = _start + 1 end local _end = str:len while (whitespace[str:sub(_end, _end)]) do _end = _end - 1 end return str:sub(_start, _end)end
-- Checks if a table has a specific keyfunction private.hasKey(_table, key) return _table[key] ~= nilend
-- Gets a specific item from a table, with a fallback if the table doesn't have that keyfunction private.getValue(_table, key, fallback) if private.hasKey(_table, key) then return _table[key] else return fallback endend
-- Processes a csv row into a table and returns itfunction private.processCsv(csv) local retval = for arg in csv:gmatch("([^,]+)") do table.insert(retval, private.trimWhitespace(arg)) end return retvalend
-- Get the arguments from a framefunction private.parseArgs(frame) if private.getValue(frame.args, "external_args", false) then return frame:getParent.args end return frame.argsend
-- Converts a difficulty number into a format that handles sorting better for + difficultiesfunction public.SortableDifficulty(frame) local args = private.parseArgs(frame) if private.hasKey(args, 1)
'number' then return diff end diff = private.trimWhitespace(diff) if diff:sub(#diff, #diff)
-- Converts a version number into a format that handles sorting betterfunction public.SortableVersion(frame) local args = private.parseArgs(frame) if private.hasKey(args, 1)
function private.startsWith(String, Start) return (string.sub(String, 1, string.len(Start))
function private.toSet(list) local out = for i, k in ipairs(list) do out[k] = true end return outend
local normed_stats =
-- Calculates Lv 1-30 FRAG/STEP/OVER given partner data from partnerStats.jsonfunction private.calculateStat(ps, stat) local statIncStr = 'awakened' .. (stat:gsub("^%l", string.upper)) .. 'Increment' local statAllLv = local stat1 = ps[stat][1] local stat20 = ps[stat][2] local statInc = 0 if ps['hasAwakening'] then statInc = ps[statIncStr] end for lv = 1, 20, 1 do statAllLv[lv] = stat1 + normed_stats[lv] * (stat20 - stat1) end for lv = 21, 30, 1 do statAllLv[lv] = stat20 + (lv - 20) * statInc end
return statAllLvend
-- Calculates Lv 1-30 PROG given partner and data from partnerStats.jsonfunction private.calculateProg(ps, stat) local overAllLv = private.calculateStat(ps, 'over') local progAllLv = if stat
'progfrag' then local fragAllLv = private.calculateStat(ps, 'frag') for lv = 1, 30, 1 do progAllLv[lv] = overAllLv[lv] * fragAllLv[lv]/50 end elseif stat
'progabsolute' then local stepAllLv = private.calculateStat(ps, 'step') local fragAllLv = private.calculateStat(ps, 'frag') for lv = 1, 30, 1 do local frag = fragAllLv[lv] local step = stepAllLv[lv] local over = overAllLv[lv] progAllLv[lv] = math.max(0, over - math.abs(math.abs(over-frag) - math.abs(over-step))) end end return progAllLvend
-- Generates rows (Template:ExactStatTableRow) for use by Template:ExactStatTable-- Stats implemented: frag, step, over, progstep, progfrag, progweaker, progabsolutefunction public.ExactStatTableRows(frame) local args = private.parseArgs(frame) -- local partnerStats = JsonUtils.jsonToObj("User:GKWS/partnerStats") local partnerStats_ = mw.loadJsonData("Module:YYSandbox/partnerStats.json") local partnerStats = for partner, ps in pairs(partnerStats_) do partnerStats[partner] = ps end local stat = private.trimWhitespace(private.getValue(args, 'stat', false)) local isProgStat = private.startsWith(stat, 'prog') local playRating = tonumber(private.trimWhitespace(private.getValue(args, 'playrating', '10'))) local condense = private.trimWhitespace(private.getValue(args, 'condense', )) ~= local condenseLvs = private.toSet -- partners with (non-random) stat-varying abilities partnerStats['Tairitsu (Tempest) [max]'] = partnerStats['Hikari (Fatalis) [max]'] = partnerStats['Vita [max bonus]'] = partnerStats['Mika Yurisaki [max bonus]'] = partnerStats['Ilith [awakened bonus]'] = -- partners that fail BYD challenge bydFailPartners = private.toSet -- partners that use double stamina doubleStaminaPartners = private.toSet -- partners with min level 20 minLv20Partners = private.toSet local rows = for partner, ps in pairs(partnerStats) do local ps = partnerStats[partner] local minLv = 1 local maxLv = 20 if minLv20Partners[partner] then minLv = 20 end if ps['hasAwakening'] then maxLv = 30 end local staminaFactor = 1 if (doubleStaminaPartners[partner] and stat ~= 'frag') then staminaFactor = 0.5 end local trackLostFactor = 1 if (isProgStat or stat
return table.concat(rows, "\n")end
return public