Przejdź do zawartości

Moduł:Rekordy sezon: Różnice pomiędzy wersjami

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
(Nie pokazano 8 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 2: Linia 2:


-- =========================================================
-- =========================================================
-- Module:Rekordy_sezon
-- Moduł:Rekordy_sezon
--
--
-- Rekordy drużyny w danym sezonie:
-- Jeden moduł dla różnych dyscyplin.
--  - najwyższe zwycięstwo dom / wyjazd
--  - najwyższa porażka dom / wyjazd
--  - najwięcej punktów zawodnika dom / wyjazd
--  - najwięcej minut dom / wyjazd
--  - najwięcej asyst dom / wyjazd
--  - najwięcej zbiórek dom / wyjazd
--  - najwyższy EVAL dom / wyjazd
--  - najwyższy +/- dom / wyjazd
--  - najdłuższa seria zwycięstw ogółem / dom / wyjazd
--  - najdłuższa seria porażek ogółem / dom / wyjazd
--
--
-- Dane pobierane są wyłącznie z istniejących wpisów Cargo.
-- Wywołanie:
--
-- {{#invoke:Rekordy_sezon|main
--  |sezon=2026/2027
--  |druzyna=Lech Poznań
--  |dyscyplina=piłka nożna
-- }}
--
-- lub:
--
-- {{#invoke:Rekordy_sezon|main
--  |sezon=2026/2027
--  |druzyna=Enea Basket Poznań
--  |dyscyplina=koszykówka
-- }}
-- =========================================================
 
 
-- =========================================================
-- FUNKCJE WSPÓLNE
-- =========================================================
-- =========================================================


function p.main(frame)
local function liczba(value)
 
    if value == nil or value == "" then
        return 0
    end
 
    value = tostring(value)
 
    value = mw.ustring.gsub(
        value,
        "%s+",
        ""
    )
 
    return tonumber(value) or 0
 
end
 
 
-- =========================================================
-- MINUTY
--
-- Obsługuje:
-- 32
-- 32.0
-- 32:15
-- 32:15.5
--
-- Do porównywania rekordów używamy sekund.
-- =========================================================
 
local function minutyNaSekundy(value)
 
    if value == nil or value == "" then
        return 0
    end
 
    value = tostring(value)
 
    value = mw.ustring.gsub(
        value,
        "%s+",
        ""
    )
 
    local minuty, sekundy =
        mw.ustring.match(
            value,
            "^(%d+):(%d+)$"
        )
 
    if minuty and sekundy then
 
        return
            tonumber(minuty) * 60 +
            tonumber(sekundy)
 
    end
 
    local liczbaMinut =
        tonumber(value)
 
    if liczbaMinut then
        return liczbaMinut * 60
    end
 
    return 0
 
end
 
 
-- =========================================================
-- FORMAT MINUT
-- =========================================================
 
local function formatMinut(sekundy)
 
    sekundy = tonumber(sekundy) or 0
 
    local minuty =
        math.floor(
            sekundy / 60
        )
 
    local sek =
        sekundy % 60
 
    if sek == 0 then
        return tostring(minuty) .. " min"
    end
 
    return
        tostring(minuty) ..
        ":" ..
        string.format(
            "%02d",
            sek
        ) ..
        " min"
 
end
 
 
local function escapeSQL(value)
 
    value = tostring(value or "")
 
    return mw.ustring.gsub(
        value,
        "'",
        "''"
    )
 
end
 
 
-- =========================================================
-- ROZPOZNANIE MIEJSCA MECZU
-- =========================================================
 
local function miejsceMeczu(row, druzyna)


     -- =====================================================
     local d1 =
    -- PARAMETRY
        tostring(row.druzyna1 or "")
    -- =====================================================


     local sezon = frame.args.sezon or ""
     local d2 =
    local druzyna = frame.args.druzyna or ""
        tostring(row.druzyna2 or "")


     if sezon == "" then
     if d1 == druzyna then
         return "'''Błąd:''' nie podano sezonu."
         return "dom"
     end
     end


     if druzyna == "" then
     if d2 == druzyna then
         return "'''Błąd:''' nie podano drużyny."
         return "wyjazd"
     end
     end


     local sezonSQL =
     return nil
        mw.ustring.gsub(sezon, "'", "''")
 
end
 
 
-- =========================================================
-- WYNIK MECZU
-- =========================================================
 
local function wynikMeczu(row)


     local druzynaSQL =
     local g1 =
         mw.ustring.gsub(druzyna, "'", "''")
         tonumber(row.gole1 or "")


    local g2 =
        tonumber(row.gole2 or "")
    if g1 ~= nil and g2 ~= nil then
        return g1, g2
    end


    -- =====================================================
    -- FUNKCJE POMOCNICZE
    -- =====================================================


     local function liczba(value)
     local wynik =
        tostring(row.wynik or "")


         if value == nil or value == "" then
    local a, b =
            return 0
         mw.ustring.match(
         end
            wynik,
            "(%d+)%s*:%s*(%d+)"
         )


        value = tostring(value)
    if a and b then
        value = mw.ustring.gsub(value, "%s+", "")


         return tonumber(value) or 0
         return
            tonumber(a),
            tonumber(b)


     end
     end




     local function wynikMeczu(row)
     return nil, nil


        local g1 = tonumber(row.gole1 or "")
end
        local g2 = tonumber(row.gole2 or "")


        if g1 and g2 then
            return g1, g2
        end


        local wynik = row.wynik or ""
-- =========================================================
-- WYNIK Z PERSPEKTYWY DRUŻYNY
-- =========================================================


        local a, b =
local function wynikZPerspektywy(row, druzyna)
            wynik:match("(%d+)%s*:%s*(%d+)")


         if a and b then
    local g1, g2 =
            return tonumber(a), tonumber(b)
         wynikMeczu(row)
        end


    if g1 == nil or g2 == nil then
         return nil, nil
         return nil, nil
    end
    local miejsce =
        miejsceMeczu(
            row,
            druzyna
        )
    if miejsce == "dom" then
        return g1, g2
    elseif miejsce == "wyjazd" then
        return g2, g1


     end
     end


    return nil, nil
end
-- =========================================================
-- NAZWA MECZU
-- =========================================================
local function nazwaMeczu(row)
    local d1 =
        tostring(row.druzyna1 or "")
    local d2 =
        tostring(row.druzyna2 or "")
    local strona =
        tostring(row.strona_meczu or "")
    local tekst =
        d1 ..
        " – " ..
        d2
    if strona ~= "" then
        return
            "[[" ..
            strona ..
            "|" ..
            tekst ..
            "]]"
    end
    return tekst
end
-- =========================================================
-- DODAWANIE REKORDU
--
-- KLUCZOWA POPRAWKA:
--
-- zapisujemy wartość rekordu bezpośrednio w item.wartosc.
--
-- Dzięki temu nie ma już:
-- attempt to compare nil with number
-- =========================================================
local function dodajRekord(
    tabela,
    miejsce,
    wartosc,
    item
)
    if wartosc == nil then
        return
    end
    wartosc =
        tonumber(wartosc)
    if wartosc == nil then
        return
    end
    item.wartosc =
        wartosc
    local lista =
        tabela[miejsce]
    if #lista == 0 then
        table.insert(
            lista,
            item
        )
        return
    end
    local obecna =
        tonumber(
            lista[1].wartosc
        ) or 0
    if wartosc > obecna then
        tabela[miejsce] = {
            item
        }
    elseif wartosc == obecna then
        table.insert(
            lista,
            item
        )


     local function miejsceMeczu(row)
     end


        local d1 = row.druzyna1 or ""
end
        local d2 = row.druzyna2 or ""


        if d1 == druzyna then
            return "dom"
        end


        if d2 == druzyna then
-- =========================================================
            return "wyjazd"
-- FORMAT REKORDÓW MECZOWYCH
        end
-- =========================================================


        return nil
local function tekstMeczow(lista)


    if not lista or #lista == 0 then
        return "—"
     end
     end


    local wynik = {}


     -- =====================================================
     for _, item in ipairs(lista) do
    -- NAZWA MECZU
 
    --
        local roznica =
    -- WAŻNE:
            tonumber(
    -- zawsze zachowujemy faktyczną kolejność gospodarze –
                item.roznica or 0
    -- goście.
            ) or 0
    -- =====================================================


    local function nazwaMeczu(row)
        local roznicaTekst


         local d1 = row.druzyna1 or ""
         if roznica >= 0 then
        local d2 = row.druzyna2 or ""
        local strona = row.strona_meczu or ""


        local tekst =
            roznicaTekst =
            d1 .. " " .. d2
                "+" ..
                tostring(roznica)


         if strona ~= "" then
         else


             return "[[" ..
             roznicaTekst =
                 strona ..
                 tostring(roznica)
                "|" ..
                tekst ..
                "]]"


         end
         end


         return tekst
 
         table.insert(
            wynik,
 
            item.tekst ..
            " (" ..