Пример #1
0
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)
Пример #2
0
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]

    absence_time_list = [1, 3, 4]
    workplace.remove_absence_time_list(absence_time_list)
    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]

    workplace.insert_absence_time_list(absence_time_list)
    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]
Пример #3
0
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")
Пример #4
0
def test_initialize():
    """test_initialize."""
    team = BaseWorkplace("team")
    w = BaseFacility("w1", workplace_id=team.ID)
    w.state = BaseFacilityState.WORKING
    w.cost_list = [9.0, 7.2]
    w.assigned_task_list = [BaseTask("task")]
    w.initialize()
    assert w.state == BaseFacilityState.FREE
    assert w.cost_list == []
    assert w.assigned_task_list == []
Пример #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)
Пример #6
0
def test_initialize():
    team = BaseFactory("team")
    w = BaseFacility("w1", factory_id=team.ID)
    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")]
    w.initialize()
    assert w.state == BaseFacilityState.FREE
    assert w.cost_list == []
    assert w.start_time_list == []
    assert w.finish_time_list == []
    assert w.assigned_task_list == []
Пример #7
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 == []
Пример #8
0
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 == []
Пример #9
0
def test_remove_insert_absence_time_list():
    """test_remove_insert_absence_time_list."""
    w = BaseFacility("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 = [0, 1, 4]
    w.remove_absence_time_list(absence_time_list)
    assert w.cost_list == [1.0, 0.0, 1.0]
    assert w.assigned_task_id_record == ["cc", "dd", "ff"]
    assert w.state_record_list == [2, 1, 2]

    w.insert_absence_time_list(absence_time_list)
    assert w.cost_list == [0.0, 0.0, 1.0, 0.0, 0.0, 1.0]
    assert w.assigned_task_id_record == [None, None, "cc", "dd", "dd", "ff"]
    assert w.state_record_list == [
        BaseFacilityState.FREE,
        BaseFacilityState.FREE,
        2,
        1,
        BaseFacilityState.FREE,
        2,
    ]
Пример #10
0
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]