Module:Build bracket/Logic and Module:Build bracket/Logic/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
imported>Pbrks
allow fraction scores (e.g. ½)
 
imported>Pbrks
No edit summary
 
Line 79: Line 79:


     return s
     return s
end
-- Numeric tiebreaker inside parentheses, e.g., "2 (3)" -> 3; nil if none.
local function parenTie(s)
    if s == nil then return nil end
    local str = tostring(s)
    local last
    for m in str:gmatch("%(([%d%.]+)%)") do
        last = tonumber(m)
    end
    return last
end
end


Line 266: Line 277:
                     end
                     end
                     if allNumeric then
                     if allNumeric then
                         local best, bestIdx, tie
                         local bestMain, bestIdx, bestTB, tie = nil, nil, nil, false
                        for _, i in ipairs(members) do
for _, i in ipairs(members) do
                            local v = legNums[i][l]
    local v = legNums[i][l]
                            if best == nil then
    local raw = state.entries[j][i].score and state.entries[j][i].score[l]
                                best, bestIdx, tie = v, i, false
    local tb  = parenTie(raw) or 0
                            else
                                if (modeLow and v < best) or (not modeLow and v > best) then
    if bestMain == nil then
                                    best, bestIdx, tie = v, i, false
        bestMain, bestIdx, bestTB, tie = v, i, tb, false
                                elseif v == best then
    else
                                    tie = true
        if (modeLow and v < bestMain) or (not modeLow and v > bestMain) then
                                end
            bestMain, bestIdx, bestTB, tie = v, i, tb, false
                            end
        elseif v == bestMain then
                        end
            if (modeLow and tb < bestTB) or (not modeLow and tb > bestTB) then
                        if not tie and bestIdx then
                bestMain, bestIdx, bestTB, tie = v, i, tb, false
                            wins[bestIdx] = (wins[bestIdx] or 0) + 1
            elseif tb == bestTB then
                        end
                tie = true
            end
        end
    end
end
if not tie and bestIdx then
    wins[bestIdx] = (wins[bestIdx] or 0) + 1
end
                     end
                     end
                 end
                 end
Line 393: Line 412:
             if not aggOnly then
             if not aggOnly then
                 -- iterate to the max leg count in the group
                 -- iterate to the max leg count in the group
                local maxL = 0
local maxL = 0
                for _, i in ipairs(members) do
for _, i in ipairs(members) do
                    local L = teamLegs(j, i)
    local L = teamLegs(j, i)
                    if L > maxL then
    if L > maxL then maxL = L end
                        maxL = L
end
                    end
                end
for l = 1, maxL do
 
    local allNumeric = true
                for l = 1, maxL do
    local bestMain, bestIdx, bestTB, tie = nil, nil, nil, false
                    local allNumeric = true
                    local best, bestIdx, tie
    for _, i in ipairs(members) do
                    for _, i in ipairs(members) do
        local v = perLegNum[i] and perLegNum[i][l]
                        local v = perLegNum[i] and perLegNum[i][l]
        if v == nil then
                        if v == nil then
            allNumeric = false
                            allNumeric = false
            break
                            break
        end
                        end
                        if best == nil then
        -- paren tiebreak (treat missing as 0 so "2 (3)" beats "2")
                            best, bestIdx, tie = v, i, false
        local raw = state.entries[j][i].score and state.entries[j][i].score[l]
                        else
        local tb  = parenTie(raw) or 0
                            if (modeLow and v < best) or (not modeLow and v > best) then
                                best, bestIdx, tie = v, i, false
        if bestMain == nil then
                            elseif v == best then
            bestMain, bestIdx, bestTB, tie = v, i, tb, false
                                tie = true
        else
                            end
            if (modeLow and v < bestMain) or (not modeLow and v > bestMain) then
                        end
                bestMain, bestIdx, bestTB, tie = v, i, tb, false
                    end
            elseif v == bestMain then
 
                if (modeLow and tb < bestTB) or (not modeLow and tb > bestTB) then
                    if allNumeric and not tie and bestIdx then
                    bestMain, bestIdx, bestTB, tie = v, i, tb, false
                        -- set the winner bold + increment wins
                elseif tb == bestTB then
                        local e = state.entries[j][bestIdx]
                    tie = true
                        e.score.weight[l] = "bold"
                end
                        e.wins = (e.wins or 0) + 1
            end
                        -- normalize others on this leg
        end
                        for _, i in ipairs(members) do
    end
                            if i ~= bestIdx then
                                state.entries[j][i].score.weight[l] = "normal"
    if allNumeric and not tie and bestIdx then
                            end
        local e = state.entries[j][bestIdx]
                        end
        e.score.weight[l] = "bold"
                    else
        e.wins = (e.wins or 0) + 1
                        -- no unique winner: normalize everyone for this leg
        for _, i in ipairs(members) do
                        for _, i in ipairs(members) do
            if i ~= bestIdx then
                            state.entries[j][i].score.weight[l] = "normal"
                state.entries[j][i].score.weight[l] = "normal"
                        end
            end
                    end
        end
                end
    else
        for _, i in ipairs(members) do
            state.entries[j][i].score.weight[l] = "normal"
        end
    end
end
             end
             end