Przejdź do zawartości

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

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
Linia 4: Linia 4:
-- Moduł:Rekordy_sezon
-- Moduł:Rekordy_sezon
--
--
-- Wspólny moduł rekordów sezonu.
-- Obsługiwane dyscypliny:
--  koszykowka
--  pilka nozna
--
--
-- Wywołanie:
-- Wywołanie:
Linia 11: Linia 13:
--  |sezon=2026/2027
--  |sezon=2026/2027
--  |druzyna=Lech Poznań
--  |druzyna=Lech Poznań
--  |dyscyplina=piłka nożna
--  |dyscyplina=pilka nozna
-- }}
-- }}
--
--
-- Obsługiwane dyscypliny:
-- DANE:
--   - koszykówka
-- Mecze
--   - piłka nożna
-- UdzialZawodnika
-- Strzelcy
--
--
-- WAŻNE:
-- Moduł korzysta wyłącznie z mw.ext.cargo.query().
-- Nie używa SELECT.
-- =========================================================
-- =========================================================


Linia 24: Linia 30:
-- FUNKCJE WSPÓLNE
-- FUNKCJE WSPÓLNE
-- =========================================================
-- =========================================================
local function escapeSQL(value)
    value = value or ""
    return mw.ustring.gsub(
        tostring(value),
        "'",
        "''"
    )
end


local function liczba(value)
local function liczba(value)
Linia 45: Linia 38:


     value = tostring(value)
     value = tostring(value)
    value = mw.ustring.gsub(value, "%s+", "")
    return tonumber(value) or 0


     value = mw.ustring.gsub(
end
        value,
 
        "%s+",
 
        ""
local function esc(value)
    )
 
     value = tostring(value or "")


     return tonumber(value) or 0
     return mw.ustring.gsub(value, "'", "''")


end
end
Linia 59: Linia 56:
-- =========================================================
-- =========================================================
-- WYNIK MECZU
-- WYNIK MECZU
--
-- WAŻNE:
-- funkcja jest lokalna i dostępna dla całego modułu.
-- =========================================================
-- =========================================================


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


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


     local g2 = tonumber(
     if row.gole1 ~= nil and row.gole2 ~= nil
        row.gole2 or ""
      and row.gole1 ~= "" and row.gole2 ~= "" then
    )


    if g1 and g2 then
         return g1, g2
         return g1, g2
     end
     end




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


     local a, b =
     local a, b =
         wynik:match(
         mw.ustring.match(
            wynik,
             "(%d+)%s*:%s*(%d+)"
             "(%d+)%s*:%s*(%d+)"
         )
         )


     if a and b then
     if a and b then
        return tonumber(a), tonumber(b)
    end


        return
     return nil, nil
            tonumber(a),
            tonumber(b)
 
    end
 
 
     return nil, nil


end
end
Linia 107: Linia 92:
-- =========================================================
-- =========================================================


local function miejsceMeczu(
local function miejsceMeczu(row, druzyna)
    row,
    druzyna
)
 
    local d1 =
        row.druzyna1 or ""
 
    local d2 =
        row.druzyna2 or ""


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


     if d1 == druzyna then
     if d1 == druzyna then
         return "dom"
         return "dom"
     end
     end


     if d2 == druzyna then
     if d2 == druzyna then
         return "wyjazd"
         return "wyjazd"
     end
     end


     return nil
     return nil
Linia 140: Linia 116:
local function nazwaMeczu(row)
local function nazwaMeczu(row)


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


     local tekst =
     local tekst =
         d1 .. " – " .. d2
         d1 .. " – " .. d2
    local strona =
        row.strona_meczu or ""


     if strona ~= "" then
     if strona ~= "" then
Linia 163: Linia 132:


     end
     end


     return tekst
     return tekst
Linia 171: Linia 139:


-- =========================================================
-- =========================================================
-- PARSOWANIE MINUTY GOLA
-- DODAWANIE REKORDU
--
-- Obsługujemy:
--
-- 14
-- 45
-- 45+2
-- 90+4
-- 105
-- 120+1
--
-- Zwracamy:
--  minuta podstawowa
--  doliczony czas
-- =========================================================
-- =========================================================


local function parsujMinute(value)
local function dodajRekord(tabela, miejsce, wartosc, item)


     if value == nil or value == "" then
     if not tabela[miejsce] then
         return nil, 0
         tabela[miejsce] = {}
     end
     end


    local lista = tabela[miejsce]


    value =
        tostring(value)


    if #lista == 0 then


    value =
         table.insert(lista, item)
         mw.ustring.gsub(
            value,
            "%s+",
            ""
        )


        return


     local minuta,
     end
          doliczona =
        value:match(
            "^(%d+)%+(%d+)$"
        )




     if minuta then
     local obecna =
        tonumber(lista[1].wartosc) or 0


        return
            tonumber(minuta),
            tonumber(doliczona)


     end
     if wartosc > obecna then
 
        tabela[miejsce] = {
            item
        }


    elseif wartosc == obecna then


    minuta =
         table.insert(
         value:match(
             lista,
             "^(%d+)"
            item
         )
         )
    if minuta then
        return
            tonumber(minuta),
            0


     end
     end
    return nil, 0


end
end
Linia 243: Linia 183:


-- =========================================================
-- =========================================================
-- PRZEDZIAŁ CZASOWY GOLA
-- KOSZYKÓWKA
-- =========================================================
-- =========================================================


local function przedzialGola(value)
local function rekordyKoszykowka(
    sezon,
    druzyna
)


     local minuta,
     -- =====================================================
          doliczona =
    -- MECZE
        parsujMinute(value)
    -- =====================================================


    local pola = table.concat({


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


    }, ",")


    -- 45+ oraz 90+ itd.
    if minuta == 45 and doliczona > 0 then
        return "45+"
    end


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


    if minuta == 90 and doliczona > 0 then
                orderBy =
        return "90+"
                    "Mecze.data ASC",
    end
 


    if minuta == 105 and doliczona > 0 then
                limit = 5000
         return "105+"
            }
    end
         )




     if minuta == 120 and doliczona > 0 then
     if not mecze or #mecze == 0 then
        return "120+"
    end


        return
            "''Brak meczów dla tej drużyny w podanym sezonie.''"


    if minuta >= 1 and minuta <= 15 then
        return "0–15"
     end
     end




     if minuta >= 16 and minuta <= 30 then
     local zwyciestwa = {
         return "16–30"
        dom = {},
     end
         wyjazd = {}
     }


    local porazki = {
        dom = {},
        wyjazd = {}
    }


    if minuta >= 31 and minuta <= 45 then
        return "31–45"
    end


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


     if minuta >= 46 and minuta <= 60 then
     for _, row in ipairs(mecze) do
        return "46–60"
    end
 


    if minuta >= 61 and minuta <= 75 then
        local g1, g2 =
        return "61–75"
            wynikMeczu(row)
    end


        local miejsce =
            miejsceMeczu(row, druzyna)


    if minuta >= 76 and minuta <= 90 then
        if g1 and g2 and miejsce then
        return "76–90"
    end


            local zdobyte
            local stracone


    if minuta >= 91 and minuta <= 105 then
            if miejsce == "dom" then
        return "91–105"
    end


                zdobyte = g1
                stracone = g2


    if minuta >= 106 and minuta <= 120 then
            else
        return "106–120"
    end


                zdobyte = g2
                stracone = g1


    if minuta > 120 then
            end
        return "120+"
    end




    return nil
            local roznica =
                zdobyte - stracone


end


            local item = {


-- =========================================================
                tekst =
-- DODANIE REKORDU DO LISTY
                    nazwaMeczu(row),
-- =========================================================


local function dodajRekord(
                wynik =
    tabela,
                    tostring(g1) ..
    miejsce,
                    ":" ..
    wartosc,
                    tostring(g2),
    item
)


    local lista =
                roznica =
        tabela[miejsce]
                    roznica,


                wartosc =
                    math.abs(roznica)


    if not lista then
            }


        tabela[miejsce] = {}


        lista =
             if roznica > 0 then
             tabela[miejsce]


    end
                dodajRekord(
                    zwyciestwa,
                    miejsce,
                    roznica,
                    item
                )


            elseif roznica < 0 then


    if #lista == 0 then
                dodajRekord(
                    porazki,