Skip to content

Commit

Permalink
fixed things that broke from the merge from master and wrote a new ex…
Browse files Browse the repository at this point in the history
…ceeds max staff method
  • Loading branch information
Wei Yan committed Jul 25, 2009
1 parent 36c0f0f commit 4691975
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/models/department_config.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DepartmentConfig < ActiveRecord::Base
validates_uniqueness_of :department_id validates_uniqueness_of :department_id
validates_numericality_of :time_increment, :grace_period, :schedule_start, validates_numericality_of :time_increment, :grace_period, :schedule_start,
:schedule_end, :description_min, :reason_min, :warning_weeks :schedule_end, :description_min, :reason_min, :warning_weeks
validate :increment_factor_of_60


PAYFORM_PERIOD = [ PAYFORM_PERIOD = [
["Weekly", false], ["Weekly", false],
Expand Down
25 changes: 18 additions & 7 deletions app/models/shift.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Shift < ActiveRecord::Base
belongs_to :location belongs_to :location
has_one :report, :dependent => :destroy has_one :report, :dependent => :destroy
has_many :sub_requests, :dependent => :destroy has_many :sub_requests, :dependent => :destroy

validates_presence_of :user validates_presence_of :user
validates_presence_of :location validates_presence_of :location
validates_presence_of :start validates_presence_of :start
Expand Down Expand Up @@ -125,11 +125,22 @@ def combine_with_surrounding_shifts
end end


def exceeds_max_staff? def exceeds_max_staff?
count = 1 # 1 because needs to count current shift count = 0
Shift.find(:all, :conditions => {:location_id => self.location_id, :scheduled => true}).each do |other| shifts_in_period = []
count += 1 if (self.start..self.end).overlaps?(other.start..other.end) && self.end != other.start && self.start != other.end Shift.find(:all, :conditions => {:location_id => self.location_id, :scheduled => true}).each do |shift|
shifts_in_period << shift if (self.start..self.end).overlaps?(other.start..other.end) && self.end != other.start && self.start != other.end
end
increment = self.department.department_config.time_increment
time = self.start + (increment / 2)
while (self.start..self.end).include?(time)
concurrent_shifts = 0
shifts_in_period.each do |shift|
concurrent_shifts += 1 if (shift.start..shift.end).include?(time)
end
count = concurrent_shifts if concurrent_shifts > count
time += increment
end end
return count > self.location.max_staff count + 1 > self.location.max_staff
end end




Expand Down Expand Up @@ -197,8 +208,8 @@ def adjust_sub_requests
end end
end end
end end


class << columns_hash['start'] class << columns_hash['start']
def type def type
:datetime :datetime
Expand Down
3 changes: 0 additions & 3 deletions lib/tasks/generate_shifts.rake
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ namespace :db do


Shift.delete_all Shift.delete_all


# This rake task is not very flexible
# Consult me before making changes - wei



# For each department, for each day from now until some time in the future, 1 time slot is created from 9AM to 11PM # For each department, for each day from now until some time in the future, 1 time slot is created from 9AM to 11PM
puts "creating a timeslot from 9AM to 11PM and populating the timeslot with shifts and sub requests" puts "creating a timeslot from 9AM to 11PM and populating the timeslot with shifts and sub requests"
Expand Down
5 changes: 2 additions & 3 deletions preload_data/department_configs.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,5 @@
--- ---
department_configs_001: department_configs_001:
complex: f
created_at: 2009-06-22 17:27:52 created_at: 2009-06-22 17:27:52
day: "6" day: "6"
department_id: "1" department_id: "1"
Expand Down

0 comments on commit 4691975

Please sign in to comment.