def test_create_data_for_cost_history_plotly(): factory = BaseFactory("factory") 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] factory.facility_list = [w1, w2] factory.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 = factory.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(factory.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_initialize(): factory = BaseFactory("factory") factory.cost_list = [9.0, 7.2] w = BaseFacility("w1") factory.facility_list = [w] w.state = BaseFacilityState.WORKING w.cost_list = [9.0, 7.2] w.start_time_list = [0] w.finish_time_list = [1] w.assigned_task_list = [BaseTask("task")] factory.initialize() assert factory.cost_list == [] assert w.state == BaseFacilityState.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(): factory = BaseFactory("factory") 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] factory.facility_list = [w1, w2] factory.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) factory.create_cost_history_plotly(init_datetime, timedelta) factory.create_cost_history_plotly(init_datetime, timedelta, title="bbbbbbb", save_fig_path="test.png") if os.path.exists("test.png"): os.remove("test.png")