Esempio n. 1
0
def test_initialize():
    """test_initialize."""
    c1 = Component("c1")
    c1.error = 4.0
    product = Product([c1])
    product.initialize()
    assert c1.error == 0.0
Esempio n. 2
0
def test_create_gantt_plotly():
    c1 = Component("c1")
    task11 = Task("task11")
    task12 = Task("task12")
    c1.extend_targeted_task_list([task11, task12])
    c2 = Component("c2")
    task2 = Task("task2")
    c2.append_targeted_task(task2)
    product = Product([c1, c2])

    # Set test case
    task11.start_time_list = [0, 2]
    task11.ready_time_list = [0, 2]
    task11.finish_time_list = [3, 5]
    task12.start_time_list = [1]
    task12.ready_time_list = [2]
    task12.finish_time_list = [5]
    task2.start_time_list = [1]
    task2.ready_time_list = [2]
    task2.finish_time_list = [5]

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    product.create_gantt_plotly(init_datetime, timedelta, save_fig_path="test.png")
    if os.path.exists("test.png"):
        os.remove("test.png")
Esempio n. 3
0
def test_get_node_and_edge_trace_for_plotly_network():
    c1 = Component("c1")
    c2 = Component("c2")
    c3 = Component("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = Product([c3, c2, c1])
    node_trace, edge_trace = product.get_node_and_edge_trace_for_plotly_network()
Esempio n. 4
0
def test_get_networkx_graph():
    c1 = Component("c1")
    c2 = Component("c2")
    c3 = Component("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = Product([c3, c2, c1])
    product.get_networkx_graph()
Esempio n. 5
0
def test_draw_networkx(tmpdir):
    """test_draw_networkx."""
    c1 = Component("c1")
    c2 = Component("c2")
    c3 = Component("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = Product([c3, c2, c1])
    product.draw_networkx(save_fig_path=os.path.join(str(tmpdir), "test.png"))
Esempio n. 6
0
def test_draw_plotly_network():
    c1 = Component("c1")
    c2 = Component("c2")
    c3 = Component("c3")
    c2.parent_component_list = [c1]
    c2.child_component_list = [c3]
    product = Product([c3, c2, c1])
    product.draw_plotly_network(save_fig_path="test.png")
    if os.path.exists("test.png"):
        os.remove("test.png")
Esempio n. 7
0
def test_create_data_for_gantt_plotly():
    """test_create_data_for_gantt_plotly."""
    c1 = Component("c1")
    c1.state_record_list = [
        BaseComponentState.WORKING,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
    ]
    product = Product([c1])
    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    product.create_data_for_gantt_plotly(init_datetime, timedelta)
Esempio n. 8
0
def test_plot_simple_gantt(tmpdir):
    """test_plot_simple_gantt."""
    c1 = Component("c1")
    c1.state_record_list = [
        BaseComponentState.WORKING,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
        BaseComponentState.FINISHED,
    ]
    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    c1.create_data_for_gantt_plotly(init_datetime, timedelta)
    product = Product([c1])
    product.plot_simple_gantt(
        save_fig_path=os.path.join(str(tmpdir), "test.png"))
Esempio n. 9
0
def test_create_data_for_gantt_plotly():
    c1 = Component("c1")
    task11 = Task("task11")
    task12 = Task("task12")
    c1.extend_targeted_task_list([task11, task12])
    c2 = Component("c2")
    task2 = Task("task2")
    c2.append_targeted_task(task2)
    product = Product([c1, c2])

    # Set test case
    task11.start_time_list = [0, 2]
    task11.ready_time_list = [0, 2]
    task11.finish_time_list = [3, 5]
    task12.start_time_list = [1]
    task12.ready_time_list = [2]
    task12.finish_time_list = [5]
    task2.start_time_list = [1]
    task2.ready_time_list = [2]
    task2.finish_time_list = [5]

    init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0)
    timedelta = datetime.timedelta(days=1)
    df = product.create_data_for_gantt_plotly(init_datetime, timedelta)
    assert df[0]["Start"] == (init_datetime + 0 * timedelta).strftime(
        "%Y-%m-%d %H:%M:%S"
    )
    assert df[0]["Finish"] == (init_datetime + (5 + 1.0) * timedelta).strftime(
        "%Y-%m-%d %H:%M:%S"
    )
    assert df[0]["Type"] == "Component"
    assert df[1]["Start"] == (init_datetime + 1 * timedelta).strftime(
        "%Y-%m-%d %H:%M:%S"
    )
    assert df[1]["Finish"] == (init_datetime + (5 + 1.0) * timedelta).strftime(
        "%Y-%m-%d %H:%M:%S"
    )
    assert df[1]["Type"] == "Component"
Esempio n. 10
0
def test_create_simple_gantt():
    c1 = Component("c1")
    task11 = Task("task11")
    task12 = Task("task12")
    c1.extend_targeted_task_list([task11, task12])
    c2 = Component("c2")
    task2 = Task("task2")
    c2.append_targeted_task(task2)
    product = Product([c1, c2])

    # Set test case
    task11.start_time_list = [1, 5]
    task11.ready_time_list = [0, 4]
    task11.finish_time_list = [2, 6]
    task12.start_time_list = [2]
    task12.ready_time_list = [1]
    task12.finish_time_list = [5]
    task2.start_time_list = [2]
    task2.ready_time_list = [1]
    task2.finish_time_list = [5]

    product.create_simple_gantt(save_fig_path="test.png")
    if os.path.exists("test.png"):
        os.remove("test.png")
Esempio n. 11
0
def dummy_project(scope="function"):
    """dummy_project."""
    # Components in Product
    c3 = Component("c3")
    c1 = Component("c1")
    c2 = Component("c2")
    c3.extend_child_component_list([c1, c2])

    # Tasks in Workflow
    task1_1 = Task("task1_1", need_facility=True)
    task1_2 = Task("task1_2")
    task2_1 = Task("task2_1")
    task3 = Task("task3")
    task3.extend_input_task_list([task1_2, task2_1])
    task1_2.append_input_task(task1_1)

    c1.extend_targeted_task_list([task1_1, task1_2])
    c2.append_targeted_task(task2_1)
    c3.append_targeted_task(task3)

    # Facilities in workplace
    f1 = BaseFacility("f1")
    f1.workamount_skill_mean_map = {
        task1_1.name: 1.0,
    }
    # workplace.facility_list.append(f1)

    # Workplace in BaseOrganization
    workplace = BaseWorkplace("workplace", facility_list=[f1])
    workplace.extend_targeted_task_list([task1_1, task1_2, task2_1, task3])

    # Teams in Organization
    team = Team("team")
    team.extend_targeted_task_list([task1_1, task1_2, task2_1, task3])

    # Workers in each Team
    w1 = Worker("w1", team_id=team.ID, cost_per_time=10.0)
    w1.workamount_skill_mean_map = {
        task1_1.name: 1.0,
        task1_2.name: 1.0,
        task2_1.name: 0.0,
        task3.name: 1.0,
    }
    w1.facility_skill_map = {f1.name: 1.0}
    team.worker_list.append(w1)

    w2 = Worker("w2", team_id=team.ID, cost_per_time=6.0)
    w2.workamount_skill_mean_map = {
        task1_1.name: 1.0,
        task1_2.name: 0.0,
        task2_1.name: 1.0,
        task3.name: 1.0,
    }
    w2.facility_skill_map = {f1.name: 1.0}
    team.worker_list.append(w2)

    # Project including Product, Workflow and Organization
    project = Project(
        init_datetime=datetime.datetime(2020, 4, 1, 8, 0, 0),
        unit_timedelta=datetime.timedelta(days=1),
    )
    project.product = Product([c3, c1, c2])
    project.workflow = Workflow([task1_1, task1_2, task2_1, task3])
    project.organization = Organization(team_list=[team],
                                        workplace_list=[workplace])
    return project
Esempio n. 12
0
def test_str():
    print(Product([]))
Esempio n. 13
0
def test_init():
    c1 = Component("c1")
    product = Product([c1])
    assert product.component_list == [c1]
Esempio n. 14
0
def test_str():
    """test_str."""
    print(Product([]))