I need some assistance, I'm working on creating a weekly schedule. But my output is not displaying the desired criteria. Everything is displaying, but it's not assigning the start and end time properly and I can't figure out why. I'm new to ruby so any help would be greatly appreciated. Below is the method from my control and the output in the view.
def generate_schedule logger.info @generate_schedules # create hash for view @generate_schedules = Hash.new # find current required schedule schedule_structure = Availability.where(:addressable_type =>'CallCenter',:addressable_id => session[:employee].call_centers.first.id).all # find all available employee times employee_availability = Availability.where('priority > 0').where(:addressable_type => 'Employee', :addressable_id => session[:employee].call_centers.first.employees.collect(&:id)).all # create availability to requirement hash to determine order of days availability_to_requirement_hash = create_availability_to_requirement_hash(schedule_structure, employee_availability) # iterate through the hash day by day, a data is no use to us availability_to_requirement_hash.each do |day,a| # select the employees with availability for the chosen day, sort them by priority, and then iterate through them to clear the requirements employee_availability.select{|b| b.day_increment == day}.sort_by{|c| c.priority}.group_by(&:addressable).each do |employee, availabilities| # select the start time for the current day defined from requirement hash start_time = schedule_structure.select{|b| b.day_increment == day && b.priority > 0}.first.time_increment #define the length of the shift shift_length = employee.length_of_shift > availabilities.length ? availabilities.length : employee.length_of_shift #define the end time for the shift end_time = start_time + shift_length logger.info end_time #check if employee already defined in hash, if present add the shift as an array of date, start time and end time, if not then add employee to hash with value as array @generate_schedules.has_key?(employee) ? @generate_schedules[employee] << [day, start_time, end_time] : @generate_schedules[employee] = [[day, start_time, end_time]] logger.info schedule_structure #update the schedule structure to reflect the time removed // do not change database (1..shift_length).each do |d| schedule_structure.select{|e| e.day_increment == day && e.priority > 0}.first.priority -= 1 end end end end
Here's an example of my output:
Aucun commentaire:
Enregistrer un commentaire