Przejdź do zawartości

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

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
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
-- =========================================================
-- =========================================================


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 127: Linia 145:


-- =========================================================
-- =========================================================
-- WYNIK Z PERSPEKTYWY DRUŻYNY
-- ROZPOZNANIE MIEJSCA MECZU
-- =========================================================
-- =========================================================


local function wynikZPerspektywy(row, druzyna)
local function miejsceMeczu(row, druzyna)
 
    local d1 =
        tostring(row.druzyna1 or "")


     local g1, g2 =
     local d2 =
         wynikMeczu(row)
         tostring(row.druzyna2 or "")


     if g1 == nil or g2 == nil then
     if d1 == druzyna then
         return nil, nil
         return "dom"
     end
     end


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


     return nil, nil
     return nil


end
end
Linia 161: 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 "")
 
    if g1 ~= nil and g2 ~= nil then
        return g1, g2
    end


    local strona =
        tostring(row.strona_meczu or "")


     local tekst =
     local wynik =
         d1 ..
         tostring(row.wynik or "")
        " " ..
        d2


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


     if strona ~= "" then
     if a and b then


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


     end
     end


     return tekst
 
     return nil, nil


end
end
Linia 198: Linia 210:


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


local function dataTekst(data)
local function wynikZPerspektywy(row, druzyna)


     return tostring(
     local g1, g2 =
         data or ""
         wynikMeczu(row)
    )


end
    if g1 == nil or g2 == nil then
        return nil, nil
    end


    local miejsce =
        miejsceMeczu(
            row,
            druzyna
        )


-- =========================================================
    if miejsce == "dom" then
-- FUNKCJA DODAWANIA REKORDU
--
-- WARTOŚĆ ZAWSZE JEST ZAPISYWANA W item.wartosc.
-- To eliminuje błąd:
--
-- attempt to compare nil with number
--
-- =========================================================


local function dodajRekord(
        return g1, g2
    tabela,
    miejsce,
    wartosc,
    item
)


     if wartosc == nil then
     elseif miejsce == "wyjazd" then
        return
    end


    wartosc =
         return g2, g1
         tonumber(wartosc)


    if wartosc == nil then
        return
     end
     end


     item.wartosc =
     return nil, nil
        wartosc
 
end




    local lista =
-- =========================================================
        tabela[miejsce]
-- NAZWA MECZU
-- =========================================================


    if not lista then
local function nazwaMeczu(row)


         tabela[miejsce] = {}
    local d1 =
         tostring(row.druzyna1 or "")


        lista =
    local d2 =
            tabela[miejsce]
        tostring(row.druzyna2 or "")


     end
     local strona =
        tostring(row.strona_meczu or "")


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


    if #lista == 0 then


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


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


     end
     end
 


     local obecna =
     return tekst
        tonumber(
            lista[1].wartosc
        ) or 0
 
 
    if wartosc > obecna then
 
        tabela[miejsce] = {
            item
        }
 
    elseif wartosc == obecna then
 
        table.insert(
            lista,
            item
        )
 
    end


end
end
Linia 292: Linia 281:


-- =========================================================
-- =========================================================
-- FORMAT REKORDÓW MECZOWYCH
-- DODAWANIE REKORDU
--
-- KLUCZOWA POPRAWKA:
--
-- zapisujemy wartość rekordu bezpośrednio w item.wartosc.
--
-- Dzięki temu nie ma już:
-- attempt to compare nil with number
-- =========================================================
-- =========================================================


local function tekstMeczow(lista)
local function dodajRekord(
    tabela,
    miejsce,
    wartosc,
    item
)


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


     local wynik = {}
     wartosc =
        tonumber(wartosc)


     for _, item in ipairs(lista) do
     if wartosc == nil then
        return
    end


        local roznica =
    item.wartosc =
            tonumber(item.roznica or 0) or 0
        wartosc


         local roznicaTekst
    local lista =
         tabela[miejsce]


        if roznica >= 0 then
    if #lista == 0 then


             roznicaTekst =
        table.insert(
                "+" ..
             lista,
                tostring(roznica)
            item
        )
 
        return
 
    end


        else


            roznicaTekst =
    local obecna =
                tostring(roznica)
        tonumber(
            lista[1].wartosc
        ) or 0


        end


    if wartosc > obecna then


         table.insert(
         tabela[miejsce] = {
             wynik,
             item
        }


            item.tekst ..
    elseif wartosc == obecna then
            " (" ..
            item.wynik ..
            ", " ..
            roznicaTekst ..
            ")"


        table.insert(
            lista,
            item
         )
         )


     end
     end


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