Moduł:Rekordy sezon: Różnice pomiędzy wersjami
Wygląd
Nie podano opisu zmian |
Nie podano opisu zmian |
||
| (Nie pokazano 3 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 13: | Linia 11: | ||
-- |sezon=2026/2027 | -- |sezon=2026/2027 | ||
-- |druzyna=Lech Poznań | -- |druzyna=Lech Poznań | ||
-- |dyscyplina= | -- |dyscyplina=piłka nożna | ||
-- }} | -- }} | ||
-- | -- | ||
-- | -- lub: | ||
-- | -- | ||
-- | -- {{#invoke:Rekordy_sezon|main | ||
-- | -- |sezon=2026/2027 | ||
-- | -- |druzyna=Enea Basket Poznań | ||
-- |dyscyplina=koszykówka | |||
-- }} | |||
-- ========================================================= | -- ========================================================= | ||
| Linia 38: | Linia 35: | ||
value = tostring(value) | value = tostring(value) | ||
value = mw.ustring.gsub(value, "%s+", "") | |||
value = mw.ustring.gsub( | |||
value, | |||
"%s+", | |||
"" | |||
) | |||
return tonumber(value) or 0 | return tonumber(value) or 0 | ||
| Linia 45: | Linia 47: | ||
-- ========================================================= | |||
-- 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) | |||
value = mw.ustring.gsub( | |||
value, | |||
"%s+", | |||
"" | |||
) | |||
local minuty, sekundy = | |||
mw.ustring.match( | |||
value, | |||
"^(%d+):(%d+)$" | |||
) | |||
if minuty and sekundy then | |||
return | |||
tonumber(minuty) * 60 + | |||
tonumber(sekundy) | |||
end | |||
local liczbaMinut = | |||
tonumber(value) | |||
if liczbaMinut then | |||
return liczbaMinut * 60 | |||
end | end | ||
return 0 | |||
end | |||
local | |||
-- ========================================================= | |||
-- FORMAT MINUT | |||
-- ========================================================= | |||
local function formatMinut(sekundy) | |||
sekundy = tonumber(sekundy) or 0 | |||
local minuty = | |||
math.floor( | |||
sekundy / 60 | |||
) | ) | ||
if | local sek = | ||
return | sekundy % 60 | ||
if sek == 0 then | |||
return tostring(minuty) .. " min" | |||
end | end | ||
return | return | ||
tostring(minuty) .. | |||
":" .. | |||
string.format( | |||
"%02d", | |||
sek | |||
) .. | |||
" min" | |||
end | |||
local function escapeSQL(value) | |||
value = tostring(value or "") | |||
return mw.ustring.gsub( | |||
value, | |||
"'", | |||
"''" | |||
) | |||
end | end | ||
| Linia 89: | Linia 145: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- ROZPOZNANIE MIEJSCA MECZU | ||
-- ========================================================= | -- ========================================================= | ||
local function miejsceMeczu(row, druzyna) | local function miejsceMeczu(row, druzyna) | ||
local d1 = tostring(row.druzyna1 or "") | local d1 = | ||
local d2 = tostring(row.druzyna2 or "") | tostring(row.druzyna1 or "") | ||
local d2 = | |||
tostring(row.druzyna2 or "") | |||
if d1 == druzyna then | if d1 == druzyna then | ||
| Linia 111: | Linia 170: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- WYNIK MECZU | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function wynikMeczu(row) | ||
local | local g1 = | ||
tonumber(row.gole1 or "") | |||
local | local g2 = | ||
tonumber(row.gole2 or "") | |||
if | if g1 ~= nil and g2 ~= nil then | ||
return g1, g2 | |||
end | |||
local wynik = | |||
" | tostring(row.wynik or "") | ||
local a, b = | |||
mw.ustring.match( | |||
wynik, | |||
"(%d+)%s*:%s*(%d+)" | |||
) | |||
if a and b then | |||
return | |||
tonumber(a), | |||
tonumber(b) | |||
end | end | ||
return | |||
return nil, nil | |||
end | end | ||
| Linia 139: | Linia 210: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- WYNIK Z PERSPEKTYWY DRUŻYNY | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function wynikZPerspektywy(row, druzyna) | ||
if | local g1, g2 = | ||
wynikMeczu(row) | |||
if g1 == nil or g2 == nil then | |||
return nil, nil | |||
end | end | ||
local | 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 | |||
end | |||
-- ========================================================= | |||
-- NAZWA MECZU | |||
-- ========================================================= | |||
local function nazwaMeczu(row) | |||
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 | |||
"[[" .. | |||
strona .. | |||
"|" .. | |||
tekst .. | |||
"]]" | |||
end | end | ||
return tekst | |||
end | end | ||
| Linia 183: | Linia 281: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- 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 | local function dodajRekord( | ||
tabela, | |||
miejsce, | |||
wartosc, | |||
item | |||
) | ) | ||
if wartosc == nil then | |||
return | |||
end | |||
wartosc = | |||
tonumber(wartosc) | |||
if wartosc == nil then | |||
return | |||
end | |||
item.wartosc = | |||
wartosc | |||
local lista = | |||
tabela[miejsce] | |||
if #lista == 0 then | |||
table.insert( | |||
lista, | |||
item | |||
) | |||
return | |||
end | |||
local obecna = | |||
tonumber( | |||
lista[1].wartosc | |||
) or 0 | |||
if wartosc > obecna then | |||
tabela[miejsce] = { | |||
item | |||
} | |||
elseif wartosc == obecna then | |||
table.insert( | |||
lista, | |||
item | |||
) | |||
end | |||
end | |||
-- ========================================================= | |||
-- FORMAT REKORDÓW MECZOWYCH | |||
-- ========================================================= | |||
local function tekstMeczow(lista) | |||
if not lista or #lista == 0 then | |||
return "—" | |||
end | |||
local wynik = {} | |||
for _, item in ipairs(lista) do | |||
local roznica = | |||
tonumber( | |||
item.roznica or 0 | |||
) or 0 | |||