app/models/task.rb
def missed_between(start_date, end_date)
    completed_shifts_task = ShiftsTask.find_all_by_task_id(self.id).select{|st| (st.created_at >= start_date) && (st.created_at <= end_date) && !st.missed}
    shifts_at_location = Shift.find_all_by_location_id(self.location_id).select{|s| (s.start >= start_date) && (s.start <= end_date) && (s.submitted?)}

    missed_shifts_tasks_slots = []
    missed_shifts_hash = {}

    if self.kind == "Hourly"
      missed_shifts_tasks_slots = (start_date.to_time.to_i..end_date.to_time.to_i).step(3600).to_a.map{|i| Time.at(i)}
    elsif self.kind == "Daily"
      missed_shifts_tasks_slots = (start_date..end_date).to_a
    elsif self.kind == "Weekly"
      missed_shifts_tasks_slots = (start_date..end_date).to_a.select{|d| d.strftime("%a") == self.day_in_week}
    end

    for slot in 0..(missed_shifts_tasks_slots.size - 2)
      guilty_shifts = []
      shifts_tasks_in_slot = completed_shifts_task.select{|st| (st.created_at > missed_shifts_tasks_slots[slot]) && (st.created_at < missed_shifts_tasks_slots[slot + 1])}
      shifts_in_slot = shifts_at_location.select{|s| (s.end > missed_shifts_tasks_slots[slot]) && (s.start < missed_shifts_tasks_slots[slot + 1])}
      shifts_in_slot = shifts_in_slot.delete_if{|s| self.kind != "Hourly" && s.end.seconds_since_midnight < self.time_of_day.seconds_since_midnight }
      if shifts_tasks_in_slot.empty? && !shifts_in_slot.empty?
        guilty_shifts << shifts_in_slot
        guilty_shifts.flatten!
        missed_shifts_hash[missed_shifts_tasks_slots[slot]] = guilty_shifts
      end
    end

    missed_shifts_hash
  end
# returns a hash containing times associated with shifts tasks that were not completed, and the shifts that failed to do them
returns a hash containing times associated with shifts tasks that were not completed, and the shifts that failed to do them
returns a hash containing times associated with shifts tasks that were not completed and the shifts that failed to do them
def missed_between(start_date, end_date)
    completed_shifts_task = ShiftsTask.find_all_by_task_id(self.id).select{|st| (st.created_at >= start_date) && (st.created_at <= end_date) && !st.missed}
    shifts_at_location = Shift.find_all_by_location_id(self.location_id).select{|s| (s.start >= start_date) && (s.start <= end_date) && (s.submitted?)}
    missed_shifts_tasks_slots = []
    missed_shifts_hash = {}
    if self.kind == "Hourly"
      missed_shifts_tasks_slots = (start_date.to_time.to_i..end_date.to_time.to_i).step(3600).to_a.map{|i| Time.at(i)}
    elsif self.kind == "Daily"
      missed_shifts_tasks_slots = (start_date..end_date).to_a
    elsif self.kind == "Weekly"
      missed_shifts_tasks_slots = (start_date..end_date).to_a.select{|d| d.strftime("%a") == self.day_in_week}
    end
    for slot in 0..(missed_shifts_tasks_slots.size - 2)
      guilty_shifts = []
      shifts_tasks_in_slot = completed_shifts_task.select{|st| (st.created_at > missed_shifts_tasks_slots[slot]) && (st.created_at < missed_shifts_tasks_slots[slot + 1])}
      shifts_in_slot = shifts_at_location.select{|s| (s.end > missed_shifts_tasks_slots[slot]) && (s.start < missed_shifts_tasks_slots[slot + 1])}
      shifts_in_slot = shifts_in_slot.delete_if{|s| self.kind != "Hourly" && s.end.seconds_since_midnight < self.time_of_day.seconds_since_midnight }
      if shifts_tasks_in_slot.empty? && !shifts_in_slot.empty?
        guilty_shifts << shifts_in_slot
        guilty_shifts.flatten!
        missed_shifts_hash[missed_shifts_tasks_slots[slot]] = guilty_shifts
      end
    end
    missed_shifts_hash
  end
def missed_between ( start_date , end_date ) completed_shifts_task = ShiftsTask . find_all_by_task_id ( self . id ) . select { | st | ( st . created_at >= start_date ) && ( st . created_at <= end_date ) && ! st . missed } shifts_at_location = Shift . find_all_by_location_id ( self . location_id ) . select { | s | ( s . start >= start_date ) && ( s . start <= end_date ) && ( s . submitted? ) } missed_shifts_tasks_slots = [ ] missed_shifts_hash = { } if self . kind == "Hourly" missed_shifts_tasks_slots = ( start_date . to_time . to_i .. end_date . to_time . to_i ) . step ( 3600 ) . to_a . map { | i | Time . at ( i ) } elsif self . kind == "Daily" missed_shifts_tasks_slots = ( start_date .. end_date ) . to_a elsif self . kind == "Weekly" missed_shifts_tasks_slots = ( start_date .. end_date ) . to_a . select { | d | d . strftime ( "%a" ) == self . day_in_week } end for slot in 0 .. ( missed_shifts_tasks_slots . size - 2 ) guilty_shifts = [ ] shifts_tasks_in_slot = completed_shifts_task . select { | st | ( st . created_at > missed_shifts_tasks_slots [ slot ] ) && ( st . created_at < missed_shifts_tasks_slots [ slot + 1 ] ) } shifts_in_slot = shifts_at_location . select { | s | ( s . end > missed_shifts_tasks_slots [ slot ] ) && ( s . start < missed_shifts_tasks_slots [ slot + 1 ] ) } shifts_in_slot = shifts_in_slot . delete_if { | s | self . kind != "Hourly" && s . end . seconds_since_midnight < self . time_of_day . seconds_since_midnight } if shifts_tasks_in_slot . empty? && ! shifts_in_slot . empty? guilty_shifts << shifts_in_slot guilty_shifts . flatten! missed_shifts_hash [ missed_shifts_tasks_slots [ slot ] ] = guilty_shifts end end missed_shifts_hash end
returns a hash containing times associated with shifts tasks that were not completed, and the shifts that failed to do them
returns a hash containing times associated with shifts tasks that were not completed and the shifts that failed to do them
start_date
end_date