This site is no longer actively maintained. It exists for historical purposes as an example of Phabricator integration and Lua scripting.

Difference between revisions of "Module:Reports"

From cpt
No edit summary
No edit summary
 
(67 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


function p.cleanse(frame)
function p.taskCreationClosureReport(frame)
local s = frame.args[1]
local start = {
s = string.gsub( s, '{', '{' )
year = frame.args[1],
s = string.gsub( s, '}', '}' )
month = frame.args[2],
s = string.gsub( s, '%[', '[' )
day = frame.args[3]
s = string.gsub( s, '%]', ']' )
}
s = string.gsub( s, '|', '|' )
local step = frame.args[4]
local timestamp_start = os.time( start )
local now = os.time()
local s = ''
local created = 0
local closed = 0
while timestamp_start < now do
local timestamp_stop = timestamp_start + (step * 86400)
if timestamp_stop > now then
timestamp_stop = now
end
local result = mw.smw.getQueryResult(
'[[Category:Phabricator Tasks]][[Has subobject.Project::~Platform Team Workboards*]]' ..
'[[Task Created Timestamp::>' .. timestamp_start .. ']]' ..
'[[Task Created Timestamp::<<' .. timestamp_stop .. ']]' ..
'|limit=3000' )
if result ~= nil then
created = created + #result.results
end
result = mw.smw.getQueryResult(
'[[Category:Phabricator Tasks]][[Has subobject.Project::~Platform Team Workboards*]]' ..
'[[Task Closed Timestamp::>' .. timestamp_start .. ']]' ..
'[[Task Closed Timestamp::<<' .. timestamp_stop .. ']]' ..
'|limit=3000' )
if result ~= nil then
closed = closed + #result.results
end
s = s .. 'Created ;' .. os.date('%Y-%m-%d', timestamp_stop) .. ';' .. created .. '\n'
s = s .. 'Closed ;' .. os.date('%Y-%m-%d', timestamp_stop) .. ';' .. closed .. '\n'
timestamp_start = timestamp_stop
end
return s
return s
end
end


function p.cptWorkboardsTableRow(frame)
function p.greenDonePointsReport(frame)
local s = ''
local sprintDates = mw.text.split(frame.args[1], ',')
local link = frame.args[1]
local points = {}
local category = frame.args[2]
s = ''
local kanban = frame.args[3]
for index = 2, #sprintDates do
local backlog = frame.args[4]
sum = 0
if ( #category > 0 and ( #kanban == 0 and #backlog == 0 )) or
local result = mw.smw.getQueryResult(
( #category == 0 and ( #kanban > 0 or ( #backlog > 0 and backlog ~= 'Watching / External' ))) then
'[[Project::Platform Team Workboards (Green)]][[Column::Done]]' ..
s = s .. '\n|' .. link
'[[Column Entry Date::>>' .. sprintDates[index - 1] .. ']]' ..
s = s .. '\n|' .. category
'[[Column Entry Date::<' .. sprintDates[index] .. ']]' ..
s = s .. '\n|' .. kanban
'|?-Has subobject.Points' )
s = s .. '\n|' .. backlog
if result ~= nil then
s = s .. '\n|-'
for k,v in pairs( result.results ) do
if #v.printouts.Points > 0 then
sum = sum + v.printouts.Points[next(v.printouts.Points)]
end
end
s = s .. sprintDates[index] .. ',' .. sum .. '\n'
end
end
end
return s
return s
end
end


function p.Workboard(frame)
function p.greenDoneTasksReport(frame)
local s = ''
local sprintDates = mw.text.split(frame.args[1], ',')
local epic = frame.args[1]
local points = {}
local result = mw.smw.getQueryResult(
s = ''
'[[Has subobject::<q>[[Project::Core Platform Team]][[Column::' ..
for index = 2, #sprintDates do
epic .. ']]</q>]][[Status::open||stalled]]' ..
count = 0
'|?CPT Kanban Column|?CPT Backlog Column|link=none|limit=500' )
local result = mw.smw.getQueryResult(
if result ~= nil then
'[[Project::Platform Team Workboards (Green)]][[Column::Done]]' ..
local tasks = {}
'[[Column Entry Date::>>' .. sprintDates[index - 1] .. ']]' ..
local columns = {}
'[[Column Entry Date::<' .. sprintDates[index] .. ']]' )
local empty = true
if result ~= nil then
local missing = false
count = #result.results
for k1,v1 in pairs( result.results ) do
s = s .. sprintDates[index] .. ',' .. count .. '\n'
local kanban_column = v1.printouts['CPT Kanban Column'][1]
local backlog_column = v1.printouts['CPT Backlog Column'][1]
empty = false
if kanban_column ~= nil then
tasks[v1.fulltext] = kanban_column
columns[kanban_column] = true
elseif backlog_column ~= nil then
tasks[v1.fulltext] = backlog_column
columns[backlog_column] = true
else
tasks[v1.fulltext] = false
missing = true
end
end
end
if ( empty ) then
end
s = 'No results'
return s
else
end
local sorted_columns = {}
 
for k1,v1 in pairs ( columns ) do
function p.clinicDutyTasksReport(frame)
table.insert( sorted_columns, k1 )
local column = frame.args[1]
end
local sprintDates = mw.text.split(mw.text.trim(frame.args[2]), ',')
table.sort( sorted_columns )
local points = {}
s = s .. '{| style="border-spacing:10px;border-collapse:separate;"\n'
s = ''
for k1,v1 in pairs( sorted_columns ) do
for index = 2, #sprintDates do
s = s .. '! style="border:1px solid #000;padding:5px;background-color:#bbb;text-align:center;" |' .. v1 .. '\n'
count = 0
end
local result = mw.smw.getQueryResult(
if ( missing ) then
'[[Transition Project::Platform Team Workboards (Clinic Duty Team)||Platform Team Workboards (External Code Reviews)]]' ..
s = s .. '! style="border:1px solid #000;padding:5px;background-color:#bbb;text-align:center;" |MISSING COLUMN\n'
'[[Transition Column::' .. column .. ']]' ..
end
'[[Transition Type::Entered Column]]' ..
s = s .. '|-\n'
'[[Transition Date::>' .. sprintDates[index - 1] .. ']]' ..
for k1,v1 in pairs( sorted_columns ) do
'[[Transition Date::<<' .. sprintDates[index] .. ']]' ..
s = s .. '| style="vertical-align:top;min-width:200px;" |\n'
'|?Transition Column')
for k2,v2 in pairs ( tasks ) do
if result ~= nil then
if v1 == v2 then
count = #result.results
s = s .. '*[[' .. k2 .. ']]\n'
s = s .. sprintDates[index] .. ',' .. count .. '\n'
end
end
end
if ( missing ) then
s = s .. '| style="vertical-align:top;min-width:200px;" |\n'
for k1,v1 in pairs ( tasks ) do
if v1 == false then
s = s .. '{| width=100%\n| style="border:2px solid #000;padding:5px;text-align:center;vertical-align:middle;" |[[' .. k1 .. ']]\n'
end
end
end
s = s .. '|}'
end
end
end
end
return s
return s
end
end
return p
return p

Latest revision as of 21:40, 29 July 2020

Documentation for this module may be created at Module:Reports/doc

local p = {}

function p.taskCreationClosureReport(frame)
	local start = {
		year = frame.args[1],
		month = frame.args[2],
		day = frame.args[3]
	}
	local step = frame.args[4]
	local timestamp_start = os.time( start )
	local now = os.time()
	local s = ''
	local created = 0
	local closed = 0
	while timestamp_start < now do
		local timestamp_stop = timestamp_start + (step * 86400)
		if timestamp_stop > now then
			timestamp_stop = now
		end
		local result = mw.smw.getQueryResult(
			'[[Category:Phabricator Tasks]][[Has subobject.Project::~Platform Team Workboards*]]' ..
			'[[Task Created Timestamp::>' .. timestamp_start .. ']]' ..
			'[[Task Created Timestamp::<<' .. timestamp_stop .. ']]' ..
			'|limit=3000' )
		if result ~= nil then
			created = created + #result.results
		end
		result = mw.smw.getQueryResult(
			'[[Category:Phabricator Tasks]][[Has subobject.Project::~Platform Team Workboards*]]' ..
			'[[Task Closed Timestamp::>' .. timestamp_start .. ']]' ..
			'[[Task Closed Timestamp::<<' .. timestamp_stop .. ']]' ..
			'|limit=3000' )
		if result ~= nil then
			closed = closed + #result.results
		end
		s = s .. 'Created ;' .. os.date('%Y-%m-%d', timestamp_stop) .. ';' .. created .. '\n'
		s = s .. 'Closed ;' .. os.date('%Y-%m-%d', timestamp_stop) .. ';' .. closed .. '\n'
		timestamp_start = timestamp_stop
	end
	return s
end

function p.greenDonePointsReport(frame)
	local sprintDates = mw.text.split(frame.args[1], ',')
	local points = {}
	s = ''
	for index = 2, #sprintDates do
		sum = 0
		local result = mw.smw.getQueryResult(
			'[[Project::Platform Team Workboards (Green)]][[Column::Done]]' ..
			'[[Column Entry Date::>>' .. sprintDates[index - 1] .. ']]' ..
			'[[Column Entry Date::<' .. sprintDates[index] .. ']]' ..
			'|?-Has subobject.Points' )
		if result ~= nil then
			for k,v in pairs( result.results ) do
				if #v.printouts.Points > 0 then
					sum = sum + v.printouts.Points[next(v.printouts.Points)]
				end
			end
			s = s .. sprintDates[index] .. ',' .. sum .. '\n'
		end
	end
	return s
end

function p.greenDoneTasksReport(frame)
	local sprintDates = mw.text.split(frame.args[1], ',')
	local points = {}
	s = ''
	for index = 2, #sprintDates do
		count = 0
		local result = mw.smw.getQueryResult(
			'[[Project::Platform Team Workboards (Green)]][[Column::Done]]' ..
			'[[Column Entry Date::>>' .. sprintDates[index - 1] .. ']]' ..
			'[[Column Entry Date::<' .. sprintDates[index] .. ']]' )
		if result ~= nil then
			count = #result.results
			s = s .. sprintDates[index] .. ',' .. count .. '\n'
		end
	end
	return s
end

function p.clinicDutyTasksReport(frame)
	local column = frame.args[1]
	local sprintDates = mw.text.split(mw.text.trim(frame.args[2]), ',')
	local points = {}
	s = ''
	for index = 2, #sprintDates do
		count = 0
		local result = mw.smw.getQueryResult(
			'[[Transition Project::Platform Team Workboards (Clinic Duty Team)||Platform Team Workboards (External Code Reviews)]]' ..
			'[[Transition Column::' .. column .. ']]' ..
			'[[Transition Type::Entered Column]]' ..
			'[[Transition Date::>' .. sprintDates[index - 1] .. ']]' ..
			'[[Transition Date::<<' .. sprintDates[index] .. ']]' ..
			'|?Transition Column')
		if result ~= nil then
			count = #result.results
			s = s .. sprintDates[index] .. ',' .. count .. '\n'
		end
	end
	return s
end

return p