Esempio n. 1
0
 def test_ivl_compound_count_periods_many_straddle_both_ends_duty_off(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (3, 12))
     assert ivl.count_periods('D', duty='off') == 1.0 / 2.0 + 3.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (3, 12))
     assert ivl.count_periods('D', duty='off') == 3.0
Esempio n. 2
0
 def test_ivl_compound_count_periods_many_float_both_duty_any(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (7, 14))
     assert ivl.count_periods('D', duty='any') == 2.0 + 2.0 / 3.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (7, 14))
     assert ivl.count_periods('D', duty='any') == 2.0 + 2.0 / 3.0
Esempio n. 3
0
 def test_ivl_compound_count_periods_straddle_float_right_duty_off(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (7, 9))
     assert ivl.count_periods('D', duty='off') == 1.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (7, 9))
     assert ivl.count_periods('D', duty='off') == 1.0 + 1.0 / 2.0
Esempio n. 4
0
 def test_ivl_compound_count_periods_one_float_left_duty_on(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (7, 8))
     assert ivl.count_periods('D') == 1.0 / 1.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (7, 8))
     assert ivl.count_periods('D') == 1.0 / 2.0
Esempio n. 5
0
 def test_ivl_compound_count_periods_many_float_right_duty_off(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (7, 14))
     assert ivl.count_periods('D', duty='off') == 2.5
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (7, 14))
     assert ivl.count_periods('D', duty='off') == 3.0
Esempio n. 6
0
 def test_ivl_compound_count_periods_one_float_right_duty_any(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (1, 2))
     assert ivl.count_periods('D', duty='any') == 2.0 / 4.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (1, 2))
     assert ivl.count_periods('D', duty='any') == 2.0 / 3.0
Esempio n. 7
0
 def test_ivl_compound_count_periods_OOB_floating(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (14, 15))
     assert ivl.count_periods('D', duty='off') == 1.0 / 2.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     ivl = Interval(clnd, (14, 15))
     with pytest.raises(PartialOutOfBoundsError):
         ivl.count_periods('D', duty='off')
Esempio n. 8
0
 def test_ivl_compound_count_periods_one_float_right_duty_on(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (4, 5))
     assert ivl.count_periods('D') == 1.0 / 2.0
     clnd = tb_10_8_6_hours(workshift_ref='end')
     assert clnd._timeline._workshift_ref == 'end'
     ivl = Interval(clnd, (4, 5))
     assert ivl.count_periods('D') == 1.0
Esempio n. 9
0
 def test_ivl_count_periods_avoiding_long_ws(self):
     clnd = clnd_variable_mins()
     ivl = Interval(clnd, (1, 3))
     # ivl contains ws 1, 2, 3
     # ws 1, 2 fall into hour of 03:00; ws 3, 4 fall into hour of 04:00
     assert ivl.count_periods('H') == 1.0  # (1/1 + 0/1)
     assert ivl.count_periods('H', duty='off') == 2.0
     assert ivl.count_periods('H', duty='any') == 1.5  # (2/2 + 1/2)
Esempio n. 10
0
 def test_ivl_count_periods_long_ws_caught_by_period(self):
     clnd = clnd_variable_mins('end')
     ivl = Interval(clnd, (1, 3))
     # ivl contains ws 1, 2, 3
     # hour of 03:00 catches ws 0 as ws ref time is end time
     # ws 0 is 3 hours long but it is NOT in the interval so we don't raise
     # ws 0, 1 fall into hour of 03:00; ws 2, 3 fall into hour of 04:00
     assert ivl.count_periods('H') == 1.0  # (0/0 + 1/1)
     assert ivl.count_periods('H', duty='off') == 1.5  # (1/2 + 1/1)
     assert ivl.count_periods('H', duty='any') == 1.5  # (1/2 + 2/2)
Esempio n. 11
0
 def test_ivl_count_periods_shorter_than_ws_at_end(self):
     clnd = clnd_variable_mins()
     ivl = Interval(clnd, (12, 14))
     # 3H long ws #14 is the last in ivl
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H')
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H', duty='off')
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H', duty='any')
Esempio n. 12
0
 def test_ivl_count_periods_shorter_than_ws_at_mid(self):
     clnd = clnd_variable_mins()
     ivl = Interval(clnd, (5, 9))
     # 3H long ws #7 is in the middle of ivl
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H')
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H', duty='off')
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H', duty='any')
Esempio n. 13
0
 def test_ivl_count_periods_shorter_than_ws_at_start(self):
     clnd = clnd_variable_mins()
     ivl = Interval(clnd, (0, 3))
     # 3H long ws #0 is first in ivl
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H')
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H', duty='off')
     with pytest.raises(UnacceptablePeriodError):
         ivl.count_periods('H', duty='any')
Esempio n. 14
0
 def test_ivl_compound_count_periods_OOB(self):
     clnd = tb_10_8_6_hours()
     ivl = Interval(clnd, (0, 2))
     with pytest.raises(PartialOutOfBoundsError):
         ivl.count_periods('W')