Przejdź do zawartości

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

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
(Nie pokazano 2 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 21: Linia 21:
--  |dyscyplina=koszykówka
--  |dyscyplina=koszykówka
-- }}
-- }}
--
-- =========================================================
-- =========================================================


Linia 48: Linia 47:




local function escapeSQL(value)
-- =========================================================
-- MINUTY
--
-- Obsługuje:
-- 32
-- 32.0
-- 32:15
-- 32:15.5
--
-- Do porównywania rekordów używamy sekund.
-- =========================================================
 
local function minutyNaSekundy(value)
 
    if value == nil or value == "" then
        return 0
    end


     value = tostring(value or "")
     value = tostring(value)


     return mw.ustring.gsub(
     value = mw.ustring.gsub(
         value,
         value,
         "'",
         "%s+",
         "''"
         ""
     )
     )


end
    local minuty, sekundy =
        mw.ustring.match(
            value,
            "^(%d+):(%d+)$"
        )


    if minuty and sekundy then


-- =========================================================
        return
-- ROZPOZNANIE MIEJSCA MECZU
            tonumber(minuty) * 60 +
-- =========================================================
            tonumber(sekundy)


local function miejsceMeczu(row, druzyna)
    end


     local d1 =
     local liczbaMinut =
         tostring(row.druzyna1 or "")
         tonumber(value)


    local d2 =
     if liczbaMinut then
        tostring(row.druzyna2 or "")
         return liczbaMinut * 60
 
     end
    if d1 == druzyna then
        return "dom"
    end
 
     if d2 == druzyna then
         return "wyjazd"
     end


     return nil
     return 0


end
end
Linia 87: Linia 100:


-- =========================================================
-- =========================================================
-- WYNIK MECZU
-- FORMAT MINUT
--
-- Zwraca wynik faktyczny:
-- g1 = gole/punkty gospodarza
-- g2 = gole/punkty gościa
-- =========================================================
-- =========================================================


local function wynikMeczu(row)
local function formatMinut(sekundy)
 
    sekundy = tonumber(sekundy) or 0


     local g1 =
     local minuty =
         tonumber(row.gole1 or "")
         math.floor(
            sekundy / 60
        )


     local g2 =
     local sek =
         tonumber(row.gole2 or "")
         sekundy % 60


     if g1 ~= nil and g2 ~= nil then
     if sek == 0 then
         return g1, g2
         return tostring(minuty) .. " min"
     end
     end


    return
        tostring(minuty) ..
        ":" ..
        string.format(
            "%02d",
            sek
        ) ..
        " min"


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


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


    if a and b then
local function escapeSQL(value)


        return
    value = tostring(value or "")
            tonumber(a),
            tonumber(b)


     end
     return mw.ustring.gsub(
 
        value,
 
        "'",
     return nil, nil
        "''"
     )


end
end
Linia 131: Linia 145:


-- =========================================================
-- =========================================================
-- WYNIK Z PERSPEKTYWY DRUŻYNY
-- ROZPOZNANIE MIEJSCA MECZU
--
-- TO JEST KLUCZOWA FUNKCJA DLA NAJCZĘSTSZYCH WYNIKÓW.
--
-- Lech - Cracovia 4:1
--      => Lech: 4:1
--
-- Cracovia - Lech 1:4
--      => Lech: 4:1
--
-- Dzięki temu nie mieszamy kolejności gospodarze/goście.
-- =========================================================
-- =========================================================


local function wynikZPerspektywy(row, druzyna)
local function miejsceMeczu(row, druzyna)


     local g1, g2 =
     local d1 =
         wynikMeczu(row)
         tostring(row.druzyna1 or "")


     if g1 == nil or g2 == nil then
     local d2 =
         return nil, nil
         tostring(row.druzyna2 or "")
    end


    local miejsce =
     if d1 == druzyna then
        miejsceMeczu(
         return "dom"
            row,
    end
            druzyna
        )
 
     if miejsce == "dom" then
 
         return g1, g2
 
    elseif miejsce == "wyjazd" then
 
        return g2, g1


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


     return nil, nil
     return nil


end
end
Linia 175: Linia 170:


-- =========================================================
-- =========================================================
-- NAZWA MECZU
-- WYNIK MECZU
-- =========================================================
-- =========================================================


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


     local d1 =
     local g1 =
         tostring(row.druzyna1 or "")
         tonumber(row.gole1 or "")


     local d2 =
     local g2 =
         tostring(row.druzyna2 or "")
         tonumber(row.gole2 or "")


     local strona =
     if g1 ~= nil and g2 ~= nil then
         tostring(row.strona_meczu or "")
         return g1, g2
    end


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


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


     if strona ~= "" then
     local a, b =
        mw.ustring.match(
            wynik,
            "(%d+)%s*:%s*(%d+)"
        )
 
    if a and b then


         return
         return
             "[[" ..
             tonumber(a),
             strona ..
             tonumber(b)
            "|" ..
            tekst ..
            "]]"


     end
     end


     return tekst
 
     return nil, nil


end
end
Linia 212: Linia 210:


-- =========================================================
-- =========================================================
-- FORMAT DATY
-- WYNIK Z PERSPEKTYWY DRUŻYNY
-- =========================================================
-- =========================================================


local function dataTekst(data)
local function wynikZPerspektywy(row, druzyna)
 
    local g1, g2 =
        wynikMeczu(row)
 
    if g1 == nil or g2 == nil then
        return nil, nil
    end
 
    local miejsce =
        miejsceMeczu(
            row,
            druzyna
        )
 
    if miejsce == "dom" then


    return tostring(
        return g1, g2
        data or ""
 
     )
    elseif miejsce == "wyjazd" then
 
        return g2, g1
 
     end
 
    return nil, nil


end
end
Linia 225: Linia 244:


-- =========================================================
-- =========================================================
-- FUNKCJA DODAWANIA REKORDU
-- NAZWA MECZU
-- =========================================================
-- =========================================================


local function dodajRekord(
local function nazwaMeczu(row)
     tabela,
 
    miejsce,
     local d1 =
    wartosc,
        tostring(row.druzyna1 or "")
     item
 
)
     local d2 =
        tostring(row.druzyna2 or "")


     if wartosc == nil then
     local strona =
         return
         tostring(row.strona_meczu or "")
    end


     local lista =
     local tekst =
         tabela[miejsce]
         d1 ..
        " – " ..
        d2


    if #lista == 0 then


        table.insert(
    if strona ~= "" then
            lista,
            item
        )


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


     end
     end


    return tekst


    local obecna =
end
        lista[1].wartosc




    if wartosc > obecna then
-- =========================================================
-- DODAWANIE REKORDU
--
-- KLUCZOWA POPRAWKA:
--
-- zapisujemy wartość rekordu bezpośrednio w item.wartosc.
--
-- Dzięki temu nie ma już:
-- attempt to compare nil with number
-- =========================================================


        tabela[miejsce] = {
local function dodajRekord(
            item
    tabela,
        }
    miejsce,
    wartosc,
    item
)


     elseif wartosc == obecna then
     if wartosc == nil then
        return
    end


         table.insert(
    wartosc =
            lista,
         tonumber(wartosc)
            item
        )


    if wartosc == nil then
        return
     end
     end


end
    item.wartosc =
        wartosc


    local lista =
        tabela[miejsce]


-- =========================================================
    if #lista == 0 then
-- FORMAT REKORDÓW MECZOWYCH
 
-- =========================================================
        table.insert(
            lista,
            item
        )


local function tekstMeczow(lista)
        return


    if not lista or #lista == 0 then
        return "—"
     end
     end


    local wynik = {}


     for _, item in ipairs(lista) do
     local obecna =
        tonumber(
            lista[1].wartosc
        ) or 0


        local roznica =
            item.roznica or 0


        local roznicaTekst
    if wartosc > obecna then


         if roznica >= 0 then
         tabela[miejsce] = {
            item
        }


            roznicaTekst =
    elseif wartosc == obecna then
                "+" ..
                tostring(roznica)
 
        else
 
            roznicaTekst =
                tostring(roznica)
 
        end
 
 
        table.insert(
            wynik,
 
            item.tekst ..
            " (" ..
            item.wynik ..
            ", " ..
            roznicaTekst ..
            ")"


        table.insert(
            lista,
            item
         )
         )


     end
     end
    return table.concat(
        wynik,
        "<br>"
    )


end
end
Linia 333: Linia 352:


-- =========================================================
-- =========================================================
-- FORMAT REKORDÓW ZAWODNIKÓW