Moduł:HistoriaSpotkanDruzyny: Różnice pomiędzy wersjami
Wygląd
Utworzono nową stronę "local p = {} local function trim(v) if v == nil then return "" end return mw.text.trim(tostring(v)) end local function esc(v) return mw.ustring.gsub( trim(v), "'", "''" ) end local function num(v) if v == nil or trim(v) == "" then return 0 end local text = mw.ustring.gsub( trim(v), ",", "." ) return tonumber(text) or 0 end local function qsum(v) lo…" |
Nie podano opisu zmian |
||
| (Nie pokazano 1 pośredniej wersji utworzonej przez tego samego użytkownika) | |||
| Linia 31: | Linia 31: | ||
return tonumber(text) or 0 | return tonumber(text) or 0 | ||
end | end | ||
| Linia 64: | Linia 47: | ||
end | end | ||
-- ========================================================= | |||
-- PRZECIWNIK | |||
-- ========================================================= | |||
-- Jeżeli nasza drużyna jest drużyną 1, | |||
-- przeciwnik znajduje się w nazwa_statystyki2. | |||
-- | |||
-- Jeżeli nasza drużyna jest drużyną 2, | |||
-- przeciwnik znajduje się w nazwa_statystyki1. | |||
-- ========================================================= | |||
local function opponent(row, team) | local function opponent(row, team) | ||
| Linia 73: | Linia 66: | ||
if loc == "dom" then | if loc == "dom" then | ||
return trim(row. | return trim(row.nazwa_statystyki2) | ||
end | end | ||
if loc == "wyjazd" then | if loc == "wyjazd" then | ||
return trim(row. | return trim(row.nazwa_statystyki1) | ||
end | end | ||
| Linia 84: | Linia 77: | ||
local function | -- ========================================================= | ||
row, | -- PAUZA | ||
-- ========================================================= | |||
-- Pauza nie jest meczem i nie może być liczona | |||
) | -- do żadnych statystyk. | ||
-- ========================================================= | |||
local function isPause(row) | |||
local values = { | |||
row.wynik, | |||
row.druzyna1, | |||
row.druzyna2, | |||
row.nazwa_statystyki1, | |||
row.nazwa_statystyki2 | |||
} | |||
for _, value in ipairs(values) do | |||
local text = | |||
mw.ustring.lower( | |||
trim(value) | |||
) | |||
if text == "pauza" then | |||
return true | |||
end | |||
if mw.ustring.find( | |||
text, | |||
"pauza", | |||
1, | |||
true | |||
) ~= nil then | |||
return true | |||
end | |||
end | |||
return false | |||
end | |||
-- ========================================================= | |||
-- DOGRYWKI | |||
-- ========================================================= | |||
-- Liczymy bezpośrednio pola dogrywka1/2/3. | |||
-- | |||
-- Dzięki temu: | |||
-- | |||
-- dogrywka1 = 1 | |||
-- dogrywka2 = 1 | |||
-- dogrywka3 = 1 | |||
-- | |||
-- daje 3 dogrywki. | |||
-- | |||
-- Nie próbujemy już zgadywać liczby dogrywek | |||
-- na podstawie kwart i wyniku końcowego. | |||
-- ========================================================= | |||
local function overtime(row) | |||
local | local count = 0 | ||
if trim(row.dogrywka1) ~= "" then | |||
count = count + 1 | |||
end | end | ||
if trim(row.dogrywka2) ~= "" then | |||
count = count + 1 | |||
end | |||
if | if trim(row.dogrywka3) ~= "" then | ||
count = count + 1 | |||
end | end | ||
return | |||
return count | |||
end | end | ||
| Linia 128: | Linia 173: | ||
return "0,0%" | return "0,0%" | ||
end | end | ||
local value = | local value = | ||
wins / games * 100 | wins / games * 100 | ||
local text = | local text = | ||
| Linia 137: | Linia 184: | ||
value | value | ||
) | ) | ||
text = | text = | ||
| Linia 144: | Linia 192: | ||
"," | "," | ||
) | ) | ||
return text .. "%" | return text .. "%" | ||
| Linia 156: | Linia 205: | ||
local date = | local date = | ||
trim(row.data) | trim(row.data) | ||
if title == "" then | if title == "" then | ||
return date | return date | ||
end | end | ||
if date == "" then | if date == "" then | ||
return "[[" .. title .. "]]" | return "[[" .. title .. "]]" | ||
end | end | ||
return ( | return ( | ||
| Linia 180: | Linia 232: | ||
return "—" | return "—" | ||
end | end | ||
local place | local place | ||
if record.location == "dom" then | if record.location == "dom" then | ||
| Linia 188: | Linia 242: | ||
place = "wyjazd" | place = "wyjazd" | ||
end | end | ||
return ( | return ( | ||
| Linia 214: | Linia 269: | ||
return true | return true | ||
end | end | ||
if newRecord.diff > oldRecord.diff then | if newRecord.diff > oldRecord.diff then | ||
return true | return true | ||
end | end | ||
if newRecord.diff < oldRecord.diff then | if newRecord.diff < oldRecord.diff then | ||
return false | return false | ||
end | end | ||
return trim(newRecord.row.data) | return trim(newRecord.row.data) | ||
| Linia 232: | Linia 290: | ||
local team = | local team = | ||
trim(frame.args.druzyna) | trim(frame.args.druzyna) | ||
if team == "" then | if team == "" then | ||
| Linia 237: | Linia 296: | ||
local title = | local title = | ||
mw.title.getCurrentTitle() | mw.title.getCurrentTitle() | ||
if title ~= nil then | if title ~= nil then | ||
team = | team = | ||
trim(title.prefixedText) | trim( | ||
title.prefixedText | |||
) | |||
end | end | ||
end | end | ||
| Linia 246: | Linia 310: | ||
if team == "" then | if team == "" then | ||
return "''Nie podano drużyny.''" | return "''Nie podano drużyny.''" | ||
end | end | ||
-- ===================================================== | |||
-- POLA CARGO | |||
-- ===================================================== | |||
local fields = table.concat( | local fields = table.concat( | ||
{ | { | ||
"Mecze.id=mecz", | "Mecze.id=mecz", | ||
"Mecze.data=data", | "Mecze.data=data", | ||
"Mecze.sezon=sezon", | "Mecze.sezon=sezon", | ||
"Mecze.druzyna1=druzyna1", | "Mecze.druzyna1=druzyna1", | ||
"Mecze.druzyna2=druzyna2", | "Mecze.druzyna2=druzyna2", | ||
"Mecze.nazwa_statystyki1=nazwa_statystyki1", | |||
"Mecze.nazwa_statystyki2=nazwa_statystyki2", | |||
"Mecze.gole1=gole1", | "Mecze.gole1=gole1", | ||
"Mecze.gole2=gole2", | "Mecze.gole2=gole2", | ||
"Mecze.wynik=wynik", | "Mecze.wynik=wynik", | ||
"Mecze.strona_meczu=strona_meczu", | "Mecze.strona_meczu=strona_meczu", | ||
"Mecze.kwarta1=kwarta1", | "Mecze.kwarta1=kwarta1", | ||
"Mecze.kwarta2=kwarta2", | "Mecze.kwarta2=kwarta2", | ||
"Mecze.kwarta3=kwarta3", | "Mecze.kwarta3=kwarta3", | ||
"Mecze.kwarta4=kwarta4" | |||
"Mecze.kwarta4=kwarta4", | |||
"Mecze.dogrywka1=dogrywka1", | |||
"Mecze.dogrywka2=dogrywka2", | |||
"Mecze.dogrywka3=dogrywka3" | |||
}, | }, | ||
"," | "," | ||
| Linia 273: | Linia 367: | ||
esc(team) | esc(team) | ||
-- ===================================================== | |||
-- POBRANIE MECZÓW | |||
-- ===================================================== | |||
local rows = | local rows = | ||
| Linia 279: | Linia 377: | ||
fields, | fields, | ||
{ | { | ||
where = | where = | ||
"(Mecze.druzyna1='" | "(Mecze.druzyna1='" | ||
| Linia 290: | Linia 389: | ||
limit = 10000 | limit = 10000 | ||
} | } | ||
) | ) | ||
| Linia 302: | Linia 402: | ||
.. ".''" | .. ".''" | ||
) | ) | ||
end | end | ||
| Linia 311: | Linia 412: | ||
win = { | win = { | ||
dom = nil, | dom = nil, | ||
wyjazd = nil | wyjazd = nil | ||
}, | }, | ||
loss = { | loss = { | ||
dom = nil, | dom = nil, | ||
wyjazd = nil | wyjazd = nil | ||
} | } | ||
} | } | ||
-- ===================================================== | |||
-- PRZETWARZANIE MECZÓW | |||
-- ===================================================== | |||
for _, row in ipairs(rows) do | for _, row in ipairs(rows) do | ||
-- ================================================= | |||
-- POMIJAMY PAUZĘ | |||
-- ================================================= | |||
if not isPause(row) then | |||
local g1 = | |||
num(row.gole1) | |||
local g2 = | |||
num(row.gole2) | |||
local loc = | |||
location( | |||
row, | |||
team | |||
) | |||
local opp = | |||
opponent( | |||
row, | |||
team | |||
) | |||
if loc and opp ~= "" then | |||
-- ========================================= | |||
-- GRUPA PRZECIWNIKA | |||
-- ========================================= | |||
local item = | |||
groups[opp] | |||
if not item then | |||
item = { | |||
nazwa = opp, | |||
mecze = 0, | |||
wygrane = 0, | |||
porazki = 0, | |||
dogrywki = 0, | |||
forScore = 0, | |||
againstScore = 0 | |||
} | |||
groups[opp] = | |||
item | |||
end | |||
-- ========================================= | |||
-- NASZE PUNKTY / PUNKTY PRZECIWNIKA | |||
-- ========================================= | |||
local gf | |||
local ga | |||
if loc == "dom" then | |||
gf = g1 | |||