def test_create_gantt_plotly(tmpdir): """test_create_gantt_plotly.""" team = BaseTeam("team") w1 = BaseWorker("w1", cost_per_time=10.0) w1.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] w2 = BaseWorker("w2", cost_per_time=5.0) w2.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] team.worker_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) team.create_gantt_plotly(init_datetime, timedelta) for ext in ["png", "html", "json"]: save_fig_path = os.path.join(str(tmpdir), "test." + ext) team.create_gantt_plotly(init_datetime, timedelta, save_fig_path=save_fig_path)
def test_remove_insert_absence_time_list(): """test_remove_insert_absence_time_list.""" w1 = BaseWorker("w1", "----") w1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] w1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] w1.state_record_list = [2, 1, 2, 1, 1, 2] w2 = BaseWorker("w1", "----") w2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] w2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] w2.state_record_list = [2, 1, 2, 1, 1, 2] team = BaseTeam("aa", worker_list=[w1, w2]) team.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] absence_time_list = [1, 3, 4] team.remove_absence_time_list(absence_time_list) assert team.cost_list == [2.0, 2.0, 2.0] assert w1.cost_list == [1.0, 1.0, 1.0] assert w1.assigned_task_id_record == ["aa", "cc", "ff"] assert w1.state_record_list == [2, 2, 2] assert w2.cost_list == [1.0, 1.0, 1.0] assert w2.assigned_task_id_record == ["aa", "cc", "ff"] assert w2.state_record_list == [2, 2, 2] team.insert_absence_time_list(absence_time_list) assert team.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] assert w1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert w1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert w1.state_record_list == [2, 0, 2, 0, 0, 2] assert w2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert w2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert w2.state_record_list == [2, 0, 2, 0, 0, 2]
def test_create_data_for_gantt_plotly(): """test_create_data_for_gantt_plotly.""" team = BaseTeam("team") w1 = BaseWorker("w1", cost_per_time=10.0) w1.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] w2 = BaseWorker("w2", cost_per_time=5.0) w2.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] team.worker_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) team.create_data_for_gantt_plotly(init_datetime, timedelta)
def dummy_organization(scope="function"): """dummy_organization.""" c1 = BaseTeam("c1") w11 = BaseWorker("w11", cost_per_time=10.0) w12 = BaseWorker("w12", cost_per_time=5.0) w11.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] w12.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] c1.worker_list = [w11, w12] c2 = BaseTeam("c2") w2 = BaseWorker("w2", cost_per_time=5.0) w2.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] c2.worker_list = [w2] c2.parent_team = c1 f = BaseFacility("f", cost_per_time=20.0) f.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace = BaseWorkplace("workplace", facility_list=[f]) dummy_workplace = BaseWorkplace("dummy") workplace.parent_workplace = dummy_workplace organization = BaseOrganization( team_list=[c1, c2], workplace_list=[workplace, dummy_workplace]) return organization
def dummy_team_for_extracting(scope="function"): """dummy_team_for_extracting.""" worker1 = BaseWorker("worker1") worker1.state_record_list = [ BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.FREE, ] worker2 = BaseWorker("worker2") worker2.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.WORKING, ] worker3 = BaseWorker("worker3") worker3.state_record_list = [ BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] worker4 = BaseWorker("worker4") worker4.state_record_list = [ BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, ] worker5 = BaseWorker("worker5") worker5.state_record_list = [ BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.WORKING, ] return BaseTeam("test", worker_list=[worker1, worker2, worker3, worker4, worker5])
def test_get_time_list_for_gannt_chart(): w = BaseWorker("w1", "----") w.state_record_list = [ BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.WORKING, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [(0, 2)] assert working_time_list == [(2, 1)] w.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [(2, 1)] assert working_time_list == [(0, 2)] w.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.WORKING, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [] assert working_time_list == [(0, 3)] # for backward w.state_record_list = [ BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.FREE, BaseWorkerState.WORKING, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [(0, 1), (4, 3)] assert working_time_list == [(1, 3), (7, 1)]
def test_plot_simple_gantt(): """test_plot_simple_gantt.""" team = BaseTeam("team") w1 = BaseWorker("w1", cost_per_time=10.0) w1.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] w2 = BaseWorker("w2", cost_per_time=5.0) w2.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] team.worker_list = [w1, w2] team.plot_simple_gantt()
def test_remove_insert_absence_time_list(): """test_remove_insert_absence_time_list.""" w = BaseWorker("w1", "----") w.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] w.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] w.state_record_list = [2, 1, 2, 1, 1, 2] absence_time_list = [1, 3, 4] w.remove_absence_time_list(absence_time_list) assert w.cost_list == [1.0, 1.0, 1.0] assert w.assigned_task_id_record == ["aa", "cc", "ff"] assert w.state_record_list == [2, 2, 2] w.insert_absence_time_list(absence_time_list) assert w.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert w.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert w.state_record_list == [2, 0, 2, 0, 0, 2]
def test_remove_insert_absence_time_list(): """test_remove_insert_absence_time_list.""" f1 = BaseFacility("w1", "----") f1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] f1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] f1.state_record_list = [2, 1, 2, 1, 1, 2] f2 = BaseFacility("w1", "----") f2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] f2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] f2.state_record_list = [2, 1, 2, 1, 1, 2] workplace = BaseWorkplace("aa", facility_list=[f1, f2]) workplace.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] w1 = BaseWorker("w1", "----") w1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] w1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] w1.state_record_list = [2, 1, 2, 1, 1, 2] w2 = BaseWorker("w1", "----") w2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] w2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] w2.state_record_list = [2, 1, 2, 1, 1, 2] team = BaseTeam("aa", worker_list=[w1, w2]) team.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] organization = BaseOrganization(team_list=[team], workplace_list=[workplace]) organization.cost_list = [4.0, 0.0, 4.0, 0.0, 0.0, 4.0] absence_time_list = [1, 3, 4] organization.remove_absence_time_list(absence_time_list) assert organization.cost_list == [4.0, 4.0, 4.0] assert workplace.cost_list == [2.0, 2.0, 2.0] assert f1.cost_list == [1.0, 1.0, 1.0] assert f1.assigned_task_id_record == ["aa", "cc", "ff"] assert f1.state_record_list == [2, 2, 2] assert f2.cost_list == [1.0, 1.0, 1.0] assert f2.assigned_task_id_record == ["aa", "cc", "ff"] assert f2.state_record_list == [2, 2, 2] assert team.cost_list == [2.0, 2.0, 2.0] assert w1.cost_list == [1.0, 1.0, 1.0] assert w1.assigned_task_id_record == ["aa", "cc", "ff"] assert w1.state_record_list == [2, 2, 2] assert w2.cost_list == [1.0, 1.0, 1.0] assert w2.assigned_task_id_record == ["aa", "cc", "ff"] assert w2.state_record_list == [2, 2, 2] organization.insert_absence_time_list(absence_time_list) assert organization.cost_list == [4.0, 0.0, 4.0, 0.0, 0.0, 4.0] assert team.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] assert w1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert w1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert w1.state_record_list == [2, 0, 2, 0, 0, 2] assert w2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert w2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert w2.state_record_list == [2, 0, 2, 0, 0, 2] assert workplace.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] assert f1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert f1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert f1.state_record_list == [2, 0, 2, 0, 0, 2] assert f2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert f2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert f2.state_record_list == [2, 0, 2, 0, 0, 2]