class TaskJuggler::TimeSheet
The TimeSheet
class stores the work related bits of a time sheet. For each task it holds a TimeSheetRecord
object. A time sheet is always bound to an existing Resource
.
Attributes
Public Class Methods
Source
# File lib/taskjuggler/TimeSheets.rb, line 248 def initialize(resource, interval, scenarioIdx) raise "Illegal resource" unless resource.is_a?(Resource) @resource = resource raise "Interval undefined" if interval.nil? @interval = interval raise "Sceneario index undefined" if scenarioIdx.nil? @scenarioIdx = scenarioIdx @sourceFileInfo = nil # This flag is set to true if at least one record was reported as # percentage. @percentageUsed = false # The TimeSheetRecord list. @records = [] @messageHandler = MessageHandlerInstance.instance end
Public Instance Methods
Source
# File lib/taskjuggler/TimeSheets.rb, line 265 def<<(record) @records.each do |r| if r.task == record.task error('ts_duplicate_task', "Duplicate records for task #{r.taskId}") end end @records << record end
Add a new TimeSheetRecord
to the list.
Source
# File lib/taskjuggler/TimeSheets.rb, line 276 def check totalSlots = 0 @records.each do |record| record.check totalSlots += record.work end unless (scenarioIdx = @resource.project['trackingScenarioIdx']) error('ts_no_tracking_scenario', 'No trackingscenario has been defined.') end if @resource['efficiency', scenarioIdx] > 0.0 targetSlots = totalNetWorkingSlots # This is the acceptable rounding error when checking the total # reported work. delta = 1 if totalSlots < (targetSlots - delta) error('ts_work_too_low', "The total work to be reported for this time sheet " + "is #{workWithUnit(targetSlots)} but only " + "#{workWithUnit(totalSlots)} were reported.") end if totalSlots > (targetSlots + delta) error('ts_work_too_high', "The total work to be reported for this time sheet " + "is #{workWithUnit(targetSlots)} but " + "#{workWithUnit(totalSlots)} were reported.") end else if totalSlots > 0 error('ts_work_not_null', "The reported work for non-working resources must be 0.") end end end
Perform all kinds of consitency checks.
Source
# File lib/taskjuggler/TimeSheets.rb, line 361 def daysToSlots(days) ((days * 60 * 60 * @resource.project.dailyWorkingHours) / @resource.project['scheduleGranularity']).to_i end
Source
# File lib/taskjuggler/TimeSheets.rb, line 366 def error(id, text, sourceFileInfo = nil) @messageHandler.error(id, text, sourceFileInfo || @sourceFileInfo, nil, @resource) end
Source
# File lib/taskjuggler/TimeSheets.rb, line 345 def percentToSlots(value) @percentageUsed = true (totalGrossWorkingSlots * value).to_i end
Converts allocation percentage into time slots.
Source
# File lib/taskjuggler/TimeSheets.rb, line 356 def slotsToDays(slots) slots * @resource.project['scheduleGranularity'] / (60 * 60 * @resource.project.dailyWorkingHours) end
Source
# File lib/taskjuggler/TimeSheets.rb, line 352 def slotsToPercent(slots) slots.to_f / totalGrossWorkingSlots end
Computes how many percent the slots are of the total working slots in the report time frame.
Source
# File lib/taskjuggler/TimeSheets.rb, line 325 def totalGrossWorkingSlots project = @resource.project # Calculate the number of weeks in the report weeksToReport = (@interval.end - @interval.start).to_f / (60 * 60 * 24 * 7) daysToSlots((project.weeklyWorkingDays * weeksToReport).to_i) end
Compute the total number of potential working time slots during the report period. This value is not resource specific.
Source
# File lib/taskjuggler/TimeSheets.rb, line 336 def totalNetWorkingSlots project = @resource.project startIdx = project.dateToIdx(@interval.start) endIdx = project.dateToIdx(@interval.end) @resource.getAllocatedSlots(@scenarioIdx, startIdx, endIdx, nil) + @resource.getFreeSlots(@scenarioIdx, startIdx, endIdx) end
Compute the total number of actual working time slots of the Resource
. This is the sum of allocated, free time slots.
Source
# File lib/taskjuggler/TimeSheets.rb, line 313 def warnOnDelta project = @resource.project startIdx = project.dateToIdx(@interval.start) endIdx = project.dateToIdx(@interval.end) @records.each do |record| record.warnOnDelta(startIdx, endIdx) end end
Source
# File lib/taskjuggler/TimeSheets.rb, line 371 def warning(id, text, sourceFileInfo = nil) @messageHandler.warning(id, text, sourceFileInfo, nil, @resource) end
Private Instance Methods
Source
# File lib/taskjuggler/TimeSheets.rb, line 377 def workWithUnit(slots) if @percentageUsed "#{(slotsToPercent(slots) * 100.0).to_i}%" else "#{slotsToDays(slots)} days" end end