Moduł:HistoriaWystepowPiłka
Wygląd
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:HistoriaWystepowPiłka/opis
local p = {}
-- =========================================================
-- MODUŁ:HISTORIAWYSTĘPÓWPIŁKA
--
-- Historia występów zawodnika w piłce nożnej
--
-- Pokazuje wyłącznie występy zawodnika
-- w drużynach poznańskich.
--
-- Liczy się UdzialZawodnika.druzyna,
-- a NIE przeciwnik.
-- =========================================================
-- =========================================================
-- DRUŻYNY POZNAŃSKIE
-- =========================================================
local druzynyPoznanskie = {
["Lech Poznań"] = true,
["Lech Poznań UAM"] = true,
["Warta Poznań"] = true,
["Enea AZS Politechnika Poznań"] = true,
["AZS Politechnika Poznań"] = true,
["MUKS Poznań"] = true
}
function p.main(frame)
local zawodnik =
mw.text.trim(
frame.args.zawodnik or ""
)
if zawodnik == "" then
zawodnik =
mw.title
.getCurrentTitle()
.text
end
-- =====================================================
-- BEZPIECZNE PRZYGOTOWANIE NAZWY ZAWODNIKA
-- =====================================================
local zawodnikSQL =
mw.ustring.gsub(
zawodnik,
"'",
"''"
)
-- =====================================================
-- POLA POBIERANE Z CARGO
-- =====================================================
local fields = table.concat({
"UdzialZawodnika.mecz=mecz",
"UdzialZawodnika.druzyna=druzyna",
"UdzialZawodnika.minuty=minuty",
"UdzialZawodnika.minuty_format=minuty_format",
"UdzialZawodnika.gol=gol",
"UdzialZawodnika.asysta=asysta",
"UdzialZawodnika.kartka=kartka",
"UdzialZawodnika.zolta_kartka=zolta_kartka",
"UdzialZawodnika.czerwona_kartka=czerwona_kartka",
"Mecze.data=data",
"Mecze.sezon=sezon",
"Mecze.druzyna1=druzyna1",
"Mecze.druzyna2=druzyna2",
"Mecze.gole1=gole1",
"Mecze.gole2=gole2",
"Mecze.wynik=wynik",
"Mecze.strona_meczu=strona_meczu"
}, ",")
-- =====================================================
-- ZAPYTANIE CARGO
-- =====================================================
local args = {
join =
"UdzialZawodnika.mecz=Mecze.id",
where =
"UdzialZawodnika.zawodnik='"
.. zawodnikSQL
.. "' AND UdzialZawodnika.minuty > 0",
orderBy =
"Mecze.data ASC",
limit = 5000
}
local rows =
mw.ext.cargo.query(
"UdzialZawodnika,Mecze",
fields,
args
)
-- =====================================================
-- FILTR DRUŻYN POZNAŃSKICH
-- =====================================================
local tylkoPoznanskie = {}
if rows then
for _, row in ipairs(rows) do
local druzyna =
mw.text.trim(
row.druzyna or ""
)
if druzynyPoznanskie[druzyna] then
table.insert(
tylkoPoznanskie,
row
)
end
end
end
rows =
tylkoPoznanskie
-- =====================================================
-- BRAK DANYCH
-- =====================================================
if not rows or #rows == 0 then
return
"''Brak wprowadzonych występów zawodnika "
.. "dla drużyn poznańskich w bazie.''"
end
-- =====================================================
-- PODSUMOWANIE
-- =====================================================
local function nowePodsumowanie()
return {
wystepy = 0,
zwyciestwa = 0,
porazki = 0,
remisy = 0,
gole = 0,
asysty = 0,
minuty = 0,
zolte = 0,
czerwone = 0
}
end
local suma =
nowePodsumowanie()
local dom =
nowePodsumowanie()
local wyjazd =
nowePodsumowanie()
local sezony = {}
local kluby = {}
-- =====================================================
-- OKREŚLENIE WYNIKU MECZU
-- =====================================================
local function okreslWynik(row)
local d1 =
row.druzyna1 or ""
local d2 =
row.druzyna2 or ""
local druzyna =
row.druzyna or ""
local wynikMeczu =
row.wynik or ""
local g1, g2 =
wynikMeczu:match(
"(%d+)%s*:%s*(%d+)"
)
if not g1 or not g2 then
return nil
end
g1 =
tonumber(g1)
g2 =
tonumber(g2)
if druzyna == d1 then
if g1 > g2 then
return "W"
elseif g1 < g2 then
return "P"
else
return "R"
end
elseif druzyna == d2 then
if g2 > g1 then
return "W"
elseif g2 < g1 then
return "P"
else
return "R"
end
end
return nil
end
-- =====================================================
-- KARTKI
-- =====================================================
local function policzKartki(row)
local zolte = 0
local czerwone = 0
-- -----------------------------------------------
-- Jeżeli korzystasz z pól liczbowych
-- -----------------------------------------------
zolte =
tonumber(row.zolta_kartka or 0)
or 0
czerwone =
tonumber(row.czerwona_kartka or 0)
or 0
-- -----------------------------------------------
-- Obsługa obecnego zapisu:
--
-- |kartka=zol
-- |kartka=czer
-- -----------------------------------------------
local kartka =
mw.text.trim(
row.kartka or ""
)
if kartka == "zol" then
zolte = zolte + 1
elseif kartka == "czer" then
czerwone = czerwone + 1
end
return zolte, czerwone
end
-- =====================================================
-- DODANIE MECZU DO PODSUMOWANIA
-- =====================================================
local function dodajDoPodsumowania(
stat,
row
)
stat.wystepy =
stat.wystepy + 1
stat.gole =
stat.gole
+ (
tonumber(row.gol or 0)
or 0
)
stat.asysty =
stat.asysty
+ (
tonumber(row.asysta or 0)
or 0
)
stat.minuty =
stat.minuty
+ (
tonumber(row.minuty or 0)
or 0
)
local zolte, czerwone =
policzKartki(row)
stat.zolte =
stat.zolte + zolte
stat.czerwone =
stat.czerwone + czerwone
local wynik =
okreslWynik(row)
if wynik == "W" then
stat.zwyciestwa =
stat.zwyciestwa + 1
elseif wynik == "P" then
stat.porazki =
stat.porazki + 1
elseif wynik == "R" then
stat.remisy =
stat.remisy + 1
end
end
-- =====================================================
-- PRZEJŚCIE PRZEZ WSZYSTKIE MECZE
-- =====================================================
for _, row in ipairs(rows) do
-- -----------------------------------------------
-- WSZYSTKIE
-- -----------------------------------------------
dodajDoPodsumowania(
suma,
row
)
-- -----------------------------------------------
-- DOM / WYJAZD
-- -----------------------------------------------
local d1 =
row.druzyna1 or ""
local d2 =
row.druzyna2 or ""
local druzyna =
row.druzyna or ""
if druzyna == d1 then
dodajDoPodsumowania(
dom,
row
)
elseif druzyna == d2 then
dodajDoPodsumowania(
wyjazd,
row
)
end
-- -----------------------------------------------
-- SEZON
-- -----------------------------------------------
local sezon =
row.sezon or ""
if sezon == "" then
sezon =
"Brak sezonu"
end
if not sezony[sezon] then
sezony[sezon] =
nowePodsumowanie()
end
dodajDoPodsumowania(
sezony[sezon],
row
)
-- -----------------------------------------------
-- KLUB
-- -----------------------------------------------
if druzyna == "" then
druzyna =
"Brak klubu"
end
if not kluby[druzyna] then
kluby[druzyna] =
nowePodsumowanie()
end
dodajDoPodsumowania(
kluby[druzyna],
row
)
end
-- =====================================================
-- FORMATOWANIE MINUT
-- =====================================================
local function formatujMinuty(minuty)
local godziny =
math.floor(
minuty / 60
)
local min =
minuty % 60
return string.format(
"%d:%02d",
godziny,
min
)
end
-- =====================================================
-- SORTOWANIE SEZONÓW
-- =====================================================
local listaSezonow = {}
for sezon, _ in pairs(sezony) do
table.insert(
listaSezonow,
sezon
)
end
table.sort(
listaSezonow,
function(a, b)
return a > b
end
)
-- =====================================================
-- SORTOWANIE KLUBÓW
-- =====================================================
local listaKlubow = {}
for klub, _ in pairs(kluby) do
table.insert(
listaKlubow,
klub
)
end
table.sort(
listaKlubow
)
-- =====================================================
-- OPIS MECZU
-- =====================================================
local function rekordMecz(row)
local d1 =
row.druzyna1 or ""
local d2 =
row.druzyna2 or ""
local data =
row.data or ""
local wynikMeczu =
row.wynik or ""
local strona =
row.strona_meczu or ""
local meczTekst =
d1
.. " – "
.. d2
if strona ~= "" then
meczTekst =
"[["
.. strona
.. "|"
.. d1
.. " – "
.. d2
.. "]]"
end
if data ~= "" then
meczTekst =
meczTekst
.. " ("
.. data
.. ")"
end
if wynikMeczu ~= "" then
meczTekst =
meczTekst
.. " "
.. wynikMeczu
end
return meczTekst
end
-- =====================================================
-- REKORDY
-- =====================================================
local rekordGole = -1
local rekordAsysty = -1
local rekordMinuty = -1
local meczeGole = {}
local meczeAsysty = {}
local meczeMinuty = {}
-- =====================================================
-- WYSZUKIWANIE REKORDÓW
-- =====================================================
for _, row in ipairs(rows) do
local gole =
tonumber(row.gol or 0)
or 0
local asysty =
tonumber(row.asysta or 0)
or 0
local minuty =
tonumber(row.minuty or 0)
or 0
-- -----------------------------------------------
-- GOLE
-- -----------------------------------------------
if gole > rekordGole then
rekordGole =
gole
meczeGole =
{ row }
elseif gole == rekordGole then
table.insert(
meczeGole,
row
)
end
-- -----------------------------------------------
-- ASYSTY
-- -----------------------------------------------
if asysty > rekordAsysty then
rekordAsysty =
asysty
meczeAsysty =
{ row }
elseif asysty == rekordAsysty then
table.insert(
meczeAsysty,
row
)
end
-- -----------------------------------------------
-- MINUTY
-- -----------------------------------------------
if minuty > rekordMinuty then
rekordMinuty =
minuty
meczeMinuty =
{ row }
elseif minuty == rekordMinuty then
table.insert(
meczeMinuty,
row
)
end
end
-- =====================================================
-- LISTA REKORDÓW
-- =====================================================
local function listaRekordow(lista)
local wynikRekordu = {}
for _, row in ipairs(lista) do
table.insert(
wynikRekordu,
rekordMecz(row)
)
end
return table.concat(
wynikRekordu,
"<br>"
)
end
-- =====================================================
-- WYNIK KOŃCOWY
-- =====================================================
local wynik = {}
-- =====================================================
-- HISTORIA
-- =====================================================
table.insert(
wynik,
"== Historia występów =="
)
table.insert(
wynik,
""
)
-- =====================================================
-- PODSUMOWANIE
-- =====================================================
table.insert(
wynik,
"=== Podsumowanie wszystkich spotkań ==="
)
table.insert(
wynik,
""
)
table.insert(
wynik,
'{| class="wikitable" style="width:100%; text-align:center;"'
)
table.insert(wynik, "! ")
table.insert(wynik, "! Wszystkie spotkania")
table.insert(wynik, "! 🏠 Mecze domowe")
table.insert(wynik, "! ✈️ Mecze wyjazdowe")
-- WYSTĘPY
table.insert(wynik, "|-")
table.insert(wynik, "! Występy")
table.insert(wynik, "| '''" .. suma.wystepy .. "'''")
table.insert(wynik, "| '''" .. dom.wystepy .. "'''")
table.insert(wynik, "| '''" .. wyjazd.wystepy .. "'''")
-- ZWYCIĘSTWA
table.insert(wynik, "|-")
table.insert(wynik, "! Zwycięstwa")
table.insert(wynik, "| '''" .. suma.zwyciestwa .. "'''")
table.insert(wynik, "| '''" .. dom.zwyciestwa .. "'''")
table.insert(wynik, "| '''" .. wyjazd.zwyciestwa .. "'''")
-- REMISY
table.insert(wynik, "|-")
table.insert(wynik, "! Remisy")
table.insert(wynik, "| '''" .. suma.remisy .. "'''")
table.insert(wynik, "| '''" .. dom.remisy .. "'''")
table.insert(wynik, "| '''" .. wyjazd.remisy .. "'''")
-- PORAŻKI
table.insert(wynik, "|-")
table.insert(wynik, "! Porażki")
table.insert(wynik, "| '''" .. suma.porazki .. "'''")
table.insert(wynik, "| '''" .. dom.porazki .. "'''")
table.insert(wynik, "| '''" .. wyjazd.porazki .. "'''")
-- GOLE
table.insert(wynik, "|-")
table.insert(wynik, "! ⚽ Gole")
table.insert(wynik, "| '''" .. suma.gole .. "'''")
table.insert(wynik, "| '''" .. dom.gole .. "'''")
table.insert(wynik, "| '''" .. wyjazd.gole .. "'''")
-- ASYSTY
table.insert(wynik, "|-")
table.insert(wynik, "! 🎯 Asysty")
table.insert(wynik, "| '''" .. suma.asysty .. "'''")
table.insert(wynik, "| '''" .. dom.asysty .. "'''")
table.insert(wynik, "| '''" .. wyjazd.asysty .. "'''")
-- MINUTY
table.insert(wynik, "|-")
table.insert(wynik, "! ⏱ Minuty")
table.insert(
wynik,
"| '''"
.. formatujMinuty(suma.minuty)
.. "'''"
)
table.insert(
wynik,
"| '''"
.. formatujMinuty(dom.minuty)
.. "'''"
)
table.insert(
wynik,
"| '''"
.. formatujMinuty(wyjazd.minuty)
.. "'''"
)
-- ŻÓŁTE
table.insert(wynik, "|-")
table.insert(wynik, "! 🟨 Żółte kartki")
table.insert(wynik, "| '''" .. suma.zolte .. "'''")
table.insert(wynik, "| '''" .. dom.zolte .. "'''")
table.insert(wynik, "| '''" .. wyjazd.zolte .. "'''")
-- CZERWONE
table.insert(wynik, "|-")
table.insert(wynik, "! 🟥 Czerwone kartki")
table.insert(wynik, "| '''" .. suma.czerwone .. "'''")
table.insert(wynik, "| '''" .. dom.czerwone .. "'''")
table.insert(wynik, "| '''" .. wyjazd.czerwone .. "'''")
table.insert(
wynik,
"|}"
)
table.insert(
wynik,
""
)
-- =====================================================
-- NAJLEPSZE WYSTĘPY
-- =====================================================
table.insert(
wynik,
"=== Najlepsze występy ==="
)
table.insert(
wynik,
""
)
table.insert(
wynik,
'{| class="wikitable" style="width:100%;"'
)
table.insert(wynik, "! Rekord")
table.insert(wynik, "! Wynik")
table.insert(wynik, "! Mecz / mecze")
-- GOLE
table.insert(wynik, "|-")
table.insert(wynik, "! ⚽ Najwięcej goli")
table.insert(
wynik,
"| '''" .. rekordGole .. "'''"
)
table.insert(
wynik,
"| " .. listaRekordow(meczeGole)
)
-- ASYSTY
table.insert(wynik, "|-")
table.insert(wynik, "! 🎯 Najwięcej asyst")
table.insert(
wynik,
"| '''" .. rekordAsysty .. "'''"
)
table.insert(
wynik,
"| " .. listaRekordow(meczeAsysty)
)
-- MINUTY
table.insert(wynik, "|-")
table.insert(wynik, "! ⏱ Najwięcej minut")
table.insert(
wynik,
"| '''"
.. formatujMinuty(rekordMinuty)
.. "'''"
)
table.insert(
wynik,
"| " .. listaRekordow(meczeMinuty)
)
table.insert(
wynik,
"|}"
)
table.insert(
wynik,
""
)
-- =====================================================
-- PODSUMOWANIE SEZONÓW
-- =====================================================
table.insert(
wynik,
"=== Podsumowanie sezonów ==="
)
table.insert(
wynik,
""
)
table.insert(
wynik,
'{| class="wikitable sortable" style="width:100%; text-align:center;"'
)
table.insert(wynik, "! Sezon")
table.insert(wynik, "! Występy")
table.insert(wynik, "! Z")
table.insert(wynik, "! R")
table.insert(wynik, "! P")
table.insert(wynik, "! ⚽ Gole")
table.insert(wynik, "! 🎯 Asysty")
table.insert(wynik, "! Minuty")
table.insert(wynik, "! 🟨")
table.insert(wynik, "! 🟥")
for _, sezon in ipairs(listaSezonow) do
local stat =
sezony[sezon]
table.insert(wynik, "|-")
table.insert(
wynik,
"| '''"
.. sezon
.. "'''"
)
table.insert(
wynik,
"| " .. stat.wystepy
)
table.insert(
wynik,
"| " .. stat.zwyciestwa
)
table.insert(
wynik,
"| " .. stat.remisy
)
table.insert(
wynik,
"| " .. stat.porazki
)
table.insert(
wynik,
"| " .. stat.gole
)
table.insert(
wynik,
"| " .. stat.asysty
)
table.insert(
wynik,
"| "
.. formatujMinuty(
stat.minuty
)
)
table.insert(
wynik,
"| " .. stat.zolte
)
table.insert(
wynik,
"| " .. stat.czerwone
)
end
table.insert(
wynik,
"|}"
)
table.insert(
wynik,
""
)
-- =====================================================
-- PODSUMOWANIE WEDŁUG KLUBU
-- =====================================================
table.insert(
wynik,
"=== Podsumowanie według klubu ==="
)
table.insert(
wynik,
""
)
table.insert(
wynik,
'{| class="wikitable sortable" style="width:100%; text-align:center;"'
)
table.insert(wynik, "! Klub")
table.insert(wynik, "! Występy")
table.insert(wynik, "! Z")
table.insert(wynik, "! R")
table.insert(wynik, "! P")
table.insert(wynik, "! ⚽ Gole")
table.insert(wynik, "! 🎯 Asysty")
table.insert(wynik, "! Minuty")
table.insert(wynik, "! 🟨")
table.insert(wynik, "! 🟥")
for _, klub in ipairs(listaKlubow) do
local stat =
kluby[klub]
table.insert(
wynik,
"|-"
)
table.insert(
wynik,
"| '''"
.. klub
.. "'''"
)
table.insert(
wynik,
"| " .. stat.wystepy
)
table.insert(
wynik,
"| " .. stat.zwyciestwa
)
table.insert(
wynik,
"| " .. stat.remisy
)
table.insert(
wynik,
"| " .. stat.porazki
)
table.insert(
wynik,
"| " .. stat.gole
)
table.insert(
wynik,
"| " .. stat.asysty
)
table.insert(
wynik,
"| "
.. formatujMinuty(
stat.minuty
)
)
table.insert(
wynik,
"| " .. stat.zolte
)
table.insert(
wynik,
"| " .. stat.czerwone
)
end
table.insert(
wynik,
"|}"
)
table.insert(
wynik,
""
)
-- =====================================================
-- TABELA WSZYSTKICH WYSTĘPÓW
-- =====================================================
table.insert(
wynik,
"=== Mecze ==="
)
table.insert(
wynik,
""
)
table.insert(
wynik,
'{| class="wikitable sortable" style="width:100%;"'
)
table.insert(wynik, "! Nr")
table.insert(wynik, "! Sezon")
table.insert(wynik, "! Data")
table.insert(wynik, "! Miejsce")
table.insert(wynik, "! Przeciwnik")
table.insert(wynik, "! Wynik")
table.insert(wynik, "! Min.")
table.insert(wynik, "! ⚽")
table.insert(wynik, "! 🎯")
table.insert(wynik, "! 🟨")
table.insert(wynik, "! 🟥")
table.insert(wynik, "! Jubileusz")
-- =====================================================
-- POSZCZEGÓLNE MECZE
-- =====================================================
for i, row in ipairs(rows) do
local data =
row.data or ""
local sezon =
row.sezon or ""
local d1 =
row.druzyna1 or ""
local d2 =
row.druzyna2 or ""
local druzyna =
row.druzyna or ""
local wynikMeczu =
row.wynik or ""
local strona =
row.strona_meczu or ""
local minutyFormat =
row.minuty_format or ""
-- jeżeli nie ma minuty_format
if minutyFormat == "" then
minutyFormat =
row.minuty or "0"
end
local gole =
row.gol or "0"
local asysty =
row.asysta or "0"
local zolte,
czerwone =
policzKartki(row)
-- -----------------------------------------------
-- DOM / WYJAZD
-- -----------------------------------------------
local miejsce = ""
if druzyna == d1 then
miejsce =
"🏠 Dom"
elseif druzyna == d2 then
miejsce =
"✈️ Wyjazd"
end
-- -----------------------------------------------
-- PRZECIWNIK
-- -----------------------------------------------
local przeciwnik = ""
if druzyna == d1 then
przeciwnik =
d2
elseif druzyna == d2 then
przeciwnik =
d1
else
przeciwnik =
d1
end
-- -----------------------------------------------
-- LINK DO MECZU
-- -----------------------------------------------
local meczTekst =
przeciwnik
if strona ~= "" then
meczTekst =
"[["
.. strona
.. "|"
.. przeciwnik
.. "]]"
end
-- -----------------------------------------------
-- JUBILEUSZ
-- -----------------------------------------------
local jubileusz = ""
if i % 50 == 0 then
jubileusz =
"'''🏆 "
.. i
.. ". występ'''"
end
-- -----------------------------------------------
-- WIERSZ
-- -----------------------------------------------
table.insert(
wynik,
"|-"
)
table.insert(
wynik,
"| " .. i
)
table.insert(
wynik,
"| " .. sezon
)
table.insert(
wynik,
"| " .. data
)
table.insert(
wynik,
"| " .. miejsce
)
table.insert(
wynik,
"| " .. meczTekst
)
table.insert(
wynik,
"| " .. wynikMeczu
)
table.insert(
wynik,
"| " .. minutyFormat
)
table.insert(
wynik,
"| " .. gole
)
table.insert(
wynik,
"| " .. asysty
)
table.insert(
wynik,
"| " .. zolte
)
table.insert(
wynik,
"| " .. czerwone
)
table.insert(
wynik,
"| " .. jubileusz
)
end
-- =====================================================
-- KONIEC TABELI
-- =====================================================
table.insert(
wynik,
"|}"
)
-- =====================================================
-- ZWRÓCENIE WYNIKU
-- =====================================================
return table.concat(
wynik,
"\n"
)
end
return p