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 13 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 2: Linia 2:


-- =========================================================
-- =========================================================
-- Module:H2H
-- MODUŁ:H2H
--
--
-- Historia bezpośrednich spotkań dwóch drużyn.
-- Historia bezpośrednich spotkań dwóch drużyn.
--
--
-- Drużyny są rozpoznawane po:
-- team1 = drużyna analizowana
--   Mecze.nazwa_statystyki1
-- team2 = przeciwnik
--  Mecze.nazwa_statystyki2
--
--
-- Dzięki temu zmiana sponsora / nazwy drużyny nie rozbija H2H.
-- nazwa_statystyki1 / nazwa_statystyki2 służą do identyfikacji
--
-- drużyn niezależnie od historycznych nazw sponsorskich.
-- Funkcje:
--  1. bilans spotkań
--  2. suma punktów
--  3. wszystkie mecze
--  4. najlepsi strzelcy
--  5. trenerzy
--  6. rekordy meczowe
--  7. rekordy indywidualne
--  8. serie zwycięstw / porażek
--   9. kwartowe porównanie wyników
--
--
-- 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
-- =========================================================
-- =========================================================


Linia 32: Linia 30:
     -- =====================================================
     -- =====================================================


     local team1 =
     local team1 = mw.text.trim(frame.args.team1 or "")
        mw.text.trim(frame.args.team1 or "")
     local team2 = mw.text.trim(frame.args.team2 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:''' nie podano team2."
         return "'''Błąd:''' należy podać obie drużyny."
 
     end
     end


Linia 53: Linia 49:


         return mw.ustring.gsub(
         return mw.ustring.gsub(
             value,
             tostring(value or ""),
             "'",
             "'",
             "''"
             "''"
Linia 61: Linia 57:




     local t1 = sql(team1)
     local team1SQL = sql(team1)
     local t2 = sql(team2)
     local team2SQL = sql(team2)
 
 
    -- =====================================================
    -- WARUNEK H2H DLA TABELI Mecze
    --
    -- WAŻNE:
    -- tutaj używamy nazwa_statystyki.
    -- Dzięki temu zmiana nazwy sponsorskiej nie rozbija H2H.
    -- =====================================================
 
    local whereMecze =
        "(" ..
        "M.nazwa_statystyki1='" .. t1 ..
        "' AND M.nazwa_statystyki2='" .. t2 ..
        "')" ..
        " OR " ..
        "(" ..
        "M.nazwa_statystyki1='" .. t2 ..
        "' AND M.nazwa_statystyki2='" .. t1 ..
        "')"




Linia 89: Linia 65:
     -- =====================================================
     -- =====================================================


     local function number(value)
     local function liczba(value)


         if value == nil or value == "" then
         if value == nil or value == "" then
Linia 95: Linia 71:
         end
         end


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


         return tonumber(value) or 0
         return tonumber(tekst) or 0


     end
     end




     local function parseScore(value)
     local function procent(wygrane, mecze)


         if not value then
         if mecze == 0 then
             return nil
             return "0,0%"
         end
         end


         local a, b =
         local wartosc =
             tostring(value):match(
             (wygrane / mecze) * 100
                "(%d+)%s*:%s*(%d+)"
            )


         if a and b then
         return string.format(
             return tonumber(a), tonumber(b)
             "%.1f%%",
        end
            wartosc
 
         ):gsub("%.", ",")
         return nil, nil


     end
     end




     local function matchScore(row)
     -- =====================================================
    -- IDENTYFIKACJA STRONY TEAM1
    -- =====================================================


        local g1 =
    local function miejsce(row)
            tonumber(row.gole1 or "")


         local g2 =
         if row.ns1 == team1 then
             tonumber(row.gole2 or "")
             return "dom"
        end


         if g1 and g2 then
         if row.ns2 == team1 then
             return g1, g2
             return "wyjazd"
         end
         end


         return parseScore(row.wynik)
         return nil


     end
     end




     local function location(row)
     -- =====================================================
    -- WYNIK TEAM1
    -- =====================================================


        local d1 =
    local function wynikDruzyny(row)
            row.nazwa_statystyki1 or ""


         local d2 =
         local g1 =
             row.nazwa_statystyki2 or ""
             liczba(row.gole1)


        local g2 =
            liczba(row.gole2)


        if d1 == team1 then
            return "dom"
        end


         if d2 == team1 then
         if row.ns1 == team1 then
            return "wyjazd"
        end


        return nil
            return g1, g2


    end
        elseif row.ns2 == team1 then


            return g2, g1


    local function teamScore(row)
        local g1, g2 =
            matchScore(row)
        if not g1 or not g2 then
            return nil, nil
         end
         end


 
         return nil, nil
         if location(row) == "dom" then
            return g1, g2
        end
 
        return g2, g1


     end
     end




     local function result(row)
     -- =====================================================
 
    -- NAZWA MECZU
        local zdobyte, stracone =
     -- =====================================================
            teamScore(row)
 
        if not zdobyte or not stracone then
            return nil
        end
 
        if zdobyte > stracone then
            return "W"
        end
 
        if zdobyte < stracone then
            return "P"
        end
 
        return "R"
 
     end


 
     local function nazwaMeczu(row)
     local function matchName(row)


         local d1 =
         local d1 =
Linia 217: Linia 159:
             row.druzyna2 or ""
             row.druzyna2 or ""


         local page =
         local strona =
             row.strona_meczu or ""
             row.strona_meczu or ""




         local text =
         local tekst =
             d1 ..
             d1 .. " – " .. d2
            " – " ..
            d2




         if page ~= "" then
         if strona ~= "" then


             return
             return "[[" ..
                "[[" ..
                 strona ..
                 page ..
                 "|" ..
                 "|" ..
                 text ..
                 tekst ..
                 "]]"
                 "]]"


         end
         end


         return text
 
         return tekst


     end
     end




     local function formatPlusMinus(value)
     -- =====================================================
    -- PARSOWANIE CZĘŚCI WYNIKU
    -- =====================================================


        value =
    local function parseWynikCzesciowy(value)
            number(value)


         if value > 0 then
         if value == nil or value == "" then
             return "+" .. tostring(value)
             return nil, nil
         end
         end


         return tostring(value)
         local tekst =
            tostring(value)


    end
        local a, b =
            tekst:match(
                "(%d+)%s*:%s*(%d+)"
            )


        if not a or not b then
            return nil, nil
        end


     -- =====================================================
        return
            tonumber(a),
            tonumber(b)
 
    end