def dummy_organization(scope="function"): c1 = BaseTeam("c1") w11 = BaseWorker("w11", cost_per_time=10.0) w12 = BaseWorker("w12", cost_per_time=5.0) w11.start_time_list = [0, 5] w11.finish_time_list = [2, 8] w12.start_time_list = [9] w12.finish_time_list = [11] c1.worker_list = [w11, w12] c2 = BaseTeam("c2") w2 = BaseWorker("w2", cost_per_time=5.0) w2.start_time_list = [9] w2.finish_time_list = [11] c2.worker_list = [w2] c2.parent_team = c1 f = BaseFacility("f", cost_per_time=20.0) f.start_time_list = [9] f.finish_time_list = [11] factory = BaseFactory("factory", facility_list=[f]) dummy_factory = BaseFactory("dummy") factory.parent_factory = dummy_factory organization = BaseOrganization(team_list=[c1, c2], factory_list=[factory, dummy_factory]) return organization
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 test_create_data_for_cost_history_plotly(): team = BaseTeam("team") w1 = BaseResource("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseResource("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] team.worker_list = [w1, w2] team.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list))) init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) data = team.create_data_for_cost_history_plotly(init_datetime, timedelta) x = [ (init_datetime + time * timedelta).strftime("%Y-%m-%d %H:%M:%S") for time in range(len(team.cost_list)) ] # w1 assert data[0].name == w1.name assert data[0].x == tuple(x) assert data[0].y == tuple(w1.cost_list) # w2 assert data[1].name == w2.name assert data[1].x == tuple(x) assert data[1].y == tuple(w2.cost_list)
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_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 test_get_worker_list(): """test_get_worker_list.""" # TODO if we have enough time for setting test case... team = BaseTeam("team") w1 = BaseWorker("w1", cost_per_time=10.0) w2 = BaseWorker("w2", cost_per_time=5.0) team.worker_list = [w2, w1] assert ( len( team.get_worker_list( name="test", ID="test", team_id="test", cost_per_time=99876, solo_working=True, workamount_skill_mean_map={}, workamount_skill_sd_map=[], facility_skill_map={}, state=BaseWorkerState.WORKING, cost_list=[], assigned_task_list=[], assigned_task_id_record=[], ) ) == 0 )
def test_create_cost_history_plotly(): team = BaseTeam("team") w1 = BaseResource("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseResource("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] team.worker_list = [w1, w2] team.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list))) init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) team.create_cost_history_plotly(init_datetime, timedelta) team.create_cost_history_plotly(init_datetime, timedelta, title="bbbbbbb")
def test_initialize(): """test_initialize.""" team = BaseTeam("team") team.cost_list = [9.0, 7.2] w = BaseWorker("w1") team.worker_list = [w] w.state = BaseWorkerState.WORKING w.cost_list = [9.0, 7.2] w.assigned_task_list = [BaseTask("task")] team.initialize() assert team.cost_list == [] assert w.state == BaseWorkerState.FREE assert w.cost_list == [] assert w.assigned_task_list == []
def test_add_labor_cost(): team = BaseTeam("team") w1 = BaseResource("w1", cost_per_time=10.0) w2 = BaseResource("w2", cost_per_time=5.0) team.worker_list = [w2, w1] w1.state = BaseResourceState.WORKING w2.state = BaseResourceState.FREE team.add_labor_cost() assert w1.cost_list == [10.0] assert w2.cost_list == [0.0] assert team.cost_list == [10.0] team.add_labor_cost(only_working=False) assert team.cost_list == [10.0, 15.0] assert w1.cost_list == [10.0, 10.0] assert w2.cost_list == [0.0, 5.0]
def test_create_gantt_plotly(): team = BaseTeam("team") w1 = BaseResource("w1", cost_per_time=10.0) w1.start_time_list = [0, 5] w1.finish_time_list = [2, 8] w2 = BaseResource("w2", cost_per_time=5.0) w2.start_time_list = [9] w2.finish_time_list = [11] 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) # not yet implemented team.create_gantt_plotly(init_datetime, timedelta, save_fig_path="test.png")
def test_initialize(): team = BaseTeam("team") team.cost_list = [9.0, 7.2] w = BaseResource("w1") team.worker_list = [w] w.state = BaseResourceState.WORKING w.cost_list = [9.0, 7.2] w.start_time_list = [0] w.finish_time_list = [1] w.assigned_task_list = [BaseTask("task")] team.initialize() assert team.cost_list == [] assert w.state == BaseResourceState.FREE assert w.cost_list == [] assert w.start_time_list == [] assert w.finish_time_list == [] assert w.assigned_task_list == []
def test_create_cost_history_plotly(tmpdir): """test_create_cost_history_plotly.""" team = BaseTeam("team") w1 = BaseWorker("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseWorker("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] team.worker_list = [w1, w2] team.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list))) init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) team.create_cost_history_plotly(init_datetime, timedelta) for ext in ["png", "html", "json"]: save_fig_path = os.path.join(str(tmpdir), "test." + ext) team.create_cost_history_plotly( init_datetime, timedelta, title="bbbbbbb", save_fig_path=save_fig_path )
def test_create_data_for_gantt_plotly(): team = BaseTeam("team") w1 = BaseResource("w1", cost_per_time=10.0) w1.start_time_list = [0, 5] w1.finish_time_list = [2, 8] w2 = BaseResource("w2", cost_per_time=5.0) w2.start_time_list = [9] w2.finish_time_list = [11] team.worker_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) df = team.create_data_for_gantt_plotly(init_datetime, timedelta) # w1 part1 assert df[0]["Task"] == team.name + ": " + w1.name assert df[0]["Start"] == ( init_datetime + w1.start_time_list[0] * timedelta ).strftime("%Y-%m-%d %H:%M:%S") assert df[0]["Finish"] == ( init_datetime + (w1.finish_time_list[0] + 1.0) * timedelta ).strftime("%Y-%m-%d %H:%M:%S") assert df[0]["Type"] == "Worker" # w1 part2 assert df[1]["Task"] == team.name + ": " + w1.name assert df[1]["Start"] == ( init_datetime + w1.start_time_list[1] * timedelta ).strftime("%Y-%m-%d %H:%M:%S") assert df[1]["Finish"] == ( init_datetime + (w1.finish_time_list[1] + 1.0) * timedelta ).strftime("%Y-%m-%d %H:%M:%S") assert df[1]["Type"] == "Worker" # w2 assert df[2]["Start"] == ( init_datetime + w2.start_time_list[0] * timedelta ).strftime("%Y-%m-%d %H:%M:%S") assert df[2]["Finish"] == ( init_datetime + (w2.finish_time_list[0] + 1.0) * timedelta ).strftime("%Y-%m-%d %H:%M:%S") assert df[2]["Type"] == "Worker"
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()