Moduł:Rekordy sezon: Różnice pomiędzy wersjami
Wygląd
Nie podano opisu zmian |
Nie podano opisu zmian |
||
| (Nie pokazano 8 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 28: | ||
-- FUNKCJE WSPÓLNE | -- FUNKCJE WSPÓLNE | ||
-- ========================================================= | -- ========================================================= | ||
local function liczba(value) | local function liczba(value) | ||
| Linia 57: | Linia 48: | ||
local function escapeSQL(value) | |||
value = tostring(value or "") | |||
return mw.ustring.gsub( | |||
value, | |||
"'", | |||
"''" | |||
) | ) | ||
end | |||
-- ========================================================= | |||
-- ROZPOZNANIE MIEJSCA MECZU | |||
-- ========================================================= | |||
local function miejsceMeczu(row, druzyna) | |||
local d1 = | |||
tostring(row.druzyna1 or "") | |||
local d2 = | |||
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 "") | |||
if g1 ~= nil and g2 ~= nil then | |||
return g1, g2 | |||
end | |||
local wynik = | |||
tostring(row.wynik or "") | |||
local a, b = | local a, b = | ||
mw.ustring.match( | |||
wynik, | |||
"(%d+)%s*:%s*(%d+)" | "(%d+)%s*:%s*(%d+)" | ||
) | ) | ||
if a and b then | if a and b then | ||
| Linia 104: | Linia 127: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- WYNIK Z PERSPEKTYWY DRUŻYNY | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function wynikZPerspektywy(row, druzyna) | ||
row, | |||
local g1, g2 = | |||
wynikMeczu(row) | |||
if g1 == nil or g2 == nil then | |||
return nil, nil | |||
end | |||
local | local miejsce = | ||
row | miejsceMeczu( | ||
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 141: | Linia 167: | ||
local d1 = | local d1 = | ||
row.druzyna1 or "" | tostring(row.druzyna1 or "") | ||
local d2 = | local d2 = | ||
row.druzyna2 or "" | tostring(row.druzyna2 or "") | ||
local strona = | |||
tostring(row.strona_meczu or "") | |||
local tekst = | local tekst = | ||
d1 .. " – " .. | d1 .. | ||
" – " .. | |||
d2 | |||
if strona ~= "" then | if strona ~= "" then | ||
return "[[" .. | return | ||
"[[" .. | |||
strona .. | strona .. | ||
"|" .. | "|" .. | ||
| Linia 163: | Linia 191: | ||
end | end | ||
return tekst | return tekst | ||
| Linia 171: | Linia 198: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- FUNKCJA DODAWANIA REKORDU | ||
-- | -- UŻYWANA PRZEZ PIŁKĘ NOŻNĄ | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function dodajRekord( | ||
tabela, | |||
if | miejsce, | ||
return | wartosc, | ||
item | |||
) | |||
if wartosc == nil then | |||
return | |||
end | end | ||
local lista = | |||
tabela[miejsce] | |||
if #lista == 0 then | |||
table.insert( | |||
lista, | |||
item | |||
) | |||
return | |||
end | |||
local obecna = | |||
lista[1].wartosc | |||
if wartosc > obecna then | |||
tabela[miejsce] = { | |||
item | |||
} | |||
elseif wartosc == obecna then | |||
table.insert( | |||
lista, | |||
item | |||
) | ) | ||
end | |||
end | |||
end | |||
-- ========================================================= | -- ========================================================= | ||
-- | -- FORMAT REKORDÓW MECZOWYCH | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function tekstMeczow(lista) | ||
if not lista or #lista == 0 then | |||
return "—" | |||
if not | |||
return | |||
end | end | ||
local wynik = {} | |||
for _, item in ipairs(lista) do | |||
local roznica = | |||
item.roznica or 0 | |||
local roznicaTekst | |||
if roznica >= 0 then | |||
roznicaTekst = | |||
"+" .. | |||
tostring(roznica) | |||
else | |||
roznicaTekst = | |||
tostring(roznica) | |||
end | |||
table.insert( | |||
wynik, | |||
item.tekst .. | |||
" (" .. | |||
item.wynik .. | |||
", " .. | |||
roznicaTekst .. | |||
")" | |||
) | |||
end | end | ||
return table.concat( | |||
wynik, | |||
"<br>" | |||
) | |||
end | |||
-- ========================================================= | |||
-- FORMAT REKORDÓW ZAWODNIKÓW | |||
-- ========================================================= | |||
local function tekstZawodnikow( | |||
lista, | |||
typ | |||
) | |||
if not lista or #lista == 0 then | |||
if | return "—" | ||
return " | |||
end | end | ||
local wynik = {} | |||
for _, item in ipairs(lista) do | |||
local zawodnikLink = | |||
"[[" .. | |||
tostring(item.zawodnik or "") .. | |||
"]]" | |||
local wartosc = "" | |||
if typ == "punkty" then | |||
wartosc = | |||
tostring(item.punkty) .. | |||
" pkt" | |||
elseif typ == "minuty" then | |||
wartosc = | |||
tostring( | |||
item.minuty_format or "" | |||
) | |||
if wartosc == "" then | |||
wartosc = | |||
tostring( | |||
item.minuty or 0 | |||
) | |||
end | |||