Przejdź do zawartości

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

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
 
(Nie pokazano 14 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 1: Linia 1:
local p = {}
local p = {}
-- =========================================================
-- MODUŁ:H2H
--
-- Historia bezpośrednich spotkań dwóch drużyn.
--
-- team1 = drużyna analizowana
-- team2 = przeciwnik
--
-- nazwa_statystyki1 / nazwa_statystyki2 służą do identyfikacji
-- drużyn niezależnie od historycznych nazw sponsorskich.
--
-- Zawiera:
-- 1. Bilans ogółem / dom / wyjazd
-- 2. Trenerów team1 w rywalizacji
-- 3. Najlepszych strzelców obu drużyn
-- 4. Rekordy indywidualne team1
-- 5. Serie zwycięstw / porażek
-- 6. Analizę kwart
-- 7. Wszystkie mecze
-- 8. Dogrywki 1, 2 i 3
-- =========================================================


function p.main(frame)
function p.main(frame)


     local team1 = frame.args.team1 or ""
    -- =====================================================
     local team2 = frame.args.team2 or ""
    -- PARAMETRY
    -- =====================================================
 
     local team1 = mw.text.trim(frame.args.team1 or "")
     local team2 = mw.text.trim(frame.args.team2 or "")
 
    if team1 == "" then
        return "'''Błąd:''' nie podano team1."
    end


     if team1 == "" or team2 == "" then
     if team2 == "" then
         return "'''Błąd:''' należy podać team1 i team2."
         return "'''Błąd:''' nie podano team2."
     end
     end


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


     local function esc(value)
    -- =====================================================
        value = tostring(value or "")
    -- BEZPIECZEŃSTWO SQL
         return mw.ustring.gsub(value, "'", "''")
    -- =====================================================
 
     local function sql(value)
 
         return mw.ustring.gsub(
            tostring(value or ""),
            "'",
            "''"
        )
 
     end
     end


    local t1 = esc(team1)
    local t2 = esc(team2)


     local function num(value)
    local team1SQL = sql(team1)
    local team2SQL = sql(team2)
 
 
    -- =====================================================
    -- FUNKCJE POMOCNICZE
    -- =====================================================
 
     local function liczba(value)
 
         if value == nil or value == "" then
         if value == nil or value == "" then
             return 0
             return 0
         end
         end


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


        return tonumber(value) or 0
     end
     end


    local function wynik(row)


        local g1 = num(row.gole1)
    local function procent(wygrane, mecze)
        local g2 = num(row.gole2)


         if row.gole1 ~= nil and row.gole2 ~= nil then
         if mecze == 0 then
             return g1, g2
             return "0,0%"
         end
         end


         local w = row.wynik or ""
         local wartosc =
            (wygrane / mecze) * 100


         local a, b = w:match("(%d+)%s*:%s*(%d+)")
         return string.format(
            "%.1f%%",
            wartosc
        ):gsub("%.", ",")
 
    end


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


        return nil, nil
    -- =====================================================
     end
    -- IDENTYFIKACJA STRONY TEAM1
     -- =====================================================


     local function strona(row)
     local function miejsce(row)


         if row.druzyna1 == team1 then
         if row.ns1 == team1 then
             return "dom"
             return "dom"
         end
         end


         if row.druzyna2 == team1 then
         if row.ns2 == team1 then
             return "wyjazd"
             return "wyjazd"
         end
         end


         return nil
         return nil
    end
    -- =====================================================
    -- WYNIK TEAM1
    -- =====================================================