def test_has_workamount_skill(): w = BaseResource("w1", "----") # w.set_workamount_skill_mean_map( # {"task1": 1.0, "task2": 0.0}, update_other_skill_info=True # ) w.workamount_skill_mean_map = {"task1": 1.0, "task2": 0.0} assert w.has_workamount_skill("task1") assert not w.has_workamount_skill("task2") assert not w.has_workamount_skill("task3")
def test_initialize(): team = BaseTeam("team") w = BaseResource("w1", team_id=team.ID) 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")] w.initialize() 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_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(): 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_perform(): task = BaseTask("task") task.state = BaseTaskState.WORKING w1 = BaseResource("w1") w2 = BaseResource("w2") w1.workamount_skill_mean_map = {"task": 1.0} task.allocated_worker_list = [w1, w2] w1.assigned_task_list = [task] w2.assigned_task_list = [task] c = BaseComponent("a") c.append_targeted_task(task) w = BaseWorkflow([task]) w.perform(10) assert task.remaining_work_amount == task.default_work_amount - 1.0 assert task.target_component == c
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_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_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_initialize(): task = BaseTask("task") task.est = 2.0 task.eft = 10.0 task.lst = 3.0 task.lft = 11.0 task.remaining_work_amount = 7 task.actual_work_amount = 6 task.state = BaseTaskState.FINISHED task.ready_time_list = [1] task.start_time_list = [2] task.finish_time_list = [15] task.additional_task_flag = True task.allocated_worker_list = [BaseResource("w1")] task_after1 = BaseTask("task_after1") task_after2 = BaseTask("task_after2", default_work_amount=5.0) task_after1.append_input_task(task) task_after2.append_input_task(task) w = BaseWorkflow([task, task_after1, task_after2]) w.critical_path_length = 100.0 w.initialize() assert w.critical_path_length == 20.0 assert w.task_list[0].est == 0.0 assert w.task_list[0].eft == 10.0 assert w.task_list[0].lst == 0.0 assert w.task_list[0].lft == 10.0 assert w.task_list[0].state == BaseTaskState.READY assert w.task_list[1].est == 10.0 assert w.task_list[1].eft == 20.0 assert w.task_list[1].lst == 10.0 assert w.task_list[1].lft == 20.0 assert w.task_list[1].state == BaseTaskState.NONE assert w.task_list[2].est == 10.0 assert w.task_list[2].eft == 15.0 assert w.task_list[2].lst == 15.0 assert w.task_list[2].lft == 20.0 assert w.task_list[2].state == BaseTaskState.NONE
def test_init(dummy_worker): # team = BaseTeam("team") assert dummy_worker.name == "wsss" assert dummy_worker.team_id == "---" assert dummy_worker.cost_per_time == 0.0 assert not dummy_worker.solo_working assert dummy_worker.workamount_skill_mean_map == {} assert dummy_worker.workamount_skill_sd_map == {} # assert dummy_worker.quality_skill_mean_map == {} assert dummy_worker.state == BaseResourceState.FREE assert dummy_worker.cost_list == [] assert dummy_worker.start_time_list == [] assert dummy_worker.finish_time_list == [] assert dummy_worker.assigned_task_list == [] w = BaseResource( "w1", solo_working=True, state=BaseResourceState.WORKING, cost_list=[10, 10], start_time_list=[1], finish_time_list=[2], assigned_task_list=[BaseTask("task")], assigned_task_id_record=[[], ["ss"]], ) assert w.name == "w1" assert w.team_id is None assert w.solo_working assert w.cost_per_time == 0.0 assert w.workamount_skill_mean_map == {} assert w.workamount_skill_sd_map == {} # assert w.quality_skill_mean_map == {} assert w.state == BaseResourceState.WORKING assert w.cost_list == [10, 10] assert w.start_time_list == [1] assert w.finish_time_list == [2] assert w.assigned_task_list[0].name == "task" assert w.assigned_task_id_record == [[], ["ss"]]
def test_init(): team = BaseTeam("team") assert team.name == "team" assert len(team.ID) > 0 assert team.worker_list == [] assert team.targeted_task_list == [] assert team.parent_team is None assert team.cost_list == [] team.cost_list.append(1) assert team.cost_list == [1.0] w1 = BaseResource("w1") t1 = BaseTask("task1") team1 = BaseTeam( "team1", parent_team=team, targeted_task_list=[t1], worker_list=[w1], cost_list=[10], ) assert team1.worker_list == [w1] assert team1.targeted_task_list == [t1] assert team1.parent_team == team assert team1.cost_list == [10]
def test_check_state(): task1 = BaseTask("task1") task2 = BaseTask("task2") task3 = BaseTask("task3") task4 = BaseTask("task4") task5 = BaseTask("task5") task3.extend_input_task_list([task1, task2]) task5.extend_input_task_list([task3, task4]) w = BaseWorkflow([task1, task2, task3, task4, task5]) w1 = BaseResource("w1", assigned_task_list=[task1]) # __check_ready test task1.state = BaseTaskState.FINISHED task2.state = BaseTaskState.FINISHED task3.state = BaseTaskState.NONE task4.state = BaseTaskState.NONE task5.state = BaseTaskState.NONE w.check_state(2, BaseTaskState.READY) assert task1.state == BaseTaskState.FINISHED assert task2.state == BaseTaskState.FINISHED assert task3.state == BaseTaskState.READY assert task4.state == BaseTaskState.READY assert task5.state == BaseTaskState.NONE # __check_working test task1.state = BaseTaskState.READY task2.state = BaseTaskState.READY task2.allocated_worker_list = [w1] task3.state = BaseTaskState.NONE task4.state = BaseTaskState.NONE task5.state = BaseTaskState.NONE w.check_state(2, BaseTaskState.WORKING) assert task1.state == BaseTaskState.READY assert task2.state == BaseTaskState.WORKING assert task3.state == BaseTaskState.NONE assert task4.state == BaseTaskState.NONE assert task5.state == BaseTaskState.NONE task1.state = BaseTaskState.WORKING task1.need_facility = True w2 = BaseResource("w2", assigned_task_list=[task1]) f2 = BaseFacility("f2", assigned_task_list=[task1]) task1.allocated_worker_list = [w2] task1.allocated_facility_list = [f2] w.check_state(2, BaseTaskState.WORKING) # __check_finished test task1.state = BaseTaskState.WORKING task1.allocated_worker_list = [w1] task1.remaining_work_amount = 0.0 task2.state = BaseTaskState.FINISHED task3.state = BaseTaskState.NONE task4.state = BaseTaskState.NONE task5.state = BaseTaskState.NONE w.check_state(2, BaseTaskState.FINISHED) assert task1.state == BaseTaskState.FINISHED assert task2.state == BaseTaskState.FINISHED assert task3.state == BaseTaskState.NONE assert task4.state == BaseTaskState.NONE assert task5.state == BaseTaskState.NONE
def test_str(): print(BaseResource("w1"))
def test_get_work_amount_skill_progress(): w = BaseResource("w1", "----") # w.set_workamount_skill_mean_map( # {"task1": 1.0, "task2": 0.0}, update_other_skill_info=True # ) w.workamount_skill_mean_map = {"task1": 1.0, "task2": 0.0} assert w.get_work_amount_skill_progress("task3") == 0.0 assert w.get_work_amount_skill_progress("task2") == 0.0 with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1 = BaseTask("task1") task1.state = BaseTaskState.NONE w.assigned_task_list = [task1] with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.READY with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.WORKING_ADDITIONALLY assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.FINISHED with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.WORKING assert w.get_work_amount_skill_progress("task1") == 1.0 w.workamount_skill_sd_map["task1"] = 0.1 w.get_work_amount_skill_progress("task1", seed=1234) task2 = BaseTask("task2") task2.state = BaseTaskState.NONE w.assigned_task_list.append(task2) w.workamount_skill_sd_map["task1"] = 0.0 assert w.get_work_amount_skill_progress("task1") == 1.0 task2.state = BaseTaskState.WORKING assert w.get_work_amount_skill_progress("task1") == 0.5
def dummy_worker(): w = BaseResource("wsss", team_id="---") return w