Module:Sandbox/urastats

.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid var(--border-color-base,#a2a9b1);background-color:#ecfcf4;color:inhe

Module:Sandbox/urastats
local p = {}

function p.sums()

	local function add_days_to_date(date_str, days)
    	local y, m, d = date_str:match("(%d+)%-(%d+)%-(%d+)")
    	local ts = os.time{ year = y, month = m, day = d, hour = 12 }
    	local new_ts = ts + days * 24 * 60 * 60
    	return os.date("%Y-%m-%d", new_ts)
	end

    -- Initialise language
    local lang = mw.language.getContentLanguage()
    
    -- Load the data array
    -- https://commons.wikimedia.org/wiki/Data:URAstats_Data.tab
    local t = mw.ext.data.get('URAstats_Data.tab')
    local rows = t.data

    -- get the necessary rows
	local day0 = rows[#rows]    -- today
	local day1 = rows[#rows-1]  -- yesterday
	local dayz = rows[1]        -- when records began

    -- Extract numeric fields (columns 2–6)
    local a0 = tonumber(day0[2]) or 0
    local b0 = tonumber(day0[3]) or 0
    local c0 = tonumber(day0[4]) or 0
    local d0 = tonumber(day0[5]) or 0
    local e0 = tonumber(day0[6]) or 0

    local a1 = tonumber(day1[2]) or 0
    local b1 = tonumber(day1[3]) or 0
    local c1 = tonumber(day1[4]) or 0
    local d1 = tonumber(day1[5]) or 0
    local e1 = tonumber(day1[6]) or 0
    
    local az = tonumber(dayz[2]) or 0
    local bz = tonumber(dayz[3]) or 0
    local cz = tonumber(dayz[4]) or 0
    local dz = tonumber(dayz[5]) or 0
    local ez = tonumber(dayz[6]) or 0
    
    -- Compute sums
    local def0 = a0 + b0 + c0
    local prob0 = d0 + e0

    local def1 = a1 + b1 + c1
    local prob1 = d1 + e1

    local defz = az + bz + cz
    local probz = dz + ez

	-- Compute rate
	local articles_per_day = math.floor((((defz + probz) - (def0 + prob0)) / #rows))
	local days_to_clear_backlog = math.ceil(((def0 + prob0) / articles_per_day))

    -- Retrieve dates and format them nicely
	local date0 = lang:formatDate( "j F Y", day0[1], nil )
	local finish_date = lang:formatDate( "j F Y", add_days_to_date(day0[1], days_to_clear_backlog), nil)

	-- Compose return string
    return string.format(
    	"At the beginning of the day (UTC) on %s there were:\n" ..
        "* %s tagged unreferenced articles, a change of %s since the day before\n" ..
        "* %s probably unreferenced articles, a change of %s since the day before\n" ..
        "* That is, a '''total backlog of %s articles''' still to deal with, a change of %s since the day before\n" ..
        "At the current [[arithmetic mean|average]] rate of '''%s articles per day''', " ..
        "it will take '''%s days to clear the backlog''', " ..
        "finishing on '''%s'''.",
        date0, 
        lang:formatNum(def0), lang:formatNum(def0 - def1), 
        lang:formatNum(prob0), lang:formatNum(prob0 - prob1), 
        lang:formatNum(def0 + prob0), lang:formatNum((def0 + prob0) - (def1 + prob1)),
        lang:formatNum(articles_per_day), lang:formatNum(days_to_clear_backlog), finish_date
    )
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.