Permalink
Browse files

fixed things that broke from the merge from master and wrote a new ex…

…ceeds max staff method
  • Loading branch information...
1 parent 36c0f0f commit 469197582327f0545fb51fe4dc3fc7b3ff7fba66 Wei Yan committed Jul 25, 2009
Showing with 21 additions and 13 deletions.
  1. +1 −0 app/models/department_config.rb
  2. +18 −7 app/models/shift.rb
  3. +0 −3 lib/tasks/generate_shifts.rake
  4. +2 −3 preload_data/department_configs.yml
@@ -5,6 +5,7 @@ class DepartmentConfig < ActiveRecord::Base
validates_uniqueness_of :department_id
validates_numericality_of :time_increment, :grace_period, :schedule_start,
:schedule_end, :description_min, :reason_min, :warning_weeks
+ validate :increment_factor_of_60
PAYFORM_PERIOD = [
["Weekly", false],
View
@@ -7,7 +7,7 @@ class Shift < ActiveRecord::Base
belongs_to :location
has_one :report, :dependent => :destroy
has_many :sub_requests, :dependent => :destroy
-
+
validates_presence_of :user
validates_presence_of :location
validates_presence_of :start
@@ -125,11 +125,22 @@ def combine_with_surrounding_shifts
end
def exceeds_max_staff?
- count = 1 # 1 because needs to count current shift
- Shift.find(:all, :conditions => {:location_id => self.location_id, :scheduled => true}).each do |other|
- count += 1 if (self.start..self.end).overlaps?(other.start..other.end) && self.end != other.start && self.start != other.end
+ count = 0
+ shifts_in_period = []
+ 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
- return count > self.location.max_staff
+ count + 1 > self.location.max_staff
end
@@ -197,8 +208,8 @@ def adjust_sub_requests
end
end
end
-
-
+
+
class << columns_hash['start']
def type
:datetime
@@ -9,9 +9,6 @@ namespace :db do
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
puts "creating a timeslot from 9AM to 11PM and populating the timeslot with shifts and sub requests"
@@ -1,6 +1,5 @@
----
-department_configs_001:
- complex: f
+---
+department_configs_001:
created_at: 2009-06-22 17:27:52
day: "6"
department_id: "1"

0 comments on commit 4691975

Please sign in to comment.