Przejdź do zawartości

Moduł:HistoriaSpotkanDruzyny: Różnice pomiędzy wersjami

Z Encyklopedia Poznanskiego Sportu
Nie podano opisu zmian
Nie podano opisu zmian
 
Linia 31: Linia 31:


     return tonumber(text) or 0
     return tonumber(text) or 0
end
local function qsum(v)
    local text = trim(v)
    local a, b = mw.ustring.match(
        text,
        "^(%d+)%s*:%s*(%d+)$"
    )
    if not a then
        return 0
    end
    return tonumber(a) + tonumber(b)
end
end


Linia 67: Linia 50:
-- =========================================================
-- =========================================================
-- PRZECIWNIK
-- PRZECIWNIK
-- =========================================================
-- Jeżeli nasza drużyna jest drużyną 1,
-- przeciwnik znajduje się w nazwa_statystyki2.
--
--
-- Nazwa przeciwnika jest pobierana z:
-- Jeżeli nasza drużyna jest drużyną 2,
-- nazwa_statystyki1 / nazwa_statystyki2
-- przeciwnik znajduje się w nazwa_statystyki1.
--
-- drużyna1 / drużyna2 służą tylko do ustalenia
-- czy nasza drużyna grała u siebie czy na wyjeździe.
-- =========================================================
-- =========================================================


Linia 94: Linia 77:




local function overtime(
-- =========================================================
     row,
-- PAUZA
     g1,
-- =========================================================
     g2
-- 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 q1 = trim(row.kwarta1)
     local count = 0
    local q2 = trim(row.kwarta2)
    local q3 = trim(row.kwarta3)
    local q4 = trim(row.kwarta4)


    if q1 == ""
        or q2 == ""
        or q3 == ""
        or q4 == "" then


         return 0
    if trim(row.dogrywka1) ~= "" then
         count = count + 1
     end
     end


    local regular_total =
        qsum(q1)
        + qsum(q2)
        + qsum(q3)
        + qsum(q4)


     local final_total =
     if trim(row.dogrywka2) ~= "" then
         g1 + g2
         count = count + 1
    end
 


     if regular_total < final_total then
     if trim(row.dogrywka3) ~= "" then
         return 1
         count = count + 1
     end
     end


     return 0
 
     return count
end
end


Linia 138: 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 147: Linia 184:
             value
             value
         )
         )


     text =
     text =
Linia 154: Linia 192:
             ","
             ","
         )
         )


     return text .. "%"
     return text .. "%"
Linia 166: 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 190: Linia 232:
         return "—"
         return "—"
     end
     end


     local place
     local place


     if record.location == "dom" then
     if record.location == "dom" then
Linia 198: Linia 242:
         place = "wyjazd"
         place = "wyjazd"
     end
     end


     return (
     return (
Linia 224: 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 242: Linia 290:
     local team =
     local team =
         trim(frame.args.druzyna)
         trim(frame.args.druzyna)


     if team == "" then
     if team == "" then
Linia 247: 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 256: 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",


            -- KLUCZOWE POLA DLA PRZECIWNIKA
             "Mecze.nazwa_statystyki1=nazwa_statystyki1",
             "Mecze.nazwa_statystyki1=nazwa_statystyki1",
             "Mecze.nazwa_statystyki2=nazwa_statystyki2",
             "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 289: Linia 367:
         esc(team)
         esc(team)


    -- =====================================================
    -- POBRANIE MECZÓW
    -- =====================================================


     local rows =
     local rows =
Linia 295: Linia 377:
             fields,
             fields,
             {
             {
                 where =
                 where =
                     "(Mecze.druzyna1='"
                     "(Mecze.druzyna1='"
Linia 306: Linia 389:


                 limit = 10000
                 limit = 10000
             }
             }
         )
         )
Linia 318: Linia 402:
             .. ".''"
             .. ".''"
         )
         )
     end
     end


Linia 327: 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


         -- =================================================
         -- =================================================
         -- POMIJANIE PAUZY
         -- POMIJAMY PAUZĘ
        --
        -- Pauza nie jest meczem i nie może wpływać
        -- na żadne statystyki.
         -- =================================================
         -- =================================================


         local wynikText =
         if not isPause(row) then
            mw.ustring.lower(
                trim(row.wynik)
            )
 
        local isPauza =
            mw.ustring.find(
                wynikText,
                "pauza",
                1,
                true
            ) ~= nil
 


        if not isPauza then


             local g1 =
             local g1 =
                 num(row.gole1)
                 num(row.gole1)


             local g2 =
             local g2 =
Linia 377: Linia 459:




            -- Przeciwnik z nazwa_statystyki1/2
             local opp =
             local opp =
                 opponent(
                 opponent(
Linia 386: Linia 467:


             if loc and opp ~= "" then
             if loc and opp ~= "" then
                -- =========================================
                -- GRUPA PRZECIWNIKA
                -- =========================================


                 local item =
                 local item =
Linia 408: Linia 494:


                         againstScore = 0
                         againstScore = 0
                     }
                     }


Linia 413: Linia 500:
                     groups[opp] =
                     groups[opp] =
                         item
                         item
                 end
                 end


                -- =========================================
                -- NASZE PUNKTY / PUNKTY PRZECIWNIKA
                -- =========================================


                 local gf
                 local gf
Linia 423: Linia 515:


                     gf = g1
                     gf = g1
                     ga = g2
                     ga = g2


Linia 428: Linia 521:


                     gf = g2
                     gf = g2
                     ga = g1
                     ga = g1


                 end
                 end


                -- =========================================
                -- MECZ
                -- =========================================


                 item.mecze =
                 item.mecze =
                     item.mecze + 1
                     item.mecze + 1


                -- =========================================
                -- KOSZE
                -- =========================================


                 item.forScore =
                 item.forScore =
Linia 444: Linia 546:
                     item.againstScore + ga
                     item.againstScore + ga


                -- =========================================
                -- DOGRYWKI
                -- =========================================


                 item.dogrywki =
                 item.dogrywki =
                     item.dogrywki
                     item.dogrywki
                     + overtime(
                     + overtime(row)
                        row,
 
                        g1,
                        g2
                    )


                -- =========================================