Class: Query::TimeAccumulator

Inherits:
Object
  • Object
show all
Defined in:
lib/query/time_accumulator.rb

Overview

singleton class to calculate time values for a given set of tasks

Class Method Summary collapse

Class Method Details

.get_hours_beyond(tasks, next_time_frame) ⇒ Float

method to calculate the working hours of tasks starting during the requested time interval, but ending after

Parameters:

  • tasks (Array)

    the tasks starting during the time interval

  • next_time_frame (Time)

    the end time of the interval

Returns:

  • (Float)

    the sum of the working hours



56
57
58
59
60
61
62
63
# File 'lib/query/time_accumulator.rb', line 56

def self.get_hours_beyond(tasks, next_time_frame)
  total = 0.0
  tasks.each { |task|
    total += next_time_frame - task.start_time
  }

  total = (total / 3600).round(2)
end

.get_hours_during(tasks) ⇒ Float

method to calculate the working hours of tasks occurring during the requested time interval

Parameters:

  • tasks (Array)

    the tasks occurring during the time interval

Returns:

  • (Float)

    the sum of the working hours



28
29
30
31
32
33
34
35
# File 'lib/query/time_accumulator.rb', line 28

def self.get_hours_during(tasks)
  total = 0.0
  tasks.each { |task|
    total += task.end_time - task.start_time
  }

  total = (total / 3600).round(2)
end

.get_hours_into(tasks, time_frame) ⇒ Float

method to calculate the working hours of tasks ending during the requested time interval, but starting before

Parameters:

  • tasks (Array)

    the tasks ending during the time interval

  • time_frame (Time)

    the start time of the interval

Returns:

  • (Float)

    the sum of the working hours



42
43
44
45
46
47
48
49
# File 'lib/query/time_accumulator.rb', line 42

def self.get_hours_into(tasks, time_frame)
  total = 0.0
  tasks.each { |task|
    total += task.end_time - time_frame
  }

  total = (total / 3600).round(2)
end

.get_interval_worktime(tasks, start_time, end_time, time_frame) ⇒ Hash

method to calculate the work time in the given time period

Parameters:

  • tasks (Hash)

    the collected tasks occuring in the time interval

  • start_time (Time)

    the start time of the time interval

  • end_time (Time)

    the end time of the time interval

  • time_frame (Integer)

    the time of the interval in hours

Returns:

  • (Hash)

    a hash containing all time values for the considered intervals



13
14
15
16
17
18
19
20
21
22
# File 'lib/query/time_accumulator.rb', line 13

def self.get_interval_worktime(tasks, start_time, end_time, time_frame)
  times = {
    :during => get_hours_during(tasks[:during]),
    :over => (tasks[:over].size > 0 ? time_frame : 0),
    :into => get_hours_into(tasks[:into], start_time),
    :beyond => get_hours_beyond(tasks[:beyond], end_time)
  }

  return times
end