Created
June 13, 2016 22:04
-
-
Save cswalina/b53060150e94e7d642c4935988304c92 to your computer and use it in GitHub Desktop.
How we might generate work sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rotation | |
has_many :shift_cycles | |
def template | |
# given some shift_cycles: | |
#-------------------------------+ | |
# days_on | days_off | shift_id | | |
#-------------------------------+ | |
# 3 | 1 | 5 | |
# 2 | 1 | 6 | |
# | |
# This method should return: | |
# [ | |
# [T,5], | |
# [T,5], | |
# [T,5], | |
# [F,5], | |
# [T,6], | |
# [T,6], | |
# [F,6] | |
# ] | |
end | |
def template_index(date) | |
( self.starts_on - date ).to_i.abs % template.length | |
end | |
# Given a date: | |
# working? => template[template_index(date)][0] (T or F) | |
# shift_id => template[template_index(date)][1] ( 5 or 6 ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment