Moduł:WGsumator

Wikimedia Polska, polski partner Fundacji Wikimedia.
Przejdź do nawigacji Przejdź do wyszukiwania

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:WGsumator/opis

function pl_num(n)
	return string.gsub( string.format('%7.2f', n), '[\.]', ',', 1 ) .. ''
end

function limit( rok )
	local limity
	limity = {
		aktualny = 20000,
		["2023"] = 20000,
		["2022"] = 20000,
		["2021"] = 20000,
		["2020"] = 12000,
		["2019"] = 12000,
		["2018"] = 15000,
		["2017"] = 20000,
		["2016"] = 20000,
		["2015"] = 25000,
		["2014"] = 30000,
		["2013"] = 5000,
	}
	if tonumber( rok ) == nil then
		rok = 'aktualny'
	end
	return limity[rok]
end

function str_projekty( rok )
	local strona = 'Wikigranty/projekty'
    if tonumber( rok ) ~= nil then
		strona = 'Wikigranty/' .. rok .. '/projekty'
	end
	return mw.title.makeTitle( '', strona )
end

function okr_rok( frame )
	local args = frame.args
	local rok = 'aktualny'
    if tonumber( args[1] ) ~= nil then
		rok = args[1]
	end
	return rok
end

function przyznane_skor( frame )
	local rok = okr_rok( frame )
	local wynik = 0
	local strona = str_projekty( rok )
	local kod = strona:getContent()
	if not kod then
		return 0
	end
	for wiersz in string.gmatch( kod, '\n\| *%[%[WG 20..[-][0-9]*%]%] *\|\|' ) do
--		mw.log( wiersz )
		local grant = string.match( wiersz, 'WG 20[0-9][0-9][-][0-9]+' )
--		mw.log( grant )
		local stronag = mw.title.makeTitle( '', grant )
		local kodg = stronag:getContent()
		if kodg ~= nil then
			local status = string.match( kodg, ' *\| *status *\= *([ a-z]*)' )
--			mw.log( status )
			if status == 'realizowany' or status == 'wykonany' or status == 'niezrealizowany' then
				local wart = string.match( kodg, ' *\| *suma *\= *[0-9]+,?[0-9]* *PLN' )
				if wart ~= nil then
					wart = tonumber( string.gsub( string.match( wart, '[0-9]+,[0-9]+' ), ',', '.' ) .. '' )
				else
					wart = 0
				end
				local rozl = string.match( kodg, ' *\| *rozliczono *\= *[0-9]+,?[0-9]*' )
				if rozl ~= nil then
					rozl = tonumber( string.gsub( string.match( rozl, '[0-9]+,[0-9]+' ), ',', '.' ) .. '' )
				else
					rozl = 0
				end
--				mw.log( wart )
--				mw.log( rozl )
				if rozl > 0 then
					wynik = wynik + rozl
				else
					wynik = wynik + wart
				end
			end
		end
	end
    return wynik
end

function rozliczone_z_zest( frame )
	local rok = okr_rok( frame )
	local wynik = 0
	local strona = str_projekty( rok )
	local kod = strona:getContent()
	if not kod then
		return 0
	end
	for wiersz in string.gmatch( kod, '\n\| *style\="text[-]align:right;" *\| *[0-9]+,[0-9]+ *\n\|[-]' ) do
		liczba = string.gsub( string.match( wiersz, '[0-9]+,[0-9]+' ), ',', '.' ) .. ''
--		mw.log( liczba )
        wynik = wynik + tonumber( liczba )
	end
    return wynik 
end

local p = {}
function p.rozliczone( frame )
	local wynik = rozliczone_z_zest( frame )
    return pl_num( wynik )
end

function p.nieprzyznane( frame )
	local rok = okr_rok( frame )
	return pl_num( limit( rok ) - przyznane_skor( frame ) )
end

function p.przyznane( frame )
	local wynik = przyznane_skor( frame )
    return pl_num( wynik )
end

function p.pozostale( frame )
	local rok = okr_rok( frame )
    return pl_num( limit( rok ) - rozliczone_z_zest( frame ) )
end

function p.oczekuje( frame )
	local rok = okr_rok( frame )
	local wynik = 0
	local strona = str_projekty( rok )
	local kod = strona:getContent()
	if not kod then
		return 0
	end
	for wiersz in string.gmatch( kod, '\n\| *style\="text[-]align:right;" *\| *[^ 0-9][0-9]+,[0-9]+[^ 0-9] *\n\|[-]' ) do
		liczba = string.gsub( string.match( wiersz, '[0-9]+,[0-9]+' ), ',', '.' ) .. ''
        wynik = wynik + tonumber( liczba )
	end
    return pl_num( wynik )
end
return p