Moduł:Rekordy sezon: Różnice pomiędzy wersjami
Wygląd
Nie podano opisu zmian |
Nie podano opisu zmian |
||
| (Nie pokazano 4 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
| Linia 4: | Linia 4: | ||
-- Moduł:Rekordy_sezon | -- Moduł:Rekordy_sezon | ||
-- | -- | ||
-- | -- Jeden moduł dla różnych dyscyplin. | ||
-- | -- | ||
-- Wywołanie: | -- Wywołanie: | ||
| Linia 14: | Linia 14: | ||
-- }} | -- }} | ||
-- | -- | ||
-- | -- lub: | ||
-- | -- | ||
-- {{#invoke:Rekordy_sezon|main | |||
-- |sezon=2026/2027 | |||
-- |druzyna=Enea Basket Poznań | |||
-- |dyscyplina=koszykówka | |||
-- }} | |||
-- ========================================================= | -- ========================================================= | ||
| Linia 24: | Linia 27: | ||
-- FUNKCJE WSPÓLNE | -- FUNKCJE WSPÓLNE | ||
-- ========================================================= | -- ========================================================= | ||
local function liczba(value) | local function liczba(value) | ||
| Linia 58: | Linia 48: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- MINUTY | ||
-- | |||
-- Obsługuje: | |||
-- 32 | |||
-- 32.0 | |||
-- 32:15 | |||
-- 32:15.5 | |||
-- | -- | ||
-- | -- Do porównywania rekordów używamy sekund. | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function minutyNaSekundy(value) | ||
if value == nil or value == "" then | |||
return 0 | |||
return | |||
end | end | ||
value = tostring(value) | |||
value = mw.ustring.gsub( | |||
value, | |||
"%s+", | |||
"" | |||
) | |||
local minuty, sekundy = | |||
local | mw.ustring.match( | ||
value, | |||
"(%d+) | "^(%d+):(%d+)$" | ||
) | ) | ||
if minuty and sekundy then | |||
if | |||
return | return | ||
tonumber( | tonumber(minuty) * 60 + | ||
tonumber( | tonumber(sekundy) | ||
end | end | ||
local liczbaMinut = | |||
tonumber(value) | |||
if liczbaMinut then | |||
return liczbaMinut * 60 | |||
end | |||
return | return 0 | ||
end | end | ||
| Linia 104: | Linia 100: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- FORMAT MINUT | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function formatMinut(sekundy) | ||
) | |||
sekundy = tonumber(sekundy) or 0 | |||
local | local minuty = | ||
math.floor( | |||
sekundy / 60 | |||
) | |||
local sek = | |||
sekundy % 60 | |||
if | if sek == 0 then | ||
return " | return tostring(minuty) .. " min" | ||
end | end | ||
return | |||
tostring(minuty) .. | |||
":" .. | |||
string.format( | |||
"%02d", | |||
sek | |||
) .. | |||
" min" | |||
end | |||
return | local function escapeSQL(value) | ||
end | value = tostring(value or "") | ||
return mw.ustring.gsub( | |||
value, | |||
"'", | |||
"''" | |||
) | |||
end | |||
-- ========================================================= | -- ========================================================= | ||
-- | -- ROZPOZNANIE MIEJSCA MECZU | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function miejsceMeczu(row, druzyna) | ||
local d1 = | local d1 = | ||
row.druzyna1 or "" | tostring(row.druzyna1 or "") | ||
local d2 = | local d2 = | ||
row.druzyna2 or "" | tostring(row.druzyna2 or "") | ||
if d1 == druzyna then | |||
return "dom" | |||
end | |||
if d2 == druzyna then | |||
return "wyjazd" | |||
end | |||
return nil | |||
end | |||
-- ========================================================= | |||
-- WYNIK MECZU | |||
-- ========================================================= | |||
local function wynikMeczu(row) | |||
local g1 = | |||
tonumber(row.gole1 or "") | |||
local g2 = | |||
tonumber(row.gole2 or "") | |||
end | if g1 ~= nil and g2 ~= nil then | ||
return g1, g2 | |||
end | |||
local wynik = | |||
tostring(row.wynik or "") | |||
local | local a, b = | ||
mw.ustring.match( | |||
wynik, | |||
"(%d+)%s*:%s*(%d+)" | |||
) | |||
if | if a and b then | ||
return | |||
tonumber(a), | |||
tonumber(b) | |||
end | |||
return nil, nil | |||
end | |||
-- ========================================================= | |||
-- WYNIK Z PERSPEKTYWY DRUŻYNY | |||
-- ========================================================= | |||
local function wynikZPerspektywy(row, druzyna) | |||
local g1, g2 = | |||
wynikMeczu(row) | |||
if g1 == nil or g2 == nil then | |||
return nil, nil | |||
end | end | ||
local miejsce = | |||
miejsceMeczu( | |||
row, | |||
druzyna | |||
) | ) | ||
if miejsce == "dom" then | |||
return g1, g2 | |||
elseif miejsce == "wyjazd" then | |||
return | return g2, g1 | ||
end | end | ||
return nil, nil | |||
return nil, | |||
end | end | ||
| Linia 243: | Linia 244: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- NAZWA MECZU | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function nazwaMeczu(row) | ||
local | local d1 = | ||
tostring(row.druzyna1 or "") | |||
local d2 = | |||
tostring(row.druzyna2 or "") | |||
local strona = | |||
tostring(row.strona_meczu or "") | |||
local tekst = | |||
d1 .. | |||
" – " .. | |||
d2 | |||
if strona ~= "" then | |||
return | |||
return " | "[[" .. | ||
strona .. | |||
"|" .. | |||
tekst .. | |||
"]]" | |||
end | end | ||
return tekst | |||
end | |||
-- ========================================================= | |||
-- 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 dodajRekord( | |||
tabela, | |||
miejsce, | |||
wartosc, | |||
item | |||
) | |||
if wartosc == nil then | |||
if | return | ||
return | |||
end | end | ||
wartosc = | |||
tonumber(wartosc) | |||
if | if wartosc == nil then | ||
return | return | ||
end | end | ||
item.wartosc = | |||
wartosc | |||
local lista = | |||
tabela[miejsce] | |||
if #lista == 0 then | |||
table.insert( | |||
lista, | |||
item | |||
) | |||
return | |||
end | end | ||
local obecna = | |||
tonumber( | |||
lista[1].wartosc | |||
) or 0 | |||
if | if wartosc > obecna then | ||
tabela[miejsce] = { | |||
item | |||
} | |||
elseif wartosc == obecna then | |||