Class: TaskJuggler::TimeSheet

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/TimeSheets.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, interval, scenarioIdx) ⇒ TimeSheet

Returns a new instance of TimeSheet.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# 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

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



246
247
248
# File 'lib/taskjuggler/TimeSheets.rb', line 246

def interval
  @interval
end

#resourceObject (readonly)

Returns the value of attribute resource.



246
247
248
# File 'lib/taskjuggler/TimeSheets.rb', line 246

def resource
  @resource
end

#scenarioIdxObject (readonly)

Returns the value of attribute scenarioIdx.



246
247
248
# File 'lib/taskjuggler/TimeSheets.rb', line 246

def scenarioIdx
  @scenarioIdx
end

#sourceFileInfoObject

Returns the value of attribute sourceFileInfo.



245
246
247
# File 'lib/taskjuggler/TimeSheets.rb', line 245

def sourceFileInfo
  @sourceFileInfo
end

Instance Method Details

#<<(record) ⇒ Object

Add a new TimeSheetRecord to the list.



265
266
267
268
269
270
271
272
273
# 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

#checkObject

Perform all kinds of consitency checks.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# 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

#daysToSlots(days) ⇒ Object



360
361
362
363
# File 'lib/taskjuggler/TimeSheets.rb', line 360

def daysToSlots(days)
  ((days * 60 * 60 * @resource.project.dailyWorkingHours) /
   @resource.project['scheduleGranularity']).to_i
end

#error(id, text, sourceFileInfo = nil) ⇒ Object



365
366
367
368
# File 'lib/taskjuggler/TimeSheets.rb', line 365

def error(id, text, sourceFileInfo = nil)
  @messageHandler.error(id, text, sourceFileInfo || @sourceFileInfo,
                        nil, @resource)
end

#percentToSlots(value) ⇒ Object

Converts allocation percentage into time slots.



344
345
346
347
# File 'lib/taskjuggler/TimeSheets.rb', line 344

def percentToSlots(value)
  @percentageUsed = true
  (totalGrossWorkingSlots * value).to_i
end

#slotsToDays(slots) ⇒ Object



355
356
357
358
# File 'lib/taskjuggler/TimeSheets.rb', line 355

def slotsToDays(slots)
  slots * @resource.project['scheduleGranularity'] /
    (60 * 60 * @resource.project.dailyWorkingHours)
end

#slotsToPercent(slots) ⇒ Object

Computes how many percent the slots are of the total working slots in the report time frame.



351
352
353
# File 'lib/taskjuggler/TimeSheets.rb', line 351

def slotsToPercent(slots)
  slots.to_f / totalGrossWorkingSlots
end

#totalGrossWorkingSlotsObject

Compute the total number of potential working time slots during the report period. This value is not resource specific.



325
326
327
328
329
330
331
# 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) / (60 * 60 * 24 * 7)

  daysToSlots(project.weeklyWorkingDays * weeksToReport)
end

#totalNetWorkingSlotsObject

Compute the total number of actual working time slots of the Resource. This is the sum of allocated, free time slots.



335
336
337
338
339
340
341
# File 'lib/taskjuggler/TimeSheets.rb', line 335

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

#warning(id, text, sourceFileInfo = nil) ⇒ Object



370
371
372
# File 'lib/taskjuggler/TimeSheets.rb', line 370

def warning(id, text, sourceFileInfo = nil)
  @messageHandler.warning(id, text, sourceFileInfo, nil, @resource)
end

#warnOnDeltaObject



313
314
315
316
317
318
319
320
321
# 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