Hi, I'm trying to write a program that creates an employee "on call" list for hourly workers. There are four crews: crew A works four 12 hour day shifts and then gets 4 days off. Crew B rotates opposite A and works four 12 hour night shifts, and then gets four days off. C & D work the four days/nights that A & B are off, then Crew A returns to work four 12 hour night shifts and B gets to work 4 days. While each crew is off, three employees from each of the off shift crews are on call to cover for absences, three on days and three on nights. The list of employees who are on call rotates each day/night so that all employees are eventually on call. My goal is to generate a list of the on call employees for each shift that looks like this:
Basically, my problem is finding a way to calculate which crews are on call and which are working for a given shift/week/month. I am storing crew names in a text file, then reading them into a String array using BufferedReader. I wrote an array to cycle the next employee to the top of the list for each shift, and I am using Joda Time to cycle through each date, and I have formatted the output to print out correctly. Here is the code I have so far:
if I'm reading this right, crew A works 4 days, then for the next 4 days 3 of them are day-shift-on-call per day (one each day has the day off),
then they work 4 nights, then for the next 4 nights 3 of them are night-shift-on-call per night (one each night has the night off).
if so, work on a 16 day cycle using Calendar's DAY_OF_YEAR (if cycle starts on say 29 Dec, add 3 to DAY_OF_YEAR)
so cycleDay = (DAY_OF_YEAR+3?) % 16 (= 0 to 15)
cycleWeek = cycleDay/4 (= 0 to 3)
give each crew A member a day-off number from 0 to 3
now it's just working the numbers
if cycleWeek == 0:
A - all on day shift
cycleDay % 4 (0 to 3) whoever matches this in crew C has day off, other 3 in C are on call day shift
B - all on night shift
cycleDay % 4 (0 to 3) whoever matches this in crew D has night off, other 3 in D are on call night shift
if cycleWeek == 1:
C - all on day shift
cycleDay % 4 (0 to 3) whoever matches this in crew A has day off, other 3 in A are on call day shift
D - all on night shift
cycleDay % 4 (0 to 3) whoever matches this in crew B has night off, other 3 in B are on call night shift
repeat for == 2 and ==3, with A/B (C/D on call) swapping, C/D (A/B on call) swapping
Thanks for the help. One point I did not explain is that there are 7 employees per crew, not just four, so 4 of them are off at a time. Would that change the solution a great deal?
Joined: Jun 09, 2003
> so cycleDay = (DAY_OF_YEAR+3?) % 16 (= 0 to 15)
actually DAY_OF_YEAR needs to have 1 deducted.
if the cycle started on 1 Jan, DAY_OF_YEAR would be 1, but it should be day 0 of the cycle.
OK the crews are 7, and it would be relatively simple if it was the same 3 on-call for the 4 days,
meaning 4 would be totally off, then a different 3 on-call for 4 nights, with the others totally off,
this rotating over a 7 cycle period, so that each member of the crew was on-call for 3 cycles of
4 days, 3 cycles of 4 nights, and 1 cycle of not on-call day or night.
to do this, start with the cycle day, divide by 16 to get cycleOfYear
cycleOfYear % 7 will give you the onCallCycle
each crew member is numbered 0 to 6
(crewNumber + onCallCycle) % 7 = aNumber
if aNumber is 0,1,2, = dayShift onCall, 3,4,5 = nightShift onCall, 6 = off both day and night in that cycle
crew C in the 1st 16 day cycle of the year
onCallCycle would be 0
so the 'aNumber' for the crew would be
(0+0)%7 = 0 (day shift on call for the 4 days)
(1+0)%7 = 1 (day shift on call for the 4 days)
(2+0)%7 = 2 (day shift on call for the 4 days)
(3+0)%7 = 3 (night shift on call for the 4 nights)
(4+0)%7 = 4 (night shift on call for the 4 nights)
(5+0)%7 = 5 (night shift on call for the 4 nights)
(6+0)%7 = 6 (not on call day or night)
the next cycle, onCallCycle would be 1
the 'aNumber' for the crew would be
(0+1)%7 = 1 (day shift on call for the 4 days)
(1+1)%7 = 2 (day shift on call for the 4 days)
(2+1)%7 = 3 (night shift on call for the 4 nights)
(3+1)%7 = 4 (night shift on call for the 4 nights)
(4+1)%7 = 5 (night shift on call for the 4 nights)
(5+1)%7 = 6 (not on call day or night)
(6+1)%7 = 0 (day shift on call for the 4 days)
one more so you can see the pattern, the next cycle onCallCycle would be 2
the 'aNumber' for the crew would be
(0+2)%7 = 2 (day shift on call for the 4 days)
(1+2)%7 = 3 (night shift on call for the 4 nights)
(2+2)%7 = 4 (night shift on call for the 4 nights)
(3+2)%7 = 5 (night shift on call for the 4 nights)
(4+2)%7 = 6 (not on call day or night)
(5+2)%7 = 0 (day shift on call for the 4 days)
(6+2)%7 = 1 (day shift on call for the 4 days)
the above works in with what I'd earlier called cycleWeek (poor name choice, not a week, represents one of the 4 4-day blocks)
if the onCall crew members were not all the same for that 4 day/night period,
it would just add a bit more complexity to the above, but do-able, you'd just
need to work in the pattern of how they were determined
Thanks for your help. I started trying to apply the pattern, but in the process realized that I missed several important details.
1. After working a four shift cycle on day shift, members of crew A are on call for two day shifts. Then they are on call for two night shifts before starting to work nights, as opposed to crew A being on call for four days straight.
2. There are two categories in each crew: senior employees and junior employees. Three senior employees are on call for the first two days off, then three junior employees are on call for the last two nights off (if crew A previously worked days). There are four senior employees who are rotated, giving one senior employee a "day off", while the junior employees are always on call the third and fourth days or nights off.
3. There is a separate category of employees who are on call the first day off and the last night off. There are two employees per crew in this category and both are on call the first and last days off.
Once again, I can't begin to say how much appreciate your help. When I started working on this project, I didn't realize how complicated it would become. I started learning Java in January and I honestly feel a bit over my head trying to tackle this.
Joined: Jun 09, 2003
(1) and (2) would be easy enough to implement, along the lines of earlier posts,
just a matter of working out the rotaion cycle (if any) of the senior members, and
adding variables to indicate whether senior or junior.
not sure about (3), are they an entirely different crew? if so, that should be easy
enough as their days/nights seem fixed.