Moduł:StatystykiHistoryczne: Różnice pomiędzy wersjami
Wygląd
Nie podano opisu zmian |
Nie podano opisu zmian |
||
| Linia 2: | Linia 2: | ||
-- ========================================================= | -- ========================================================= | ||
-- MODUŁ:STATYSTYKIHISTORYCZNE | -- MODUŁ: STATYSTYKIHISTORYCZNE | ||
-- | -- | ||
-- Łączne statystyki zawodników ze wszystkich | -- Łączne statystyki zawodników ze wszystkich | ||
| Linia 132: | Linia 132: | ||
limit = 5000 | limit = 5000 | ||
} | } | ||
) | ) | ||
| Linia 199: | Linia 198: | ||
limit = 5000 | limit = 5000 | ||
} | } | ||
) | ) | ||
| Linia 281: | Linia 279: | ||
-- ===================================================== | -- ===================================================== | ||
-- FORMATOWANIE MINUT | -- FORMATOWANIE MINUT | ||
-- | |||
-- Wartość Cargo jest traktowana jako liczba sekund. | |||
-- Wynik: HH:MM:SS | |||
-- ===================================================== | -- ===================================================== | ||
local function formatujMinuty( | local function formatujMinuty(sekundy) | ||
sekundy = | |||
math.floor( | math.floor( | ||
tonumber( | tonumber(sekundy or 0) | ||
or 0 | or 0 | ||
) | ) | ||
local godziny = | local godziny = | ||
math.floor( | math.floor( | ||
sekundy / 3600 | |||
) | ) | ||
local | local minuty = | ||
math.floor( | |||
(sekundy % 3600) / 60 | |||
) | |||
local sekundyPozostale = | |||
sekundy % 60 | |||
return string.format( | return string.format( | ||
"%d:%02d", | "%d:%02d:%02d", | ||
godziny, | godziny, | ||
minuty, | |||
sekundyPozostale | |||
) | ) | ||
| Linia 318: | Linia 327: | ||
local nazwa = | local nazwa = | ||
row.zawodnik | row.zawodnik | ||
-- Bezpieczne przygotowanie nazwy strony. | |||
local strona = | |||
mw.uri.encode( | |||
nazwa, | |||
"WIKI" | |||
) | |||
| Linia 521: | Linia 538: | ||
local lista = {} | local lista = {} | ||
-- ----------------------------------------------- | |||
-- KOPIA LISTY ZAWODNIKÓW | |||
-- ----------------------------------------------- | |||
for _, zawodnik in ipairs(zawodnicy) do | for _, zawodnik in ipairs(zawodnicy) do | ||
| Linia 531: | Linia 552: | ||
end | end | ||
-- ----------------------------------------------- | |||
-- SORTOWANIE | |||
-- ----------------------------------------------- | |||
table.sort( | table.sort( | ||
| Linia 544: | Linia 569: | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
-- | -- OTWARCIE TABELI | ||
-- | |||
-- Bardzo ważne: | |||
-- {| musi rozpoczynać nową linię. | |||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
| Linia 554: | Linia 582: | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
-- | -- TYTUŁ | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
| Linia 562: | Linia 590: | ||
.. definicja.nazwa | .. definicja.nazwa | ||
.. "'''" | .. "'''" | ||
) | ) | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
-- | -- NAGŁÓWKI | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
table.insert( | table.insert( | ||
wynik, | wynik, | ||
"! " | "! Miejsce !! Zawodnik !! " | ||
.. definicja.nazwa | .. mw.ustring.upper( | ||
definicja.nazwa | |||
) | |||
) | ) | ||
| Linia 603: | Linia 618: | ||
-- | -- Miejsce | ||
table.insert( | table.insert( | ||
| Linia 614: | Linia 627: | ||
-- | -- Zawodnik | ||
table.insert( | table.insert( | ||
| Linia 627: | Linia 638: | ||
-- | -- Wartość | ||
table.insert( | table.insert( | ||
| Linia 646: | Linia 655: | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
-- | -- ZAMKNIĘCIE TABELI | ||
-- ----------------------------------------------- | -- ----------------------------------------------- | ||
| Linia 704: | Linia 713: | ||
wynik, | wynik, | ||
"" | "" | ||
) | ) | ||
| Linia 712: | Linia 720: | ||
-- ===================================================== | -- ===================================================== | ||
-- UKŁAD 3 KOLUMNY | -- UKŁAD 3 KOLUMNY | ||
-- | |||
-- 1. MECZE | |||
-- 2. PUNKTY | |||
-- 3. MINUTY | |||
-- | |||
-- 4. ASYSTY | |||
-- 5. ZBIÓRKI | |||
-- 6. BLOKI | |||
-- ===================================================== | -- ===================================================== | ||
| Linia 727: | Linia 743: | ||
wynik, | wynik, | ||
'<div style="min-width:0;">' | '<div style="min-width:0;">' | ||
) | |||
table.insert( | |||
wynik, | |||
zbudujTabele( | |||
tabele[1] | tabele[1] | ||
) | ) | ||
) | |||
table.insert( | |||
wynik, | |||
"</div>" | |||
) | ) | ||
| Linia 741: | Linia 765: | ||
wynik, | wynik, | ||
'<div style="min-width:0;">' | '<div style="min-width:0;">' | ||
) | |||
table.insert( | |||
wynik, | |||
zbudujTabele( | |||
tabele[2] | tabele[2] | ||
) | ) | ||
) | |||
table.insert( | |||
wynik, | |||
"</div>" | |||
) | ) | ||
| Linia 755: | Linia 787: | ||
wynik, | wynik, | ||
'<div style="min-width:0;">' | '<div style="min-width:0;">' | ||
) | |||
table.insert( | |||
wynik, | |||
zbudujTabele( | |||
tabele[3] | tabele[3] | ||
) | ) | ||
) | |||
table.insert( | |||
wynik, | |||
"</div>" | |||
) | ) | ||
| Linia 769: | Linia 809: | ||
wynik, | wynik, | ||
'<div style="min-width:0;">' | '<div style="min-width:0;">' | ||
) | |||
table.insert( | |||
wynik, | |||
zbudujTabele( | |||
tabele[4] | tabele[4] | ||
) | ) | ||
) | |||
table.insert( | |||
wynik, | |||
"</div>" | |||
) | ) | ||
| Linia 783: | Linia 831: | ||
wynik, | wynik, | ||
'<div style="min-width:0;">' | '<div style="min-width:0;">' | ||
) | |||
table.insert( | |||
wynik, | |||
zbudujTabele( | |||
tabele[5] | tabele[5] | ||
) | ) | ||
) | |||
table.insert( | |||
wynik, | |||
"</div>" | |||
) | ) | ||
| Linia 797: | Linia 853: | ||
wynik, | wynik, | ||
'<div style="min-width:0;">' | '<div style="min-width:0;">' | ||
) | |||
table.insert( | |||
wynik, | |||
zbudujTabele( | |||
tabele[6] | tabele[6] | ||
) | ) | ||
) | |||
table.insert( | |||
wynik, | |||
"</div>" | |||
) | ) | ||
Wersja z 09:50, 30 sie 2026
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:StatystykiHistoryczne/opis
local p = {}
-- =========================================================
-- MODUŁ: STATYSTYKIHISTORYCZNE
--
-- Łączne statystyki zawodników ze wszystkich
-- wprowadzonych sezonów.
--
-- KOSZYKÓWKA
--
-- Tabele:
-- 1. Mecze
-- 2. Punkty
-- 3. Minuty
-- 4. Asysty
-- 5. Zbiórki
-- 6. Bloki
--
-- Użycie:
--
-- {{#invoke:StatystykiHistoryczne|main
-- |druzyna=Enea Basket Poznań
-- |sezon_biezacy=2025/2026
-- }}
--
-- Zawodnicy występujący w sezonie_biezacy są
-- wyróżniani pogrubieniem.
-- =========================================================
function p.main(frame)
-- =====================================================
-- PARAMETRY
-- =====================================================
local druzyna =
mw.text.trim(
frame.args.druzyna or ""
)
local sezonBiezacy =
mw.text.trim(
frame.args.sezon_biezacy or ""
)
-- =====================================================
-- SPRAWDZENIE DRUŻYNY
-- =====================================================
if druzyna == "" then
return
"'''Błąd:''' nie podano parametru <code>druzyna</code>."
end
-- =====================================================
-- BEZPIECZNE PRZYGOTOWANIE NAZW
-- =====================================================
local druzynaSQL =
mw.ustring.gsub(
druzyna,
"'",
"''"
)
local sezonSQL = ""
if sezonBiezacy ~= "" then
sezonSQL =
mw.ustring.gsub(
sezonBiezacy,
"'",
"''"
)
end
-- =====================================================
-- POBRANIE DANYCH Z CARGO
-- =====================================================
local fields = table.concat({
"UdzialZawodnika.zawodnik=zawodnik",
"COUNT(UdzialZawodnika.mecz)=mecze",
"SUM(UdzialZawodnika.gol)=punkty",
"SUM(UdzialZawodnika.minuty)=minuty",
"SUM(UdzialZawodnika.asysta)=asysty",
"SUM(UdzialZawodnika.zbiorka)=zbiorki",
"SUM(UdzialZawodnika.blok)=bloki"
}, ",")
-- =====================================================
-- WARUNEK
-- =====================================================
local where =
"UdzialZawodnika.druzyna='"
.. druzynaSQL
.. "'"
-- =====================================================
-- ZAPYTANIE
-- =====================================================
local rows =
mw.ext.cargo.query(
"UdzialZawodnika",
fields,
{
where = where,
groupBy =
"UdzialZawodnika.zawodnik",
limit = 5000
}
)
-- =====================================================
-- BRAK DANYCH
-- =====================================================
if not rows or #rows == 0 then
return
"''Brak danych statystycznych dla drużyny "
.. druzyna
.. ".''"
end
-- =====================================================
-- FUNKCJA LICZBOWA
-- =====================================================
local function liczba(value)
return
tonumber(value or 0)
or 0
end
-- =====================================================
-- SPRAWDZENIE AKTUALNYCH ZAWODNIKÓW
--
-- Zawodnik jest uznawany za obecnego, jeżeli ma
-- przynajmniej jeden występ w podanym sezonie.
-- =====================================================
local aktualni = {}
if sezonSQL ~= "" then
local currentRows =
mw.ext.cargo.query(
"UdzialZawodnika,Mecze",
"UdzialZawodnika.zawodnik=zawodnik",
{
join =
"UdzialZawodnika.mecz=Mecze.id",
where =
"UdzialZawodnika.druzyna='"
.. druzynaSQL
.. "'"
.. " AND Mecze.sezon='"
.. sezonSQL
.. "'"
.. " AND UdzialZawodnika.minuty > 0",
groupBy =
"UdzialZawodnika.zawodnik",
limit = 5000
}
)
if currentRows then
for _, row in ipairs(currentRows) do
local zawodnik =
mw.text.trim(
row.zawodnik or ""
)
if zawodnik ~= "" then
aktualni[zawodnik] = true
end
end
end
end
-- =====================================================
-- PRZYGOTOWANIE DANYCH
-- =====================================================
local zawodnicy = {}
for _, row in ipairs(rows) do
local zawodnik =
mw.text.trim(
row.zawodnik or ""
)
if zawodnik ~= "" then
table.insert(
zawodnicy,
{
zawodnik = zawodnik,
mecze =
liczba(row.mecze),
punkty =
liczba(row.punkty),
minuty =
liczba(row.minuty),
asysty =
liczba(row.asysty),
zbiorki =
liczba(row.zbiorki),
bloki =
liczba(row.bloki),
aktualny =
aktualni[zawodnik] or false
}
)
end
end
-- =====================================================
-- FORMATOWANIE MINUT
--
-- Wartość Cargo jest traktowana jako liczba sekund.
-- Wynik: HH:MM:SS
-- =====================================================
local function formatujMinuty(sekundy)
sekundy =
math.floor(
tonumber(sekundy or 0)
or 0
)
local godziny =
math.floor(
sekundy / 3600
)
local minuty =
math.floor(
(sekundy % 3600) / 60
)
local sekundyPozostale =
sekundy % 60
return string.format(
"%d:%02d:%02d",
godziny,
minuty,
sekundyPozostale
)
end
-- =====================================================
-- LINK DO ZAWODNIKA
-- =====================================================
local function linkZawodnika(row)
local nazwa =
row.zawodnik
-- Bezpieczne przygotowanie nazwy strony.
local strona =
mw.uri.encode(
nazwa,
"WIKI"
)
local tekst =
"[["
.. nazwa
.. "|"
.. nazwa
.. "]]"
-- -----------------------------------------------
-- WYRÓŻNIENIE AKTUALNEGO ZAWODNIKA
-- -----------------------------------------------
if row.aktualny then
tekst =
"'''"
.. tekst
.. "'''"
end
return tekst
end
-- =====================================================
-- SORTOWANIE
-- =====================================================
local funkcjeSortowania = {
mecze = function(a, b)
if a.mecze ~= b.mecze then
return a.mecze > b.mecze
end
return a.zawodnik < b.zawodnik
end,
punkty = function(a, b)
if a.punkty ~= b.punkty then
return a.punkty > b.punkty
end
return a.zawodnik < b.zawodnik
end,
minuty = function(a, b)
if a.minuty ~= b.minuty then
return a.minuty > b.minuty
end
return a.zawodnik < b.zawodnik
end,
asysty = function(a, b)
if a.asysty ~= b.asysty then
return a.asysty > b.asysty
end
return a.zawodnik < b.zawodnik
end,
zbiorki = function(a, b)
if a.zbiorki ~= b.zbiorki then
return a.zbiorki > b.zbiorki
end
return a.zawodnik < b.zawodnik
end,
bloki = function(a, b)
if a.bloki ~= b.bloki then
return a.bloki > b.bloki
end
return a.zawodnik < b.zawodnik
end
}
-- =====================================================
-- DEFINICJA TABEL
-- =====================================================
local tabele = {
{
nazwa = "MECZE",
pole = "mecze",
format = function(v)
return tostring(v)
end
},
{
nazwa = "PUNKTY",
pole = "punkty",
format = function(v)
return tostring(v)
end
},
{
nazwa = "MINUTY",
pole = "minuty",
format = function(v)
return formatujMinuty(v)
end
},
{
nazwa = "ASYSTY",
pole = "asysty",
format = function(v)
return tostring(v)
end
},
{
nazwa = "ZBIÓRKI",
pole = "zbiorki",
format = function(v)
return tostring(v)
end
},
{
nazwa = "BLOKI",
pole = "bloki",
format = function(v)
return tostring(v)
end
}
}
-- =====================================================
-- BUDOWANIE POJEDYNCZEJ TABELI
-- =====================================================
local function zbudujTabele(definicja)
local lista = {}
-- -----------------------------------------------
-- KOPIA LISTY ZAWODNIKÓW
-- -----------------------------------------------
for _, zawodnik in ipairs(zawodnicy) do
table.insert(
lista,
zawodnik
)
end
-- -----------------------------------------------
-- SORTOWANIE
-- -----------------------------------------------
table.sort(
lista,
funkcjeSortowania[
definicja.pole
]
)
local wynik = {}
-- -----------------------------------------------
-- OTWARCIE TABELI
--
-- Bardzo ważne:
-- {| musi rozpoczynać nową linię.
-- -----------------------------------------------
table.insert(
wynik,
'{| class="wikitable" style="width:100%; text-align:center;"'
)
-- -----------------------------------------------
-- TYTUŁ
-- -----------------------------------------------
table.insert(
wynik,
"|+ '''"
.. definicja.nazwa
.. "'''"
)
-- -----------------------------------------------
-- NAGŁÓWKI
-- -----------------------------------------------
table.insert(
wynik,
"! Miejsce !! Zawodnik !! "
.. mw.ustring.upper(
definicja.nazwa
)
)
-- -----------------------------------------------
-- WIERSZE
-- -----------------------------------------------
for i, zawodnik in ipairs(lista) do
table.insert(
wynik,
"|-"
)
-- Miejsce
table.insert(
wynik,
"| "
.. i
)
-- Zawodnik
table.insert(
wynik,
"| "
.. linkZawodnika(
zawodnik
)
)
-- Wartość
table.insert(
wynik,
"| '''"
.. definicja.format(
zawodnik[
definicja.pole
]
)
.. "'''"
)
end
-- -----------------------------------------------
-- ZAMKNIĘCIE TABELI
-- -----------------------------------------------
table.insert(
wynik,
"|}"
)
return table.concat(
wynik,
"\n"
)
end
-- =====================================================
-- WYNIK
-- =====================================================
local wynik = {}
table.insert(
wynik,
"== Statystyki historyczne – "
.. druzyna
.. " =="
)
table.insert(
wynik,
""
)
-- =====================================================
-- INFORMACJA O WYRÓŻNIENIU
-- =====================================================
if sezonBiezacy ~= "" then
table.insert(
wynik,
"'''''"
.. "Pogrubieniem wyróżniono zawodników "
.. "występujących w sezonie "
.. sezonBiezacy
.. "."
.. "'''''"
)
table.insert(
wynik,
""
)
end
-- =====================================================
-- UKŁAD 3 KOLUMNY
--
-- 1. MECZE
-- 2. PUNKTY
-- 3. MINUTY
--
-- 4. ASYSTY
-- 5. ZBIÓRKI
-- 6. BLOKI
-- =====================================================
table.insert(
wynik,
'<div style="display:grid; grid-template-columns:repeat(3, minmax(0, 1fr)); gap:12px; align-items:start;">'
)
-- =====================================================
-- TABELA 1 – MECZE
-- =====================================================
table.insert(
wynik,
'<div style="min-width:0;">'
)
table.insert(
wynik,
zbudujTabele(
tabele[1]
)
)
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- TABELA 2 – PUNKTY
-- =====================================================
table.insert(
wynik,
'<div style="min-width:0;">'
)
table.insert(
wynik,
zbudujTabele(
tabele[2]
)
)
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- TABELA 3 – MINUTY
-- =====================================================
table.insert(
wynik,
'<div style="min-width:0;">'
)
table.insert(
wynik,
zbudujTabele(
tabele[3]
)
)
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- TABELA 4 – ASYSTY
-- =====================================================
table.insert(
wynik,
'<div style="min-width:0;">'
)
table.insert(
wynik,
zbudujTabele(
tabele[4]
)
)
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- TABELA 5 – ZBIÓRKI
-- =====================================================
table.insert(
wynik,
'<div style="min-width:0;">'
)
table.insert(
wynik,
zbudujTabele(
tabele[5]
)
)
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- TABELA 6 – BLOKI
-- =====================================================
table.insert(
wynik,
'<div style="min-width:0;">'
)
table.insert(
wynik,
zbudujTabele(
tabele[6]
)
)
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- KONIEC UKŁADU
-- =====================================================
table.insert(
wynik,
"</div>"
)
-- =====================================================
-- ZWRÓCENIE WYNIKU
-- =====================================================
return table.concat(
wynik,
"\n"
)
end
return p