def clnd_variable_mins(workshift_ref=None): if workshift_ref is None: workshift_ref = 'start' halfhours = tb.Organizer('30T', structure=[0, 1]) splitter = tb.Organizer(marks=[ '01 Oct 2017 03:05', '01 Oct 2017 06:05', '01 Oct 2017 09:05', '01 Oct 2017 12:05' ], structure=[0, halfhours, 0, halfhours, 0]) return tb.Timeboard('T', '01 Oct 2017', '01 Oct 2017 14:59', layout=splitter, workshift_ref=workshift_ref)
def test_tb_constructor_week5x8(self): week5x8 = tb.Organizer(marker='W', structure=[[1, 1, 1, 1, 1, 0, 0]]) amendments = pd.Series(index=pd.date_range(start='01 Jan 2017', end='10 Jan 2017', freq='D'), data=0).to_dict() clnd = tb.Timeboard(base_unit_freq='D', start='28 Dec 2016', end='02 Apr 2017', layout=week5x8, amendments=amendments) assert clnd.start_time == datetime.datetime(2016, 12, 28, 0, 0, 0) assert clnd.end_time > datetime.datetime(2017, 4, 2, 23, 59, 59) assert clnd.end_time < datetime.datetime(2017, 4, 3, 0, 0, 0) assert clnd.base_unit_freq == 'D' assert clnd('28 Dec 2016').is_on_duty() assert clnd('30 Dec 2016').is_on_duty() assert clnd('31 Dec 2016').is_off_duty() assert clnd('01 Jan 2017').is_off_duty() assert clnd('10 Jan 2017').is_off_duty() assert clnd('11 Jan 2017').is_on_duty() assert clnd('27 Mar 2017').is_on_duty() assert clnd('31 Mar 2017').is_on_duty() assert clnd('01 Apr 2017').is_off_duty() assert clnd('02 Apr 2017').is_off_duty()
def tb_10_8_6_hours(workshift_ref='start', worktime_source='duration'): shifts = tb.Marker(each='D', at=[{'hours': 2}, {'hours': 8}, {'hours': 18}]) daily = tb.Organizer(marker=shifts, structure=[1, 0]) return tb.Timeboard(base_unit_freq='H', start='01 Oct 2017', end='06 Oct 2017', layout=daily, workshift_ref=workshift_ref, worktime_source=worktime_source)
def tb_281116_020517_8x5(): week5x8 = tb.Organizer(marker='W', structure=[[1, 1, 1, 1, 1, 0, 0]]) amendments = pd.Series(index=pd.date_range(start='01 Jan 2017', end='10 Jan 2017', freq='D'), data=0).to_dict() return tb.Timeboard(base_unit_freq='D', start='28 Nov 2016', end='02 May 2017', layout=week5x8, amendments=amendments)
def test_interval_constructor_period_straddles_2_ws(self): shifts = tb.Organizer(marker='90T', structure=[0, 1, 0, 2]) clnd = tb.Timeboard( base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, ) # period straddles ws 0 and 1 # but only ref time of ws 1 falls into the period ivl = clnd.get_interval('04 Oct 2017 01:00', period='H') assert ivl._loc == (1, 1)
def test_interval_d_count_periods_m_with_gap(self): week5x8 = tb.Organizer(marker='W', structure=[[1, 1, 1, 1, 1, 0, 0]]) amendments = pd.Series(index=pd.date_range(start='01 Feb 2017', end='28 Feb 2017', freq='D'), data=0).to_dict() clnd = tb.Timeboard(base_unit_freq='D', start='28 Nov 2016', end='02 May 2017', layout=week5x8, amendments=amendments) ivl = clnd.get_interval(('29 Dec 2016', '01 Apr 2017')) # in February all days are off -> Feb does not count when duty='on' assert ivl.count_periods('M') == 2.0 / 22.0 + 2.0 assert ivl.count_periods('M', duty='off') == 1.0 / 9.0 + 3.0 + 1.0 / 10.0 assert ivl.count_periods('M', duty='any') == 3.0 / 31.0 + 3.0 + 1.0 / 30.0
def test_interval_constructor_period_start_aligned_end_inside_ws(self): shifts = tb.Organizer(marker='90T', structure=[0, 1, 0, 2]) clnd = tb.Timeboard( base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, ) # period (00:00 - 00:59) is inside ws 0 (00:00 - 01:29) # ref time of ws 0 falls into the period ivl = clnd.get_interval('04 Oct 2017 00:00', period='H') assert ivl._loc == (0, 0) # now ref time is end time and ws 0 ref time is outside the period clnd = tb.Timeboard(base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, workshift_ref='end') with pytest.raises(VoidIntervalError): clnd.get_interval('04 Oct 2017 00:00', period='H')
def test_interval_constructor_period_entirely_inside_ws(self): shifts = tb.Organizer(marker='3H', structure=[0, 1, 0, 2]) clnd = tb.Timeboard( base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, ) # period (04:00 - 04:59) is inside workshift (03:00 - 05:59) # and does not includes workshift's start or end times. # No matter if the ref time is 'start' or 'end', # it is outside the period with pytest.raises(VoidIntervalError): clnd.get_interval('04 Oct 2017 04:00', period='H') clnd = tb.Timeboard(base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, workshift_ref='end') with pytest.raises(VoidIntervalError): clnd.get_interval('04 Oct 2017 04:00', period='H')
def test_interval_constructor_period_begin_inside_ws_end_aligned(self): shifts = tb.Organizer(marker='90T', structure=[0, 1, 0, 2]) clnd = tb.Timeboard( base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, ) # period (02:00 - 02:59) is inside ws 1 (01:30 - 02:59) # ref time of ws 1 is outside the period with pytest.raises(VoidIntervalError): clnd.get_interval('04 Oct 2017 02:00', period='H') # now ref time is end time and ws 1 ref time is within the period clnd = tb.Timeboard(base_unit_freq='T', start='04 Oct 2017', end='04 Oct 2017 23:59', layout=shifts, workshift_ref='end') ivl = clnd.get_interval('04 Oct 2017 02:00', period='H') assert ivl._loc == (1, 1)