def test_create_gantt_plotly(tmpdir): """test_create_gantt_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] w2 = BaseFacility("w2", cost_per_time=5.0) w2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace.facility_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) workplace.create_gantt_plotly( init_datetime, timedelta, save_fig_path=os.path.join(str(tmpdir), "test.png") ) for ext in ["png", "html", "json"]: save_fig_path = os.path.join(str(tmpdir), "test." + ext) workplace.create_gantt_plotly( init_datetime, timedelta, save_fig_path=save_fig_path )
def test_create_data_for_cost_history_plotly(): """test_create_data_for_cost_history_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseFacility("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] workplace.facility_list = [w1, w2] workplace.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 = workplace.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(workplace.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_data_for_gantt_plotly(): """test_create_data_for_gantt_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] w2 = BaseFacility("w2", cost_per_time=5.0) w2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace.facility_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) workplace.create_data_for_gantt_plotly(init_datetime, timedelta)
def test_get_facility_list(): """test_get_facility_list.""" # TODO if we have enough time for setting test case... workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w2 = BaseFacility("w2", cost_per_time=5.0) workplace.facility_list = [w2, w1] assert ( len( workplace.get_facility_list( name="test", ID="test", workplace_id="test", cost_per_time=99876, solo_working=True, workamount_skill_mean_map={}, workamount_skill_sd_map=[], state=BaseFacilityState.WORKING, cost_list=[], assigned_task_list=[], assigned_task_id_record=[], ) ) == 0 )
def test_initialize(): """test_initialize.""" workplace = BaseWorkplace("workplace") workplace.cost_list = [9.0, 7.2] w = BaseFacility("w1") workplace.facility_list = [w] w.state = BaseFacilityState.WORKING w.cost_list = [9.0, 7.2] w.assigned_task_list = [BaseTask("task")] workplace.initialize() assert workplace.cost_list == [] assert w.state == BaseFacilityState.FREE assert w.cost_list == [] assert w.assigned_task_list == []
def test_add_labor_cost(): """test_add_labor_cost.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w2 = BaseFacility("w2", cost_per_time=5.0) workplace.facility_list = [w2, w1] w1.state = BaseFacilityState.WORKING w2.state = BaseFacilityState.FREE workplace.add_labor_cost() assert w1.cost_list == [10.0] assert w2.cost_list == [0.0] assert workplace.cost_list == [10.0] workplace.add_labor_cost(only_working=False) assert workplace.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_cost_history_plotly(tmpdir): """test_create_cost_history_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseFacility("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] workplace.facility_list = [w1, w2] workplace.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) workplace.create_cost_history_plotly(init_datetime, timedelta) for ext in ["png", "html", "json"]: save_fig_path = os.path.join(str(tmpdir), "test." + ext) workplace.create_cost_history_plotly( init_datetime, timedelta, title="bbbbbbb", save_fig_path=save_fig_path ) if os.path.exists(save_fig_path): os.remove(save_fig_path)
def test_plot_simple_gantt(): """test_plot_simple_gantt.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] w2 = BaseFacility("w2", cost_per_time=5.0) w2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace.facility_list = [w1, w2] workplace.plot_simple_gantt()