Moduł:HistoriaWystepow: Różnice pomiędzy wersjami
Wygląd
Utworzono nową stronę "local p = {} function p.main(frame) local zawodnik = frame.args.zawodnik or mw.title.getCurrentTitle().text if zawodnik == "" then return "" end -- Pobieramy tylko rzeczywiste występy: -- minuty > 0 local rows = mw.ext.cargo.query{ tables = "UdzialZawodnika,Mecze", join_on = "UdzialZawodnika.mecz=Mecze.id", fields = table.concat({ "UdzialZawodnika.mecz", "UdzialZawodnika.druzyna",…" |
Nie podano opisu zmian |
||
| Linia 3: | Linia 3: | ||
function p.main(frame) | function p.main(frame) | ||
local zawodnik = frame.args.zawodnik | local zawodnik = frame.args.zawodnik | ||
if zawodnik == "" then | if not zawodnik or zawodnik == "" then | ||
zawodnik = mw.title.getCurrentTitle().text | |||
end | end | ||
-- | -- Bezpieczne przygotowanie nazwy zawodnika do SQL | ||
local zawodnikSQL = mw.ustring.gsub(zawodnik, "'", "''") | |||
local | |||
-- ========================================== | |||
-- POBRANIE WYSTĘPÓW | |||
-- ========================================== | |||
local fields = table.concat({ | |||
"UdzialZawodnika.mecz=mecz", | |||
"UdzialZawodnika.druzyna=druzyna", | |||
"UdzialZawodnika.minuty=minuty", | |||
"UdzialZawodnika.minuty_format=minuty_format", | |||
"UdzialZawodnika.gol=gol", | |||
"UdzialZawodnika.eval=eval", | |||
"UdzialZawodnika.plusminus=plusminus", | |||
"Mecze.data=data", | |||
"Mecze.druzyna1=druzyna1", | |||
"Mecze.druzyna2=druzyna2", | |||
"Mecze.wynik=wynik", | |||
where = "UdzialZawodnika.zawodnik=" .. | "Mecze.strona_meczu=strona_meczu" | ||
}, ",") | |||
local args = { | |||
join = "UdzialZawodnika.mecz=Mecze.id", | |||
where = "UdzialZawodnika.zawodnik='" .. zawodnikSQL .. "' AND UdzialZawodnika.minuty > 0", | |||
orderBy = "Mecze.data ASC", | orderBy = "Mecze.data ASC", | ||
limit = 5000 | limit = 5000 | ||
} | } | ||
local rows = mw.ext.cargo.query( | |||
"UdzialZawodnika,Mecze", | |||
fields, | |||
args | |||
) | |||
if not rows or #rows == 0 then | if not rows or #rows == 0 then | ||
return "''Brak wprowadzonych występów w bazie.''" | return "''Brak wprowadzonych występów w bazie.''" | ||
end | end | ||
-- ========================================== | -- ========================================== | ||
| Linia 49: | Linia 56: | ||
local porazki = 0 | local porazki = 0 | ||
local remisy = 0 | local remisy = 0 | ||
local punkty = 0 | local punkty = 0 | ||
local sumaMinut = 0 | |||
local sumaEval = 0 | |||
local sumaPlusMinus = 0 | |||
for _, row in ipairs(rows) do | for _, row in ipairs(rows) do | ||
punkty = punkty + tonumber(row | punkty = punkty + tonumber(row.gol or 0) | ||
sumaMinut = sumaMinut + tonumber(row.minuty or 0) | |||
sumaEval = sumaEval + tonumber(row.eval or 0) | |||
sumaPlusMinus = sumaPlusMinus + tonumber(row.plusminus or 0) | |||
local | local d1 = row.druzyna1 or "" | ||
local | local d2 = row.druzyna2 or "" | ||
local | local druzyna = row.druzyna or "" | ||
local wynikMeczu = row | local wynikMeczu = row.wynik or "" | ||
local g1, g2 = wynikMeczu:match("(%d+)%s*:%s*(%d+)") | local g1, g2 = wynikMeczu:match("(%d+)%s*:%s*(%d+)") | ||
if g1 and g2 then | if g1 and g2 then | ||
g1 = tonumber(g1) | g1 = tonumber(g1) | ||
g2 = tonumber(g2) | g2 = tonumber(g2) | ||
if druzyna == d1 then | |||
if g1 > g2 then | |||
zwyciestwa = zwyciestwa + 1 | zwyciestwa = zwyciestwa + 1 | ||
elseif g1 < g2 then | |||
porazki = porazki + 1 | |||
else | else | ||
remisy = remisy + 1 | |||
end | end | ||
elseif druzyna == d2 then | elseif druzyna == d2 then | ||
if g2 > g1 then | |||
zwyciestwa = zwyciestwa + 1 | zwyciestwa = zwyciestwa + 1 | ||
elseif g2 < g1 then | |||
porazki = porazki + 1 | |||
else | else | ||
remisy = remisy + 1 | |||
end | end | ||
end | end | ||
end | end | ||
| Linia 92: | Linia 106: | ||
-- ========================================== | -- ========================================== | ||
-- | -- FORMAT MINUT | ||
-- ========================================== | -- ========================================== | ||
local godziny = math.floor(sumaMinut / 60) | |||
local minuty = sumaMinut % 60 | |||
local sumaMinutFormat = string.format( | |||
"%d:%02d", | |||
godziny, | |||
minuty | |||
) | |||
-- ========================================== | |||
-- WYNIK | |||
-- ========================================== | |||
local wynik = {} | |||
table.insert(wynik, "== Historia występów ==") | table.insert(wynik, "== Historia występów ==") | ||
table.insert(wynik, "") | table.insert(wynik, "") | ||
table.insert(wynik, | |||
" | -- ========================================== | ||
-- TABELA PODSUMOWANIA | |||
-- ========================================== | |||
table.insert( | |||
wynik, | |||
'{| class="wikitable" style="width:100%; text-align:center;"' | |||
) | ) | ||
table.insert(wynik, | table.insert(wynik, '! colspan="2" | Występy') | ||
table.insert(wynik, "! Zwycięstwa") | |||
table.insert(wynik, "! Porażki") | |||
table.insert(wynik, "! Remisy") | |||
table.insert(wynik, "! Punkty") | |||
table.insert(wynik, "! Minuty") | |||
) | table.insert(wynik, "! EVAL") | ||
table.insert(wynik, "! +/-") | |||
table.insert(wynik, "|-") | |||
table.insert(wynik, "| colspan=2 | '''" .. wystepy .. "'''") | |||
table.insert(wynik, "| '''" .. zwyciestwa .. "'''") | |||
table.insert(wynik, "| '''" .. porazki .. "'''") | |||
table.insert(wynik, "| '''" .. remisy .. "'''") | |||
table.insert(wynik, "| '''" .. punkty .. "'''") | |||
table.insert(wynik, "| " .. sumaMinutFormat) | |||
table.insert(wynik, "| " .. sumaEval) | |||
table.insert(wynik, "| " .. sumaPlusMinus) | |||
table.insert(wynik, "|}") | |||
table.insert(wynik, "") | table.insert(wynik, "") | ||
-- ========================================== | -- ========================================== | ||
-- TABELA | -- TABELA WYSTĘPÓW | ||
-- ========================================== | -- ========================================== | ||
table.insert(wynik, '{| class="wikitable sortable" style="width:100%;"') | table.insert( | ||
table.insert(wynik, "! | wynik, | ||
'{| class="wikitable sortable" style="width:100%;"' | |||
) | |||
table.insert(wynik, "! Nr") | |||
table.insert(wynik, "! Data") | table.insert(wynik, "! Data") | ||
table.insert(wynik, "! | table.insert(wynik, "! Przeciwnik") | ||
table.insert(wynik, "! Wynik") | table.insert(wynik, "! Wynik") | ||
table.insert(wynik, "! Min.") | table.insert(wynik, "! Min.") | ||
| Linia 127: | Linia 178: | ||
table.insert(wynik, "! +/-") | table.insert(wynik, "! +/-") | ||
table.insert(wynik, "! Jubileusz") | table.insert(wynik, "! Jubileusz") | ||
-- ========================================== | |||
-- POSZCZEGÓLNE MECZE | |||
-- ========================================== | |||
for i, row in ipairs(rows) do | for i, row in ipairs(rows) do | ||
local data = row | local data = row.data or "" | ||
local d1 = row | local d1 = row.druzyna1 or "" | ||
local d2 = row | local d2 = row.druzyna2 or "" | ||
local wynikMeczu = row | local druzyna = row.druzyna or "" | ||
local strona = row | local wynikMeczu = row.wynik or "" | ||
local | local strona = row.strona_meczu or "" | ||
local pkt = row | |||
local eval = row | local minutyFormat = row.minuty_format or "" | ||
local plusminus = row | local pkt = row.gol or "0" | ||
local eval = row.eval or "0" | |||
local plusminus = row.plusminus or "0" | |||
-- ====================================== | |||
-- PRZECIWNIK | |||
-- ====================================== | |||
local przeciwnik = "" | |||
local | |||
if druzyna == d1 then | if druzyna == d1 then | ||
przeciwnik = d2 | przeciwnik = d2 | ||
elseif druzyna == d2 then | |||
przeciwnik = d1 | |||
else | else | ||
przeciwnik = d1 | przeciwnik = d1 | ||
end | end | ||
-- | -- ====================================== | ||
local meczTekst | -- LINK DO STRONY MECZU | ||
-- ====================================== | |||
local meczTekst = przeciwnik | |||
if strona ~= "" then | if strona ~= "" then | ||
meczTekst = "[[" .. strona .. "|" .. przeciwnik .. "]]" | meczTekst = "[[" .. strona .. "|" .. przeciwnik .. "]]" | ||
end | end | ||
-- | -- ====================================== | ||
-- JUBILEUSZ | |||
-- ====================================== | |||
local jubileusz = "" | local jubileusz = "" | ||
| Linia 166: | Linia 231: | ||
end | end | ||
-- ====================================== | |||
-- WIERSZ | |||
-- ====================================== | |||
table.insert(wynik, | table.insert(wynik, "|-") | ||
table.insert(wynik, "| " .. i) | |||
) | table.insert(wynik, "| " .. data) | ||
table.insert(wynik, "| " .. meczTekst) | |||
table.insert(wynik, "| " .. wynikMeczu) | |||
table.insert(wynik, "| " .. minutyFormat) | |||
table.insert(wynik, "| " .. pkt) | |||
table.insert(wynik, "| " .. eval) | |||
table.insert(wynik, "| " .. plusminus) | |||
table.insert(wynik, "| " .. jubileusz) | |||
end | end | ||
Wersja z 04:38, 17 sie 2026
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:HistoriaWystepow/opis
local p = {}
function p.main(frame)
local zawodnik = frame.args.zawodnik
if not zawodnik or zawodnik == "" then
zawodnik = mw.title.getCurrentTitle().text
end
-- Bezpieczne przygotowanie nazwy zawodnika do SQL
local zawodnikSQL = mw.ustring.gsub(zawodnik, "'", "''")
-- ==========================================
-- POBRANIE WYSTĘPÓW
-- ==========================================
local fields = table.concat({
"UdzialZawodnika.mecz=mecz",
"UdzialZawodnika.druzyna=druzyna",
"UdzialZawodnika.minuty=minuty",
"UdzialZawodnika.minuty_format=minuty_format",
"UdzialZawodnika.gol=gol",
"UdzialZawodnika.eval=eval",
"UdzialZawodnika.plusminus=plusminus",
"Mecze.data=data",
"Mecze.druzyna1=druzyna1",
"Mecze.druzyna2=druzyna2",
"Mecze.wynik=wynik",
"Mecze.strona_meczu=strona_meczu"
}, ",")
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
)
if not rows or #rows == 0 then
return "''Brak wprowadzonych występów w bazie.''"
end
-- ==========================================
-- PODSUMOWANIE
-- ==========================================
local wystepy = #rows
local zwyciestwa = 0
local porazki = 0
local remisy = 0
local punkty = 0
local sumaMinut = 0
local sumaEval = 0
local sumaPlusMinus = 0
for _, row in ipairs(rows) do
punkty = punkty + tonumber(row.gol or 0)
sumaMinut = sumaMinut + tonumber(row.minuty or 0)
sumaEval = sumaEval + tonumber(row.eval or 0)
sumaPlusMinus = sumaPlusMinus + tonumber(row.plusminus or 0)
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 g1 and g2 then
g1 = tonumber(g1)
g2 = tonumber(g2)
if druzyna == d1 then
if g1 > g2 then
zwyciestwa = zwyciestwa + 1
elseif g1 < g2 then
porazki = porazki + 1
else
remisy = remisy + 1
end
elseif druzyna == d2 then
if g2 > g1 then
zwyciestwa = zwyciestwa + 1
elseif g2 < g1 then
porazki = porazki + 1
else
remisy = remisy + 1
end
end
end
end
-- ==========================================
-- FORMAT MINUT
-- ==========================================
local godziny = math.floor(sumaMinut / 60)
local minuty = sumaMinut % 60
local sumaMinutFormat = string.format(
"%d:%02d",
godziny,
minuty
)
-- ==========================================
-- WYNIK
-- ==========================================
local wynik = {}
table.insert(wynik, "== Historia występów ==")
table.insert(wynik, "")
-- ==========================================
-- TABELA PODSUMOWANIA
-- ==========================================
table.insert(
wynik,
'{| class="wikitable" style="width:100%; text-align:center;"'
)
table.insert(wynik, '! colspan="2" | Występy')
table.insert(wynik, "! Zwycięstwa")
table.insert(wynik, "! Porażki")
table.insert(wynik, "! Remisy")
table.insert(wynik, "! Punkty")
table.insert(wynik, "! Minuty")
table.insert(wynik, "! EVAL")
table.insert(wynik, "! +/-")
table.insert(wynik, "|-")
table.insert(wynik, "| colspan=2 | '''" .. wystepy .. "'''")
table.insert(wynik, "| '''" .. zwyciestwa .. "'''")
table.insert(wynik, "| '''" .. porazki .. "'''")
table.insert(wynik, "| '''" .. remisy .. "'''")
table.insert(wynik, "| '''" .. punkty .. "'''")
table.insert(wynik, "| " .. sumaMinutFormat)
table.insert(wynik, "| " .. sumaEval)
table.insert(wynik, "| " .. sumaPlusMinus)
table.insert(wynik, "|}")
table.insert(wynik, "")
-- ==========================================
-- TABELA WYSTĘPÓW
-- ==========================================
table.insert(
wynik,
'{| class="wikitable sortable" style="width:100%;"'
)
table.insert(wynik, "! Nr")
table.insert(wynik, "! Data")
table.insert(wynik, "! Przeciwnik")
table.insert(wynik, "! Wynik")
table.insert(wynik, "! Min.")
table.insert(wynik, "! Pkt")
table.insert(wynik, "! EVAL")
table.insert(wynik, "! +/-")
table.insert(wynik, "! Jubileusz")
-- ==========================================
-- POSZCZEGÓLNE MECZE
-- ==========================================
for i, row in ipairs(rows) do
local data = row.data 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 ""
local pkt = row.gol or "0"
local eval = row.eval or "0"
local plusminus = row.plusminus or "0"
-- ======================================
-- PRZECIWNIK
-- ======================================
local przeciwnik = ""
if druzyna == d1 then
przeciwnik = d2
elseif druzyna == d2 then
przeciwnik = d1
else
przeciwnik = d1
end
-- ======================================
-- LINK DO STRONY 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, "| " .. data)
table.insert(wynik, "| " .. meczTekst)
table.insert(wynik, "| " .. wynikMeczu)
table.insert(wynik, "| " .. minutyFormat)
table.insert(wynik, "| " .. pkt)
table.insert(wynik, "| " .. eval)
table.insert(wynik, "| " .. plusminus)
table.insert(wynik, "| " .. jubileusz)
end
table.insert(wynik, "|}")
return table.concat(wynik, "\n")
end
return p