Przejdź do zawartości

Moduł:HistoriaWystepow: Różnice pomiędzy wersjami

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
Linia 49: Linia 49:


     -- ==========================================
     -- ==========================================
     -- PODSUMOWANIE
     -- PODSUMOWANIE - WSZYSTKIE MECZE
    -- ==========================================
 
    local suma = {
        wystepy = 0,
        zwyciestwa = 0,
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }
 
    -- ==========================================
    -- PODSUMOWANIE - DOM
     -- ==========================================
     -- ==========================================


     local wystepy = #rows
     local dom = {
    local zwyciestwa = 0
        wystepy = 0,
    local porazki = 0
        zwyciestwa = 0,
    local remisy = 0
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }


     local punkty = 0
     -- ==========================================
     local sumaMinut = 0
     -- PODSUMOWANIE - WYJAZD
     local sumaEval = 0
     -- ==========================================
    local sumaPlusMinus = 0


     for _, row in ipairs(rows) do
     local wyjazd = {
        wystepy = 0,
        zwyciestwa = 0,
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }
 
    -- ==========================================
    -- FUNKCJA OKREŚLAJĄCA WYNIK
    -- ==========================================


        punkty = punkty + tonumber(row.gol or 0)
    local function okreslWynik(row)
        sumaMinut = sumaMinut + tonumber(row.minuty or 0)
        sumaEval = sumaEval + tonumber(row.eval or 0)
        sumaPlusMinus = sumaPlusMinus + tonumber(row.plusminus or 0)


         local d1 = row.druzyna1 or ""
         local d1 = row.druzyna1 or ""
Linia 76: Linia 106:
         local g1, g2 = wynikMeczu:match("(%d+)%s*:%s*(%d+)")
         local g1, g2 = wynikMeczu:match("(%d+)%s*:%s*(%d+)")


         if g1 and g2 then
         if not g1 or not g2 then
            return nil
        end
 
        g1 = tonumber(g1)
        g2 = tonumber(g2)
 
        if druzyna == d1 then
 
            if g1 > g2 then
                return "W"
            elseif g1 < g2 then
                return "P"
            else
                return "R"
            end
 
        elseif druzyna == d2 then
 
            if g2 > g1 then
                return "W"
            elseif g2 < g1 then
                return "P"
            else
                return "R"
            end
 
        end
 
        return nil
    end
 
    -- ==========================================
    -- FUNKCJA DODAJĄCA MECZ DO PODSUMOWANIA
    -- ==========================================


            g1 = tonumber(g1)
    local function dodajDoPodsumowania(stat, row)
            g2 = tonumber(g2)


            if druzyna == d1 then
        stat.wystepy = stat.wystepy + 1


                if g1 > g2 then
        stat.punkty = stat.punkty + tonumber(row.gol or 0)
                    zwyciestwa = zwyciestwa + 1
        stat.minuty = stat.minuty + tonumber(row.minuty or 0)
                elseif g1 < g2 then
        stat.eval = stat.eval + tonumber(row.eval or 0)
                    porazki = porazki + 1
        stat.plusminus = stat.plusminus + tonumber(row.plusminus or 0)
                else
                    remisy = remisy + 1
                end


            elseif druzyna == d2 then
        local wynik = okreslWynik(row)


                if g2 > g1 then
        if wynik == "W" then
                    zwyciestwa = zwyciestwa + 1
            stat.zwyciestwa = stat.zwyciestwa + 1
                elseif g2 < g1 then
        elseif wynik == "P" then
                    porazki = porazki + 1
            stat.porazki = stat.porazki + 1
                else
        elseif wynik == "R" then
                    remisy = remisy + 1
            stat.remisy = stat.remisy + 1
                end
        end
    end
 
    -- ==========================================
    -- PRZEJŚCIE PRZEZ MECZE
    -- ==========================================
 
    for _, row in ipairs(rows) do
 
        -- Wszystkie mecze
        dodajDoPodsumowania(suma, row)
 
        local d1 = row.druzyna1 or ""
        local d2 = row.druzyna2 or ""
        local druzyna = row.druzyna or ""


             end
        -- Dom / wyjazd
        if druzyna == d1 then
             dodajDoPodsumowania(dom, row)
        elseif druzyna == d2 then
            dodajDoPodsumowania(wyjazd, row)
         end
         end
     end
     end


Linia 109: Linia 188:
     -- ==========================================
     -- ==========================================


     local godziny = math.floor(sumaMinut / 60)
     local function formatujMinuty(minuty)
    local minuty = sumaMinut % 60


    local sumaMinutFormat = string.format(
        local godziny = math.floor(minuty / 60)
        "%d:%02d",
        local min = minuty % 60
        godziny,
 
         minuty
        return string.format("%d:%02d", godziny, min)
     )
    end
 
    -- ==========================================
    -- FORMAT PODSUMOWANIA
    -- ==========================================
 
    local function podsumowanie(stat)
 
         return
            "'''"
            .. stat.wystepy
            .. "''' występów • "
            .. "'''"
            .. stat.zwyciestwa
            .. "''' zwycięstw • "
            .. "'''"
            .. stat.porazki
            .. "''' porażek"
            .. (stat.remisy > 0 and
                " • '''" .. stat.remisy .. "''' remisów"
                or "")
            .. " • '''"
            .. stat.punkty
            .. "''' pkt"
            .. " • '''"
            .. formatujMinuty(stat.minuty)
            .. "''' min"
            .. " • EVAL '''"
            .. stat.eval
            .. "'''"
            .. " • +/- '''"
            .. stat.plusminus
            .. "'''"
     end


     -- ==========================================
     -- ==========================================
Linia 125: Linia 236:


     table.insert(wynik, "== Historia występów ==")
     table.insert(wynik, "== Historia występów ==")
    table.insert(wynik, "")
    -- ==========================================
    -- PODSUMOWANIE
    -- ==========================================
    table.insert(wynik, "=== Podsumowanie ===")
    table.insert(wynik, "")
    table.insert(
        wynik,
        "'''Wszystkie spotkania:''' " .. podsumowanie(suma)
    )
    table.insert(
        wynik,
        "'''Mecze domowe:''' " .. podsumowanie(dom)
    )
    table.insert(
        wynik,
        "'''Mecze wyjazdowe:''' " .. podsumowanie(wyjazd)
    )
     table.insert(wynik, "")
     table.insert(wynik, "")


Linia 136: Linia 271:
     )
     )


     table.insert(wynik, '! colspan="2" | Występy')
     table.insert(wynik, "!")
    table.insert(wynik, "! Wszystkie")
    table.insert(wynik, "! Dom")
    table.insert(wynik, "! Wyjazd")
 
    table.insert(wynik, "|-")
 
    table.insert(wynik, "! Występy")
    table.insert(wynik, "| '''" .. suma.wystepy .. "'''")
    table.insert(wynik, "| " .. dom.wystepy)
    table.insert(wynik, "| " .. wyjazd.wystepy)
 
    table.insert(wynik, "|-")
 
     table.insert(wynik, "! Zwycięstwa")
     table.insert(wynik, "! Zwycięstwa")
    table.insert(wynik, "| '''" .. suma.zwyciestwa .. "'''")
    table.insert(wynik, "| " .. dom.zwyciestwa)
    table.insert(wynik, "| " .. wyjazd.zwyciestwa)
    table.insert(wynik, "|-")
     table.insert(wynik, "! Porażki")
     table.insert(wynik, "! Porażki")
    table.insert(wynik, "| '''" .. suma.porazki .. "'''")
    table.insert(wynik, "| " .. dom.porazki)
    table.insert(wynik, "| " .. wyjazd.porazki)
    table.insert(wynik, "|-")
     table.insert(wynik, "! Remisy")
     table.insert(wynik, "! Remisy")
    table.insert(wynik, "| '''" .. suma.remisy .. "'''")
    table.insert(wynik, "| " .. dom.remisy)
    table.insert(wynik, "| " .. wyjazd.remisy)
    table.insert(wynik, "|-")
     table.insert(wynik, "! Punkty")
     table.insert(wynik, "! Punkty")
    table.insert(wynik, "| '''" .. suma.punkty .. "'''")
    table.insert(wynik, "| " .. dom.punkty)
    table.insert(wynik, "| " .. wyjazd.punkty)
    table.insert(wynik, "|-")
     table.insert(wynik, "! Minuty")
     table.insert(wynik, "! Minuty")
    table.insert(wynik, "| '''" .. formatujMinuty(suma.minuty) .. "'''")
    table.insert(wynik, "| " .. formatujMinuty(dom.minuty))
    table.insert(wynik, "| " .. formatujMinuty(wyjazd.minuty))
    table.insert(wynik, "|-")
     table.insert(wynik, "! EVAL")
     table.insert(wynik, "! EVAL")
     table.insert(wynik, "! +/-")
     table.insert(wynik, "| '''" .. suma.eval .. "'''")
    table.insert(wynik, "| " .. dom.eval)
    table.insert(wynik, "| " .. wyjazd.eval)


     table.insert(wynik, "|-")
     table.insert(wynik, "|-")


     table.insert(wynik, "| colspan=2 | '''" .. wystepy .. "'''")
     table.insert(wynik, "! +/-")
     table.insert(wynik, "| '''" .. zwyciestwa .. "'''")
     table.insert(wynik, "| '''" .. suma.plusminus .. "'''")
    table.insert(wynik, "| '''" .. porazki .. "'''")
     table.insert(wynik, "| " .. dom.plusminus)
     table.insert(wynik, "| '''" .. remisy .. "'''")
     table.insert(wynik, "| " .. wyjazd.plusminus)
     table.insert(wynik, "| '''" .. punkty .. "'''")
    table.insert(wynik, "| " .. sumaMinutFormat)
    table.insert(wynik, "| " .. sumaEval)
    table.insert(wynik, "| " .. sumaPlusMinus)


     table.insert(wynik, "|}")
     table.insert(wynik, "|}")
Linia 171: Linia 347:
     table.insert(wynik, "! Nr")
     table.insert(wynik, "! Nr")
     table.insert(wynik, "! Data")
     table.insert(wynik, "! Data")
    table.insert(wynik, "! Miejsce")
     table.insert(wynik, "! Przeciwnik")
     table.insert(wynik, "! Przeciwnik")
     table.insert(wynik, "! Wynik")
     table.insert(wynik, "! Wynik")
Linia 196: Linia 373:
         local eval = row.eval or "0"
         local eval = row.eval or "0"
         local plusminus = row.plusminus or "0"
         local plusminus = row.plusminus or "0"
        -- ======================================
        -- MIEJSCE
        -- ======================================
        local miejsce = ""
        if druzyna == d1 then
            miejsce = "🏠 Dom"
        elseif druzyna == d2 then
            miejsce = "✈️ Wyjazd"
        end


         -- ======================================
         -- ======================================
Linia 238: Linia 427:
         table.insert(wynik, "| " .. i)
         table.insert(wynik, "| " .. i)
         table.insert(wynik, "| " .. data)
         table.insert(wynik, "| " .. data)
        table.insert(wynik, "| " .. miejsce)
         table.insert(wynik, "| " .. meczTekst)
         table.insert(wynik, "| " .. meczTekst)
         table.insert(wynik, "| " .. wynikMeczu)
         table.insert(wynik, "| " .. wynikMeczu)

Wersja z 04:53, 17 sie 2026

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:HistoriaWystepow/opis

local p = {}

function p.main(frame)

    local zawodnik = frame.args.zawodnik

    if not zawodnik or zawodnik == "" then
        zawodnik = mw.title.getCurrentTitle().text
    end

    -- Bezpieczne przygotowanie nazwy zawodnika do SQL
    local zawodnikSQL = mw.ustring.gsub(zawodnik, "'", "''")

    -- ==========================================
    -- POBRANIE WYSTĘPÓW
    -- ==========================================

    local fields = table.concat({
        "UdzialZawodnika.mecz=mecz",
        "UdzialZawodnika.druzyna=druzyna",
        "UdzialZawodnika.minuty=minuty",
        "UdzialZawodnika.minuty_format=minuty_format",
        "UdzialZawodnika.gol=gol",
        "UdzialZawodnika.eval=eval",
        "UdzialZawodnika.plusminus=plusminus",
        "Mecze.data=data",
        "Mecze.druzyna1=druzyna1",
        "Mecze.druzyna2=druzyna2",
        "Mecze.wynik=wynik",
        "Mecze.strona_meczu=strona_meczu"
    }, ",")

    local args = {
        join = "UdzialZawodnika.mecz=Mecze.id",
        where = "UdzialZawodnika.zawodnik='" .. zawodnikSQL .. "' AND UdzialZawodnika.minuty > 0",
        orderBy = "Mecze.data ASC",
        limit = 5000
    }

    local rows = mw.ext.cargo.query(
        "UdzialZawodnika,Mecze",
        fields,
        args
    )

    if not rows or #rows == 0 then
        return "''Brak wprowadzonych występów w bazie.''"
    end

    -- ==========================================
    -- PODSUMOWANIE - WSZYSTKIE MECZE
    -- ==========================================

    local suma = {
        wystepy = 0,
        zwyciestwa = 0,
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }

    -- ==========================================
    -- PODSUMOWANIE - DOM
    -- ==========================================

    local dom = {
        wystepy = 0,
        zwyciestwa = 0,
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }

    -- ==========================================
    -- PODSUMOWANIE - WYJAZD
    -- ==========================================

    local wyjazd = {
        wystepy = 0,
        zwyciestwa = 0,
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }

    -- ==========================================
    -- FUNKCJA OKREŚLAJĄCA WYNIK
    -- ==========================================

    local function okreslWynik(row)

        local d1 = row.druzyna1 or ""
        local d2 = row.druzyna2 or ""
        local druzyna = row.druzyna or ""
        local wynikMeczu = row.wynik or ""

        local g1, g2 = wynikMeczu:match("(%d+)%s*:%s*(%d+)")

        if not g1 or not g2 then
            return nil
        end

        g1 = tonumber(g1)
        g2 = tonumber(g2)

        if druzyna == d1 then

            if g1 > g2 then
                return "W"
            elseif g1 < g2 then
                return "P"
            else
                return "R"
            end

        elseif druzyna == d2 then

            if g2 > g1 then
                return "W"
            elseif g2 < g1 then
                return "P"
            else
                return "R"
            end

        end

        return nil
    end

    -- ==========================================
    -- FUNKCJA DODAJĄCA MECZ DO PODSUMOWANIA
    -- ==========================================

    local function dodajDoPodsumowania(stat, row)

        stat.wystepy = stat.wystepy + 1

        stat.punkty = stat.punkty + tonumber(row.gol or 0)
        stat.minuty = stat.minuty + tonumber(row.minuty or 0)
        stat.eval = stat.eval + tonumber(row.eval or 0)
        stat.plusminus = stat.plusminus + tonumber(row.plusminus or 0)

        local wynik = okreslWynik(row)

        if wynik == "W" then
            stat.zwyciestwa = stat.zwyciestwa + 1
        elseif wynik == "P" then
            stat.porazki = stat.porazki + 1
        elseif wynik == "R" then
            stat.remisy = stat.remisy + 1
        end
    end

    -- ==========================================
    -- PRZEJŚCIE PRZEZ MECZE
    -- ==========================================

    for _, row in ipairs(rows) do

        -- Wszystkie mecze
        dodajDoPodsumowania(suma, row)

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

        -- Dom / wyjazd
        if druzyna == d1 then
            dodajDoPodsumowania(dom, row)
        elseif druzyna == d2 then
            dodajDoPodsumowania(wyjazd, row)
        end

    end

    -- ==========================================
    -- FORMAT MINUT
    -- ==========================================

    local function formatujMinuty(minuty)

        local godziny = math.floor(minuty / 60)
        local min = minuty % 60

        return string.format("%d:%02d", godziny, min)
    end

    -- ==========================================
    -- FORMAT PODSUMOWANIA
    -- ==========================================

    local function podsumowanie(stat)

        return
            "'''"
            .. stat.wystepy
            .. "''' występów • "
            .. "'''"
            .. stat.zwyciestwa
            .. "''' zwycięstw • "
            .. "'''"
            .. stat.porazki
            .. "''' porażek"
            .. (stat.remisy > 0 and
                " • '''" .. stat.remisy .. "''' remisów"
                or "")
            .. " • '''"
            .. stat.punkty
            .. "''' pkt"
            .. " • '''"
            .. formatujMinuty(stat.minuty)
            .. "''' min"
            .. " • EVAL '''"
            .. stat.eval
            .. "'''"
            .. " • +/- '''"
            .. stat.plusminus
            .. "'''"
    end

    -- ==========================================
    -- WYNIK
    -- ==========================================

    local wynik = {}

    table.insert(wynik, "== Historia występów ==")
    table.insert(wynik, "")

    -- ==========================================
    -- PODSUMOWANIE
    -- ==========================================

    table.insert(wynik, "=== Podsumowanie ===")
    table.insert(wynik, "")

    table.insert(
        wynik,
        "'''Wszystkie spotkania:''' " .. podsumowanie(suma)
    )

    table.insert(
        wynik,
        "'''Mecze domowe:''' " .. podsumowanie(dom)
    )

    table.insert(
        wynik,
        "'''Mecze wyjazdowe:''' " .. podsumowanie(wyjazd)
    )

    table.insert(wynik, "")

    -- ==========================================
    -- TABELA PODSUMOWANIA
    -- ==========================================

    table.insert(
        wynik,
        '{| class="wikitable" style="width:100%; text-align:center;"'
    )

    table.insert(wynik, "!")
    table.insert(wynik, "! Wszystkie")
    table.insert(wynik, "! Dom")
    table.insert(wynik, "! Wyjazd")

    table.insert(wynik, "|-")

    table.insert(wynik, "! Występy")
    table.insert(wynik, "| '''" .. suma.wystepy .. "'''")
    table.insert(wynik, "| " .. dom.wystepy)
    table.insert(wynik, "| " .. wyjazd.wystepy)

    table.insert(wynik, "|-")

    table.insert(wynik, "! Zwycięstwa")
    table.insert(wynik, "| '''" .. suma.zwyciestwa .. "'''")
    table.insert(wynik, "| " .. dom.zwyciestwa)
    table.insert(wynik, "| " .. wyjazd.zwyciestwa)

    table.insert(wynik, "|-")

    table.insert(wynik, "! Porażki")
    table.insert(wynik, "| '''" .. suma.porazki .. "'''")
    table.insert(wynik, "| " .. dom.porazki)
    table.insert(wynik, "| " .. wyjazd.porazki)

    table.insert(wynik, "|-")

    table.insert(wynik, "! Remisy")
    table.insert(wynik, "| '''" .. suma.remisy .. "'''")
    table.insert(wynik, "| " .. dom.remisy)
    table.insert(wynik, "| " .. wyjazd.remisy)

    table.insert(wynik, "|-")

    table.insert(wynik, "! Punkty")
    table.insert(wynik, "| '''" .. suma.punkty .. "'''")
    table.insert(wynik, "| " .. dom.punkty)
    table.insert(wynik, "| " .. wyjazd.punkty)

    table.insert(wynik, "|-")

    table.insert(wynik, "! Minuty")
    table.insert(wynik, "| '''" .. formatujMinuty(suma.minuty) .. "'''")
    table.insert(wynik, "| " .. formatujMinuty(dom.minuty))
    table.insert(wynik, "| " .. formatujMinuty(wyjazd.minuty))

    table.insert(wynik, "|-")

    table.insert(wynik, "! EVAL")
    table.insert(wynik, "| '''" .. suma.eval .. "'''")
    table.insert(wynik, "| " .. dom.eval)
    table.insert(wynik, "| " .. wyjazd.eval)

    table.insert(wynik, "|-")

    table.insert(wynik, "! +/-")
    table.insert(wynik, "| '''" .. suma.plusminus .. "'''")
    table.insert(wynik, "| " .. dom.plusminus)
    table.insert(wynik, "| " .. wyjazd.plusminus)

    table.insert(wynik, "|}")

    table.insert(wynik, "")

    -- ==========================================
    -- TABELA WYSTĘPÓW
    -- ==========================================

    table.insert(
        wynik,
        '{| class="wikitable sortable" style="width:100%;"'
    )

    table.insert(wynik, "! Nr")
    table.insert(wynik, "! Data")
    table.insert(wynik, "! Miejsce")
    table.insert(wynik, "! Przeciwnik")
    table.insert(wynik, "! Wynik")
    table.insert(wynik, "! Min.")
    table.insert(wynik, "! Pkt")
    table.insert(wynik, "! EVAL")
    table.insert(wynik, "! +/-")
    table.insert(wynik, "! Jubileusz")

    -- ==========================================
    -- POSZCZEGÓLNE MECZE
    -- ==========================================

    for i, row in ipairs(rows) do

        local data = row.data or ""
        local d1 = row.druzyna1 or ""
        local d2 = row.druzyna2 or ""
        local druzyna = row.druzyna or ""
        local wynikMeczu = row.wynik or ""
        local strona = row.strona_meczu or ""

        local minutyFormat = row.minuty_format or ""
        local pkt = row.gol or "0"
        local eval = row.eval or "0"
        local plusminus = row.plusminus or "0"

        -- ======================================
        -- MIEJSCE
        -- ======================================

        local miejsce = ""

        if druzyna == d1 then
            miejsce = "🏠 Dom"
        elseif druzyna == d2 then
            miejsce = "✈️ Wyjazd"
        end

        -- ======================================
        -- PRZECIWNIK
        -- ======================================

        local przeciwnik = ""

        if druzyna == d1 then
            przeciwnik = d2
        elseif druzyna == d2 then
            przeciwnik = d1
        else
            przeciwnik = d1
        end

        -- ======================================
        -- LINK DO STRONY MECZU
        -- ======================================

        local meczTekst = przeciwnik

        if strona ~= "" then
            meczTekst = "[[" .. strona .. "|" .. przeciwnik .. "]]"
        end

        -- ======================================
        -- JUBILEUSZ
        -- ======================================

        local jubileusz = ""

        if i % 50 == 0 then
            jubileusz = "'''🏆 " .. i .. ". występ'''"
        end

        -- ======================================
        -- WIERSZ
        -- ======================================

        table.insert(wynik, "|-")
        table.insert(wynik, "| " .. i)
        table.insert(wynik, "| " .. data)
        table.insert(wynik, "| " .. miejsce)
        table.insert(wynik, "| " .. meczTekst)
        table.insert(wynik, "| " .. wynikMeczu)
        table.insert(wynik, "| " .. minutyFormat)
        table.insert(wynik, "| " .. pkt)
        table.insert(wynik, "| " .. eval)
        table.insert(wynik, "| " .. plusminus)
        table.insert(wynik, "| " .. jubileusz)

    end

    table.insert(wynik, "|}")

    return table.concat(wynik, "\n")
end

return p