class TaskJuggler::NikuReport
The Niku report can be used to export resource allocation data for certain task groups in the Niku XOG format. This file can be read by the Clarity enterprise resource management software from Computer Associates. Since I don’t think this is a use case for many users, the implementation is somewhat of a hack. The report relies on 3 custom attributes that the user has to define in the project. Resources must be tagged with a ClarityRID and Tasks must have a ClarityPID and a ClarityPName. This file format works for our Clarity installation. I have no idea if it is even portable to other Clarity installations.
Public Class Methods
new(report)
click to toggle source
Calls superclass method
# File lib/taskjuggler/reports/NikuReport.rb, line 56 def initialize(report) super(report) # A Hash to store NikuProject objects by id @projects = {} # A Hash to map ClarityRID to Resource @resources = {} # Unallocated and vacation time during the report period for all # resources hashed by ClarityId. Values are in days. @resourcesFreeWork = {} # Resources total effort during the report period hashed by ClarityId @resourcesTotalEffort = {} @scenarioIdx = nil end
Public Instance Methods
generateIntermediateFormat()
click to toggle source
Calls superclass method
# File lib/taskjuggler/reports/NikuReport.rb, line 75 def generateIntermediateFormat super @scenarioIdx = a('scenarios')[0] computeResourceTotals collectProjects computeProjectAllocations end
to_csv()
click to toggle source
# File lib/taskjuggler/reports/NikuReport.rb, line 207 def to_csv table = [] # Header line with project names table << (row = []) # First column is the resource name and ID. row << "" projectIds = @projects.keys.sort projectIds.each do |projectId| row << @projects[projectId].name end # Header line with project IDs table << (row = []) row << "Resource" projectIds.each do |projectId| row << projectId end @resourcesTotalEffort.keys.sort.each do |resourceId| # Add one line per resource. table << (row = []) row << "#{@resources[resourceId].name} (#{resourceId})" projectIds.each do |projectId| row << sum(projectId, resourceId) end end table end
to_html()
click to toggle source
# File lib/taskjuggler/reports/NikuReport.rb, line 85 def to_html tableFrame = generateHtmlTableFrame tableFrame << (tr = XMLElement.new('tr')) tr << (td = XMLElement.new('td')) td << (table = XMLElement.new('table', 'class' => 'tj_table', 'cellspacing' => '1')) # Table Header with two rows. First the project name, then the ID. table << (thead = XMLElement.new('thead')) thead << (tr = XMLElement.new('tr', 'class' => 'tabline')) # First line tr << htmlTabCell('Project', true, 'right') @projects.keys.sort.each do |projectId| # Don't include projects without allocations. next if projectTotal(projectId) <= 0.0 name = @projects[projectId].name # To avoid exploding tables for long project names, we only show the # last 15 characters for those. We expect the last characters to be # more significant in those names than the first. name = '...' + name[-15..-1] if name.length > 15 tr << htmlTabCell(name, true, 'center') end tr << htmlTabCell('', true) # Second line thead << (tr = XMLElement.new('tr', 'class' => 'tabline')) tr << htmlTabCell('Resource', true, 'left') @projects.keys.sort.each do |projectId| # Don't include projects without allocations. next if projectTotal(projectId) <= 0.0 tr << htmlTabCell(projectId, true, 'center') end tr << htmlTabCell('Total', true, 'center') # The actual content. One line per resource. table << (tbody = XMLElement.new('tbody')) numberFormat = a('numberFormat') @resourcesTotalEffort.keys.sort.each do |resourceId| tbody << (tr = XMLElement.new('tr', 'class' => 'tabline')) tr << htmlTabCell("#{@resources[resourceId].name} (#{resourceId})", true, 'left') @projects.keys.sort.each do |projectId| next if projectTotal(projectId) <= 0.0 value = sum(projectId, resourceId) valStr = numberFormat.format(value) valStr = '' if valStr.to_f == 0.0 tr << htmlTabCell(valStr) end tr << htmlTabCell(numberFormat.format(resourceTotal(resourceId)), true) end # Project totals tbody << (tr = XMLElement.new('tr', 'class' => 'tabline')) tr << htmlTabCell('Total', 'true', 'left') @projects.keys.sort.each do |projectId| next if (pTotal = projectTotal(projectId)) <= 0.0 tr << htmlTabCell(numberFormat.format(pTotal), true, 'right') end tr << htmlTabCell(numberFormat.format(total()), true, 'right') tableFrame end
to_niku()
click to toggle source
# File lib/taskjuggler/reports/NikuReport.rb, line 149 def to_niku xml = XMLDocument.new xml << XMLComment.new(<<"EOT" Generated by #{AppConfig.softwareName} v#{AppConfig.version} on #{TjTime.new} For more information about #{AppConfig.softwareName} see #{AppConfig.contact}. Project: #{@project['name']} Date: #{@project['now']} EOT ) xml << (nikuDataBus = XMLElement.new('NikuDataBus', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:noNamespaceSchemaLocation' => '../xsd/nikuxog_project.xsd')) nikuDataBus << XMLElement.new('Header', 'action' => 'write', 'externalSource' => 'NIKU', 'objectType' => 'project', 'version' => '7.5.0') nikuDataBus << (projects = XMLElement.new('Projects')) timeFormat = '%Y-%m-%dT%H:%M:%S' numberFormat = a('numberFormat') @projects.keys.sort.each do |projectId| prj = @projects[projectId] projects << (project = XMLElement.new('Project', 'name' => prj.name, 'projectID' => prj.id)) project << (resources = XMLElement.new('Resources')) # We iterate over all resources to ensure that all have an entry in # the Clarity database for all projects. This is done to work around a # limitation of Clarity with respect to filling time sheets with # assigned projects. @resources.keys.sort.each do |clarityRID| resources << (resource = XMLElement.new('Resource', 'resourceID' => clarityRID, 'defaultAllocation' => '0')) resource << (allocCurve = XMLElement.new('AllocCurve')) sum = sum(prj.id, clarityRID) allocCurve << (XMLElement.new('Segment', 'start' => a('start').to_s(timeFormat), 'finish' => (a('end') - 1).to_s(timeFormat), 'sum' => numberFormat.format(sum).to_s)) end # The custom information section usually contains Clarity installation # specific parts. They are identical for each project section, so we # mis-use the title attribute to insert them as an XML blob. project << XMLBlob.new(a('title')) unless a('title').empty? end xml.to_s end