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.



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/taskjuggler/TimeSheets.rb', line 249

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.



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

def interval
  @interval
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#scenarioIdxObject (readonly)

Returns the value of attribute scenarioIdx.



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

def scenarioIdx
  @scenarioIdx
end

#sourceFileInfoObject

Returns the value of attribute sourceFileInfo.



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

def sourceFileInfo
  @sourceFileInfo
end

Instance Method Details

#<<(record) ⇒ Object

Add a new TimeSheetRecord to the list.



266
267
268
269
270
271
272
273
274
# File 'lib/taskjuggler/TimeSheets.rb', line 266

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.



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
312
# File 'lib/taskjuggler/TimeSheets.rb', line 277

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



362
363
364
365
# File 'lib/taskjuggler/TimeSheets.rb', line 362

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

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



367
368
369
370
# File 'lib/taskjuggler/TimeSheets.rb', line 367

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

#percentToSlots(value) ⇒ Object

Converts allocation percentage into time slots.



346
347
348
349
# File 'lib/taskjuggler/TimeSheets.rb', line 346

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

#slotsToDays(slots) ⇒ Object



357
358
359
360
# File 'lib/taskjuggler/TimeSheets.rb', line 357

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.



353
354
355
# File 'lib/taskjuggler/TimeSheets.rb', line 353

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.



326
327
328
329
330
331
332
333
# File 'lib/taskjuggler/TimeSheets.rb', line 326

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

#totalNetWorkingSlotsObject

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



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

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



372
373
374
# File 'lib/taskjuggler/TimeSheets.rb', line 372

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

#warnOnDeltaObject



314
315
316
317
318
319
320
321
322
# File 'lib/taskjuggler/TimeSheets.rb', line 314

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