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 3 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 4: Linia 4:
-- Moduł:Rekordy_sezon
-- Moduł:Rekordy_sezon
--
--
-- Obsługiwane dyscypliny:
-- Jeden moduł dla różnych dyscyplin.
--  koszykowka
--  pilka nozna
--
--
-- Wywołanie:
-- Wywołanie:
Linia 13: Linia 11:
--  |sezon=2026/2027
--  |sezon=2026/2027
--  |druzyna=Lech Poznań
--  |druzyna=Lech Poznań
--  |dyscyplina=pilka nozna
--  |dyscyplina=piłka nożna
-- }}
-- }}
--
--
-- DANE:
-- lub:
-- Mecze
-- UdzialZawodnika
-- Strzelcy
--
--
-- WAŻNE:
-- {{#invoke:Rekordy_sezon|main
-- Moduł korzysta wyłącznie z mw.ext.cargo.query().
-- |sezon=2026/2027
-- Nie używa SELECT.
-- |druzyna=Enea Basket Poznań
--  |dyscyplina=koszykówka
-- }}
-- =========================================================
-- =========================================================


Linia 38: Linia 35:


     value = tostring(value)
     value = tostring(value)
     value = mw.ustring.gsub(value, "%s+", "")
 
     value = mw.ustring.gsub(
        value,
        "%s+",
        ""
    )


     return tonumber(value) or 0
     return tonumber(value) or 0
Linia 45: Linia 47:




local function esc(value)
-- =========================================================
-- MINUTY
--
-- Obsługuje:
-- 32
-- 32.0
-- 32:15
-- 32:15.5
--
-- Do porównywania rekordów używamy sekund.
-- =========================================================


    value = tostring(value or "")
local function minutyNaSekundy(value)


     return mw.ustring.gsub(value, "'", "''")
     if value == nil or value == "" then
        return 0
    end


end
    value = tostring(value)


    value = mw.ustring.gsub(
        value,
        "%s+",
        ""
    )


-- =========================================================
    local minuty, sekundy =
-- WYNIK MECZU
        mw.ustring.match(
-- =========================================================
            value,
            "^(%d+):(%d+)$"
        )


local function wynikMeczu(row)
    if minuty and sekundy then


    local g1 = liczba(row.gole1)
        return
    local g2 = liczba(row.gole2)
            tonumber(minuty) * 60 +
            tonumber(sekundy)


     if row.gole1 ~= nil and row.gole2 ~= nil
     end
      and row.gole1 ~= "" and row.gole2 ~= "" then


         return g1, g2
    local liczbaMinut =
         tonumber(value)


    if liczbaMinut then
        return liczbaMinut * 60
     end
     end


    return 0


    local wynik = tostring(row.wynik or "")
end


     local a, b =
 
         mw.ustring.match(
-- =========================================================
             wynik,
-- FORMAT MINUT
            "(%d+)%s*:%s*(%d+)"
-- =========================================================
 
local function formatMinut(sekundy)
 
    sekundy = tonumber(sekundy) or 0
 
     local minuty =
         math.floor(
             sekundy / 60
         )
         )


     if a and b then
    local sek =
         return tonumber(a), tonumber(b)
        sekundy % 60
 
     if sek == 0 then
         return tostring(minuty) .. " min"
     end
     end


     return nil, nil
     return
        tostring(minuty) ..
        ":" ..
        string.format(
            "%02d",
            sek
        ) ..
        " min"
 
end
 
 
local function escapeSQL(value)
 
    value = tostring(value or "")
 
    return mw.ustring.gsub(
        value,
        "'",
        "''"
    )


end
end
Linia 89: Linia 145:


-- =========================================================
-- =========================================================
-- MIEJSCE MECZU
-- ROZPOZNANIE MIEJSCA MECZU
-- =========================================================
-- =========================================================


local function miejsceMeczu(row, druzyna)
local function miejsceMeczu(row, druzyna)


     local d1 = tostring(row.druzyna1 or "")
     local d1 =
     local d2 = tostring(row.druzyna2 or "")
        tostring(row.druzyna1 or "")
 
     local d2 =
        tostring(row.druzyna2 or "")


     if d1 == druzyna then
     if d1 == druzyna then
Linia 111: Linia 170:


-- =========================================================
-- =========================================================
-- NAZWA MECZU
-- WYNIK MECZU
-- =========================================================
-- =========================================================


local function nazwaMeczu(row)
local function wynikMeczu(row)


     local d1 = tostring(row.druzyna1 or "")
     local g1 =
    local d2 = tostring(row.druzyna2 or "")
        tonumber(row.gole1 or "")
    local strona = tostring(row.strona_meczu or "")


     local tekst =
     local g2 =
         d1 .. " " .. d2
         tonumber(row.gole2 or "")


     if strona ~= "" then
     if g1 ~= nil and g2 ~= nil then
        return g1, g2
    end


         return "[[" ..
 
             strona ..
    local wynik =
             "|" ..
         tostring(row.wynik or "")
             tekst ..
 
             "]]"
    local a, b =
        mw.ustring.match(
             wynik,
             "(%d+)%s*:%s*(%d+)"
        )
 
    if a and b then
 
        return
             tonumber(a),
             tonumber(b)


     end
     end


     return tekst
 
     return nil, nil


end
end
Linia 139: Linia 210:


-- =========================================================
-- =========================================================
-- DODAWANIE REKORDU
-- WYNIK Z PERSPEKTYWY DRUŻYNY
-- =========================================================
-- =========================================================


local function dodajRekord(tabela, miejsce, wartosc, item)
local function wynikZPerspektywy(row, druzyna)


     if not tabela[miejsce] then
    local g1, g2 =
         tabela[miejsce] = {}
        wynikMeczu(row)
 
     if g1 == nil or g2 == nil then
         return nil, nil
     end
     end


     local lista = tabela[miejsce]
     local miejsce =
        miejsceMeczu(
            row,
            druzyna
        )


    if miejsce == "dom" then


    if #lista == 0 then
        return g1, g2


        table.insert(lista, item)
    elseif miejsce == "wyjazd" then


         return
         return g2, g1


     end
     end


    return nil, nil


    local obecna =
end
        tonumber(lista[1].wartosc) or 0




     if wartosc > obecna then
-- =========================================================
-- 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


        tabela[miejsce] = {
            item
        }


     elseif wartosc == obecna then
     if strona ~= "" then


         table.insert(
         return
             lista,
            "[[" ..
             item
            strona ..
        )
             "|" ..
             tekst ..
            "]]"


     end
     end
    return tekst


end
end
Linia 183: Linia 281:


-- =========================================================
-- =========================================================
-- KOSZYKÓWKA
-- 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 rekordyKoszykowka(
local function dodajRekord(
     sezon,
     tabela,
     druzyna
     miejsce,
    wartosc,
    item
)
)


     -- =====================================================
     if wartosc == nil then
    -- MECZE
        return
     -- =====================================================
     end


     local pola = table.concat({
     wartosc =
        tonumber(wartosc)


        "Mecze.id=mecz",
    if wartosc == nil then
        "Mecze.data=data",
         return
        "Mecze.sezon=sezon",
    end
        "Mecze.rozgrywki=rozgrywki",
        "Mecze.druzyna1=druzyna1",
        "Mecze.druzyna2=druzyna2",
        "Mecze.gole1=gole1",
        "Mecze.gole2=gole2",
         "Mecze.wynik=wynik",
        "Mecze.strona_meczu=strona_meczu"


     }, ",")
     item.wartosc =
        wartosc


    local lista =
        tabela[miejsce]


     local mecze =
     if #lista == 0 then
        mw.ext.cargo.query(
            "Mecze",
            pola,
            {
                where =
                    "(Mecze.druzyna1='" ..
                    esc(druzyna) ..
                    "' OR Mecze.druzyna2='" ..
                    esc(druzyna) ..
                    "')" ..
                    " AND Mecze.sezon='" ..
                    esc(sezon) ..
                    "'",


                orderBy =
        table.insert(
                    "Mecze.data ASC",
            lista,
            item
        )


                limit = 5000
         return
            }
         )


    end


    if not mecze or #mecze == 0 then


         return
    local obecna =
             "''Brak meczów dla tej drużyny w podanym sezonie.''"
         tonumber(
             lista[1].wartosc
        ) or 0


    end


    if wartosc > obecna then


    local zwyciestwa = {
        tabela[miejsce] = {
        dom = {},
            item
         wyjazd = {}
         }
    }


     local porazki = {
     elseif wartosc == obecna then
        dom = {},
        wyjazd = {}
    }


        table.insert(
            lista,
            item
        )


     -- =====================================================
     end
    -- PRZETWARZANIE MECZÓW
    -- =====================================================


    for _, row in ipairs(mecze) do
end


        local g1, g2 =
            wynikMeczu(row)


        local miejsce =
-- =========================================================
            miejsceMeczu(row, druzyna)
-- FORMAT REKORDÓW MECZOWYCH
-- =========================================================


        if g1 and g2 and miejsce then
local function tekstMeczow(lista)


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


            if miejsce == "dom" then
    local wynik = {}


                zdobyte = g1
    for _, item in ipairs(lista) do
                stracone = g2


             else
        local roznica =
             tonumber(
                item.roznica or 0
            ) or 0