Przejdź do zawartości

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

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
Linia 9: Linia 9:
     end
     end


     -- ==========================================
     -- =====================================================
     -- BEZPIECZNE PRZYGOTOWANIE NAZWY
     -- BEZPIECZNE PRZYGOTOWANIE NAZWY ZAWODNIKA
     -- ==========================================
     -- =====================================================


     local zawodnikSQL = mw.ustring.gsub(zawodnik, "'", "''")
     local zawodnikSQL = mw.ustring.gsub(zawodnik, "'", "''")


     -- ==========================================
     -- =====================================================
     -- POLA POBIERANE Z CARGO
     -- POLA POBIERANE Z CARGO
     -- ==========================================
     -- =====================================================


     local fields = table.concat({
     local fields = table.concat({
Linia 27: Linia 27:
         "UdzialZawodnika.eval=eval",
         "UdzialZawodnika.eval=eval",
         "UdzialZawodnika.plusminus=plusminus",
         "UdzialZawodnika.plusminus=plusminus",
         "Mecze.data=data",
         "Mecze.data=data",
        "Mecze.sezon=sezon",
         "Mecze.druzyna1=druzyna1",
         "Mecze.druzyna1=druzyna1",
         "Mecze.druzyna2=druzyna2",
         "Mecze.druzyna2=druzyna2",
Linia 34: Linia 36:
     }, ",")
     }, ",")


     -- ==========================================
     -- =====================================================
     -- ZAPYTANIE CARGO
     -- ZAPYTANIE CARGO
     -- ==========================================
     -- =====================================================


     local args = {
     local args = {
Linia 51: Linia 53:
     )
     )


     -- ==========================================
     -- =====================================================
     -- BRAK DANYCH
     -- BRAK DANYCH
     -- ==========================================
     -- =====================================================


     if not rows or #rows == 0 then
     if not rows or #rows == 0 then
Linia 59: Linia 61:
     end
     end


     -- ==========================================
     -- =====================================================
     -- PODSUMOWANIE - WSZYSTKIE MECZE
     -- FUNKCJA TWORZĄCA PODSUMOWANIE
     -- ==========================================
     -- =====================================================


     local suma = {
     local function nowePodsumowanie()
        wystepy = 0,
 
        zwyciestwa = 0,
        return {
        porazki = 0,
            wystepy = 0,
        remisy = 0,
            zwyciestwa = 0,
        punkty = 0,
            porazki = 0,
        minuty = 0,
            remisy = 0,
        eval = 0,
            punkty = 0,
        plusminus = 0
            minuty = 0,
    }
            eval = 0,
            plusminus = 0
        }


     -- ==========================================
     end
    -- PODSUMOWANIE - MECZE DOMOWE
    -- ==========================================


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


     -- ==========================================
     local suma = nowePodsumowanie()
     -- PODSUMOWANIE - MECZE WYJAZDOWE
     local dom = nowePodsumowanie()
     -- ==========================================
     local wyjazd = nowePodsumowanie()


     local wyjazd = {
    -- podsumowania poszczególnych sezonów
        wystepy = 0,
     local sezony = {}
        zwyciestwa = 0,
        porazki = 0,
        remisy = 0,
        punkty = 0,
        minuty = 0,
        eval = 0,
        plusminus = 0
    }


     -- ==========================================
     -- =====================================================
     -- OKREŚLENIE WYNIKU MECZU
     -- OKREŚLENIE WYNIKU MECZU
     -- ==========================================
     -- =====================================================


     local function okreslWynik(row)
     local function okreslWynik(row)
Linia 149: Linia 136:
     end
     end


     -- ==========================================
     -- =====================================================
     -- DODANIE MECZU DO PODSUMOWANIA
     -- DODANIE MECZU DO PODSUMOWANIA
     -- ==========================================
     -- =====================================================


     local function dodajDoPodsumowania(stat, row)
     local function dodajDoPodsumowania(stat, row)
Linia 157: Linia 144:
         stat.wystepy = stat.wystepy + 1
         stat.wystepy = stat.wystepy + 1


         stat.punkty = stat.punkty + tonumber(row.gol or 0)
         stat.punkty =
         stat.minuty = stat.minuty + tonumber(row.minuty or 0)
            stat.punkty +
         stat.eval = stat.eval + tonumber(row.eval or 0)
            tonumber(row.gol or 0)
         stat.plusminus = stat.plusminus + tonumber(row.plusminus 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)
         local wynik = okreslWynik(row)
Linia 166: Linia 164:
         if wynik == "W" then
         if wynik == "W" then


             stat.zwyciestwa = stat.zwyciestwa + 1
             stat.zwyciestwa =
                stat.zwyciestwa + 1


         elseif wynik == "P" then
         elseif wynik == "P" then


             stat.porazki = stat.porazki + 1
             stat.porazki =
                stat.porazki + 1


         elseif wynik == "R" then
         elseif wynik == "R" then


             stat.remisy = stat.remisy + 1
             stat.remisy =
                stat.remisy + 1


         end
         end
     end
     end


     -- ==========================================
     -- =====================================================
     -- PRZEJŚCIE PRZEZ WSZYSTKIE WYSTĘPY
     -- PRZEJŚCIE PRZEZ WSZYSTKIE MECZE
     -- ==========================================
     -- =====================================================


     for _, row in ipairs(rows) do
     for _, row in ipairs(rows) do


         -- Wszystkie spotkania
         -- -----------------------------------------------
         dodajDoPodsumowania(suma, row)
        -- WSZYSTKIE MECZE
        -- -----------------------------------------------
 
         dodajDoPodsumowania(
            suma,
            row
        )
 
        -- -----------------------------------------------
        -- DOM / WYJAZD
        -- -----------------------------------------------


         local d1 = row.druzyna1 or ""
         local d1 = row.druzyna1 or ""
Linia 192: Linia 204:
         local druzyna = row.druzyna or ""
         local druzyna = row.druzyna or ""


        -- Dom
         if druzyna == d1 then
         if druzyna == d1 then


             dodajDoPodsumowania(dom, row)
             dodajDoPodsumowania(
                dom,
                row
            )


        -- Wyjazd
         elseif druzyna == d2 then
         elseif druzyna == d2 then


             dodajDoPodsumowania(wyjazd, row)
             dodajDoPodsumowania(
                wyjazd,
                row
            )
 
        end
 
        -- -----------------------------------------------
        -- SEZON
        -- -----------------------------------------------
 
        local sezon = row.sezon or ""
 
        if sezon == "" then
            sezon = "Brak sezonu"
        end


        if not sezony[sezon] then
            sezony[sezon] = nowePodsumowanie()
         end
         end
        dodajDoPodsumowania(
            sezony[sezon],
            row
        )


     end
     end


     -- ==========================================
     -- =====================================================
     -- FORMATOWANIE MINUT
     -- FORMATOWANIE MINUT
     -- ==========================================
     -- =====================================================


     local function formatujMinuty(minuty)
     local function formatujMinuty(minuty)


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


         return string.format(
         return string.format(
Linia 220: Linia 258:
             min
             min
         )
         )
     end
     end


     -- ==========================================
     -- =====================================================
    -- SORTOWANIE SEZONÓW
    -- =====================================================
 
    local listaSezonow = {}
 
    for sezon, _ in pairs(sezony) do
        table.insert(
            listaSezonow,
            sezon
        )
    end
 
    table.sort(
        listaSezonow,
        function(a, b)
 
            return a > b
 
        end
    )
 
    -- =====================================================
     -- WYNIK
     -- WYNIK
     -- ==========================================
     -- =====================================================


     local wynik = {}
     local wynik = {}
Linia 235: Linia 296:
     table.insert(wynik, "")
     table.insert(wynik, "")


     -- ==========================================
     -- =====================================================
     -- TABELA PODSUMOWANIA
     -- PODSUMOWANIE WSZYSTKICH / DOM / WYJAZD
     -- ==========================================
     -- =====================================================


     table.insert(
     table.insert(
         wynik,
         wynik,
         "=== Podsumowanie ==="
         "=== Podsumowanie wszystkich spotkań ==="
     )
     )


Linia 250: Linia 311:
         '{| class="wikitable" style="width:100%; text-align:center;"'
         '{| class="wikitable" style="width:100%; text-align:center;"'
     )
     )
    -- Nagłówki


     table.insert(
     table.insert(
Linia 265: Linia 324:
     table.insert(
     table.insert(
         wynik,
         wynik,
         "! Mecze domowe"
         "! 🏠 Mecze domowe"
     )
     )


     table.insert(
     table.insert(
         wynik,
         wynik,
         "! Mecze wyjazdowe"
         "! ✈️ Mecze wyjazdowe"
     )
     )


Linia 276: Linia 335:


     table.insert(wynik, "|-")
     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(
    -- Zwycięstwa
        wynik,
 
        "! Występy"
     table.insert(wynik, "|-")
     )
    table.insert(wynik, "! Zwycięstwa")
    table.insert(wynik, "| '''" .. suma.zwyciestwa .. "'''")
    table.insert(wynik, "| '''" .. dom.zwyciestwa .. "'''")
     table.insert(wynik, "| '''" .. wyjazd.zwyciestwa .. "'''")
 
    -- Porażki


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


     table.insert(
     -- Remisy
        wynik,
        "| '''" .. dom.wystepy .. "'''"
    )


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


     -- Zwycięstwa
     -- Punkty


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


     table.insert(
     -- Minuty
        wynik,
        "! Zwycięstwa"
    )


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


     table.insert(
     -- EVAL
        wynik,
        "| '''" .. dom.zwyciestwa .. "'''"
    )


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


     -- Porażki
     -- Plus/minus


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


     table.insert(
     table.insert(
         wynik,
         wynik,
         "! Porażki"
         "|}"
     )
     )
    table.insert(wynik, "")
    -- =====================================================
    -- PODSUMOWANIE POSZCZEGÓLNYCH SEZONÓW
    -- =====================================================


     table.insert(
     table.insert(
         wynik,
         wynik,
         "| '''" .. suma.porazki .. "'''"
         "=== Podsumowanie sezonów ==="
     )
     )
    table.insert(wynik, "")


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


     table.insert(
     table.insert(
         wynik,
         wynik,
         "| '''" .. wyjazd.porazki .. "'''"
         "! Sezon"
     )
     )
    -- Remisy
    table.insert(wynik, "|-")


     table.insert(
     table.insert(
         wynik,
         wynik,