def test_simple_haus_kabel():
    haus = Haus()
    yaml = simple_haus.define_testcase()

    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    read_kabel(haus, yaml["kabel"])
    autogenerate_kabel(haus)
    create_nodes_from_walls(haus)
    create_nodes_from_connectors(haus)
    associate_objects_to_walls_and_nodes(haus)
    calc_wires(haus)
    create_roombook(haus)
    assert len(haus.kabel) == 7
    # explicit cable
    assert haus.kabel[0].start == "1.1.1"
    assert len(haus.kabel[0].end) == 3
    assert haus.kabel[0].end[0] == "2.2.3"
    assert haus.kabel[0].end[1] == "2.2.4"
    assert haus.kabel[0].end[2] == "2.2.5"
    assert haus.kabel[0].length == approx(9.4)
    # impicit definde cabels
    assert haus.kabel[1].start == "1.1.1"
    assert len(haus.kabel[1].end) == 1
    assert haus.kabel[1].end[0] == "1.1.2"
    assert haus.kabel[1].type == KabelType.NYM5x15
    assert haus.kabel[1].length == approx(3.4)

    assert haus.kabel[2].length == approx(3.6)
    assert haus.kabel[3].end[0] == "2.1.1"
    # directly above it
    assert haus.kabel[3].length == approx(2.8)
    assert haus.kabel[4].length == approx(5.6)
Beispiel #2
0
def read_setup(yaml_file):
    with open(yaml_file, "r") as stream:
        data = yaml.safe_load(stream)
    # print("Reading Setup for {}".format(data["config"]["name"]))

    folder = os.path.dirname(os.path.abspath(yaml_file)) + "/"
    file_anschluesse = folder + data["config"]["anschluesse"]
    file_struktur = folder + data["config"]["struktur"]
    file_kabel = folder + data["config"]["kabel"]
    if not os.path.isfile(file_struktur):
        raise RuntimeError("File not found: {}".format(file_struktur))
    if not os.path.isfile(file_anschluesse):
        raise RuntimeError("File not found: {}".format(file_anschluesse))
    if not os.path.isfile(file_kabel):
        raise RuntimeError("File not found: {}".format(file_kabel))
    haus = Haus()

    # Read YAML filess
    with open(file_struktur, "r") as stream:
        yaml_struktur = yaml.safe_load(stream)
    with open(file_anschluesse, "r") as stream:
        yaml_anschluesse = yaml.safe_load(stream)
    with open(file_kabel, "r") as stream:
        yaml_kabel = yaml.safe_load(stream)

    read_struktur(haus, yaml_struktur)
    read_anschluesse(haus, yaml_anschluesse)
    read_kabel(haus, yaml_kabel)
    autogenerate_kabel(haus)

    create_nodes_from_walls(haus)
    create_nodes_from_connectors(haus)

    return haus
def test_single_wall_kabel():
    haus = Haus()
    yaml = simple_haus.single_wall()

    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    create_nodes_from_walls(haus)
    associate_objects_to_walls_and_nodes(haus)
    autogenerate_kabel(haus, False)
    calc_wires(haus)
def test_single_wall():
    haus = Haus()
    yaml = simple_haus.single_wall()

    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    create_nodes_from_walls(haus)
    associate_objects_to_walls_and_nodes(haus)
    assert len(haus.nodes) == 10
    for g in haus.geschosse:
        for r in g.rooms:
            for o in r.objects:
                assert o.associated_node != None
def test_autogenerate_kabels():
    haus = Haus()
    yaml = simple_haus.define_testcase()

    yaml["anschluesse"] = {
        "geschosse": [
            {
                "id": 1,
                "name": "G1",
                "rooms": [
                    {
                        "id": 1,
                        "name": "R11",
                        "objects": [
                            {
                                "id": 1,
                                "name": "O111",
                                "con-type": "steckdose",
                                "anzahl": 1,
                                "pos": {"hori": [20, 150], "vert": "oben"},
                            },
                            {
                                "id": 2,
                                "name": "O112",
                                "con-type": "knx",
                                "knx-component": "gt",
                                "pos": {"hori": [200, 20], "vert": "oben"},
                            },
                            {
                                "id": 3,
                                "name": "O113",
                                "con-type": "knx",
                                "knx-component": "pm",
                                "pos": {"hori": [350, 20], "vert": "oben"},
                            },
                        ],
                    }
                ],
            }
        ]
    }
    yaml["kabel"] = {"kabel": []}
    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    read_kabel(haus, yaml["kabel"])
    autogenerate_kabel(haus, False)
    calc_wires(haus)
    create_roombook(haus)
    assert len(haus.kabel) == 2
    assert haus.kabel[0].length == approx(1.30 + 1.80)
    assert haus.kabel[1].length == approx(1.30 + 3.30)
def test_autogen_kabel_with_astar_len_calc():
    haus = Haus()
    yaml = simple_haus.define_testcase()
    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    # read_kabel(haus,yaml["kabel"])
    autogenerate_kabel(haus)
    create_nodes_from_walls(haus)
    assert len(haus.nodes) == 8 + 16
    haus.geschosse[0].nodes[4].connect(haus.geschosse[1].nodes[0])
    associate_objects_to_walls_and_nodes(haus)

    calc_wires(haus)
    create_roombook(haus)
def test_simple_haus_kabel():
    haus = Haus()
    yaml = simple_haus.define_testcase_simple1()

    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    create_nodes_from_walls(haus)
    associate_objects_to_walls_and_nodes(haus)

    assert (
        haus.geschosse[0].rooms[0].objects[0].associated_wall
        == haus.geschosse[0].walls[1]
    )
    assert (
        haus.geschosse[0].rooms[0].objects[1].associated_wall
        == haus.geschosse[0].walls[0]
    )

    # object 2 is added first becaus eit is on wall 1
    assert haus.geschosse[0].rooms[0].objects[1].associated_node.id == haus.nodes[10].id
    assert haus.geschosse[0].rooms[0].objects[0].associated_node.id == haus.nodes[13].id

    assert len(haus.geschosse[0].walls[0].nodes) == 7

    #  2 ---------- 5 --------- 3
    #  |            |           |
    #  |            |           |
    #  |            6           |
    #  |            |           |
    #  |            |           |
    #  0 ---------- 4 --------- 1

    nodes = haus.geschosse[0].walls[0].nodes
    # connection to the new edge on the "floor"
    assert nodes[0].get_connected_nodes()[0].id == nodes[4].id
    # connection to the upper egde
    assert nodes[0].get_connected_nodes()[2].id == nodes[2].id
    # new edge on floor is connected to object edge
    assert nodes[4].get_connected_nodes()[2].id == nodes[6].id

    assert nodes[6].get_connected_nodes()[0].id == nodes[4].id
    assert nodes[6].get_connected_nodes()[1].id == nodes[5].id
Beispiel #8
0
def test_astar():
    haus = Haus()
    yaml = simple_haus.define_testcase_simple1()

    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    create_nodes_from_walls(haus)
    associate_objects_to_walls_and_nodes(haus)
    autogenerate_kabel(haus)

    assert len(haus.kabel) == 1

    get_kabel_objects(haus, haus.kabel[0])
    path = calc_kabel_len(haus.kabel[0])

    assert len(path) == 6

    for e in path:
        print("EDGE: {}".format(e))

    assert haus.kabel[0].length == approx(
        (40 + 240 + 2 * sqrt(10**2 + 30**2)) * 0.01)
def test_indirect_connection():
    haus = Haus()
    yaml = simple_haus.define_testcase()
    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    create_nodes_from_walls(haus)

    assert len(haus.nodes) == 8 + 16
    assert len(haus.geschosse[0].nodes) == 8
    assert len(haus.geschosse[1].nodes) == 16
    associate_objects_to_walls_and_nodes(haus)
    haus.kabel.append(Kabel("2.1.2", "2.2.2"))
    calc_wires(haus)
    create_roombook(haus)
    assert haus.kabel[0].start == "2.1.2"
    assert haus.kabel[0].end[0] == "2.2.2"
    # assert haus.kabel[0].length == approx(1 + 1.5)

    # path = calc_kabel_len(haus, haus.kabel[0])
    # for e in path:
    #     print(e)
    # assert len(path) == 8
    print(haus.kabel[0])
    assert haus.kabel[0].length == approx(2.4 + 1.0 + 0.9 + 1.0)
Beispiel #10
0
def test_read_struktur():
    haus = Haus()
    yaml_data = {
        "geschosse": [
            {
                "id": 1,
                "name": "G1",
                "rooms": [
                    {
                        "id": 1,
                        "name": "R11",
                        "objects": [
                            {
                                "id": 1,
                                "name": "O111",
                                "con-type": "steckdose",
                                "anzahl": 1,
                                "pos": {"hori": [10, 0], "vert": "oben"},
                            },
                            {
                                "id": 2,
                                "name": "O112",
                                "con-type": "steckdose",
                                "anzahl": 2,
                                "pos": {"hori": [20, 5], "vert": "oben"},
                            },
                            {
                                "id": 3,
                                "name": "O113",
                                "con-type": "steckdose",
                                "anzahl": 3,
                                "pos": {"hori": [30, 8], "vert": "oben"},
                            },
                        ],
                    }
                ],
            },
            {
                "id": 2,
                "name": "G2",
                "rooms": [
                    {
                        "id": 1,
                        "name": "R21",
                        "objects": [
                            {
                                "id": 1,
                                "name": "O211",
                                "con-type": "steckdose",
                                "anzahl": 1,
                                "pos": {"hori": [10, 0], "vert": "oben"},
                            },
                            {
                                "id": 2,
                                "name": "O212",
                                "con-type": "steckdose",
                                "anzahl": 2,
                                "pos": {"hori": [20, 5], "vert": "oben"},
                            },
                        ],
                    }
                ],
            },
        ]
    }
    yaml_data_struktur = {
        "geschosse": [
            {
                "id": 1,
                "name": "G1",
                "height": 236,
                "heights": [0, 30, 100, 210, 236],
                "walls": [
                    {"id": 1, "pos": {"hori": [25, 0]}, "ende": [36.5, 1049]},
                    {
                        "id": 2,
                        "pos": {"hori": [25, 0]},
                        "ende": ["36.5+576+11.5", 36.5],
                    },
                ],
            },
            {
                "id": 2,
                "name": "G2",
                "height": 255,
                "heights": [0, 30, 100, 230, 255],
                "walls": [
                    {"id": 1, "pos": {"hori": [25, 0]}, "ende": [36.5, 324]},
                    {
                        "id": 2,
                        "pos": {"hori": ["61.5-36.5", 0]},
                        "ende": ["587.5+36.5", 36.5],
                    },
                ],
            },
            {
                "id": 3,
                "name": "G3",
                "height": 255,
                "heights": [0, 30, 100, 230, 255],
                "walls": [
                    {"id": 1, "pos": {"hori": [25, 0]}, "ende": [24, "292.5+31.5"]},
                    {"id": 2, "pos": {"hori": [0, 292.5]}, "ende": [24, 883]},
                ],
            },
        ]
    }

    print(yaml_data)
    read_struktur(haus, yaml_data_struktur)
    read_anschluesse(haus, yaml_data)
    assert len(haus.geschosse[0].rooms) == 1
    assert len(haus.geschosse[0].rooms[0].objects) == 3
    assert len(haus.geschosse[1].rooms) == 1
    assert len(haus.geschosse[1].rooms[0].objects) == 2
def test_read_struktur():
    haus = Haus()
    yaml = simple_haus.define_testcase()

    read_struktur(haus, yaml["struktur"])
    read_anschluesse(haus, yaml["anschluesse"])
    create_nodes_from_walls(haus)
    create_svg(haus)

    assert len(haus.nodes) == 24
    assert len(haus.geschosse) == 2
    assert len(haus.geschosse[0].walls) == 2
    nodes = haus.geschosse[0].nodes
    assert len(nodes) == 8

    # for e in nodes:
    #     print("Edge: {}".format(e))
    #     for c in e.get_connected_nodes():
    #         print("-- connected to {}".format(c))

    assert len(nodes[0].get_connected_nodes()) == 3
    assert nodes[0].get_connected_nodes()[0] == nodes[1]
    assert nodes[0].get_connected_nodes()[1] == nodes[2]
    assert nodes[0].get_connected_nodes()[2] == nodes[4]
    assert len(nodes[1].get_connected_nodes()) == 2
    assert nodes[1].get_connected_nodes()[0] == nodes[0]
    assert nodes[1].get_connected_nodes()[1] == nodes[5]
    assert len(nodes[2].get_connected_nodes()) == 3
    assert nodes[2].get_connected_nodes()[0] == nodes[3]
    assert nodes[2].get_connected_nodes()[1] == nodes[0]
    assert nodes[2].get_connected_nodes()[2] == nodes[6]
    assert len(nodes[3].get_connected_nodes()) == 2
    assert nodes[3].get_connected_nodes()[0] == nodes[2]
    assert nodes[3].get_connected_nodes()[1] == nodes[7]

    #  upper nodes
    assert len(nodes[4].get_connected_nodes()) == 3
    assert nodes[4].get_connected_nodes()[0] == nodes[0]
    assert nodes[4].get_connected_nodes()[1] == nodes[5]
    assert nodes[4].get_connected_nodes()[2] == nodes[6]
    assert len(nodes[5].get_connected_nodes()) == 2
    assert nodes[5].get_connected_nodes()[0].id == nodes[4].id
    assert nodes[5].get_connected_nodes()[1].id == nodes[1].id
    assert len(nodes[6].get_connected_nodes()) == 3
    assert nodes[6].get_connected_nodes()[0] == nodes[4]
    assert nodes[6].get_connected_nodes()[1] == nodes[2]
    assert nodes[6].get_connected_nodes()[2] == nodes[7]
    assert len(nodes[7].get_connected_nodes()) == 2
    assert nodes[7].get_connected_nodes()[0] == nodes[6]
    assert nodes[7].get_connected_nodes()[1] == nodes[3]

    ## obergeschoss
    assert len(haus.geschosse[1].walls) == 4
    nodes = haus.geschosse[1].nodes
    assert len(nodes) == 16
    for i, e in enumerate(nodes):
        print("Node: {}".format(e))
        for c in e.get_connected_nodes():
            print("-- connected to {}".format(c))
        if i < 8:  # nodes at bottom of the wall
            assert e.z == 250
        else:  # nodes at top of the wall
            assert e.z == 550

    assert len(nodes[0].get_connected_nodes()) == 3
    assert nodes[0].get_connected_nodes()[0].id == nodes[1].id
    assert nodes[0].get_connected_nodes()[1].id == nodes[2].id
    assert nodes[0].get_connected_nodes()[2].id == nodes[8].id
    assert len(nodes[1].get_connected_nodes()) == 2
    assert nodes[1].get_connected_nodes()[0].id == nodes[0].id
    assert nodes[1].get_connected_nodes()[1].id == nodes[9].id
    assert len(nodes[2].get_connected_nodes()) == 3
    assert nodes[2].get_connected_nodes()[0].id == nodes[6].id
    assert nodes[2].get_connected_nodes()[1].id == nodes[0].id
    assert nodes[2].get_connected_nodes()[2].id == nodes[10].id
    assert len(nodes[3].get_connected_nodes()) == 3
    assert nodes[3].get_connected_nodes()[0].id == nodes[4].id
    assert nodes[3].get_connected_nodes()[1].id == nodes[6].id
    assert nodes[3].get_connected_nodes()[2].id == nodes[11].id
    assert len(nodes[4].get_connected_nodes()) == 3
    assert nodes[4].get_connected_nodes()[0].id == nodes[5].id
    assert nodes[4].get_connected_nodes()[1].id == nodes[3].id
    assert nodes[4].get_connected_nodes()[2].id == nodes[13].id
    assert len(nodes[5].get_connected_nodes()) == 2
    assert nodes[5].get_connected_nodes()[0].id == nodes[4].id
    assert nodes[5].get_connected_nodes()[1].id == nodes[14].id
    assert len(nodes[6].get_connected_nodes()) == 4
    assert nodes[6].get_connected_nodes()[0].id == nodes[7].id
    assert nodes[6].get_connected_nodes()[1].id == nodes[2].id
    assert nodes[6].get_connected_nodes()[2].id == nodes[3].id
    assert nodes[6].get_connected_nodes()[3].id == nodes[12].id
    assert len(nodes[7].get_connected_nodes()) == 2
    assert nodes[7].get_connected_nodes()[0].id == nodes[6].id
    assert nodes[7].get_connected_nodes()[1].id == nodes[15].id
    # upper nodes
    assert len(nodes[8].get_connected_nodes()) == 3
    assert nodes[8].get_connected_nodes()[0].id == nodes[0].id
    assert nodes[8].get_connected_nodes()[1].id == nodes[9].id
    assert nodes[8].get_connected_nodes()[2].id == nodes[10].id
    assert len(nodes[9].get_connected_nodes()) == 2
    assert nodes[9].get_connected_nodes()[0].id == nodes[8].id
    assert nodes[9].get_connected_nodes()[1].id == nodes[1].id
    assert len(nodes[10].get_connected_nodes()) == 3
    assert nodes[10].get_connected_nodes()[0].id == nodes[8].id
    assert nodes[10].get_connected_nodes()[1].id == nodes[2].id
    assert nodes[10].get_connected_nodes()[2].id == nodes[12].id
    assert len(nodes[11].get_connected_nodes()) == 3
    assert nodes[11].get_connected_nodes()[0].id == nodes[3].id
    assert nodes[11].get_connected_nodes()[1].id == nodes[12].id
    assert nodes[11].get_connected_nodes()[2].id == nodes[13].id
    assert len(nodes[12].get_connected_nodes()) == 4
    assert nodes[12].get_connected_nodes()[0].id == nodes[10].id
    assert nodes[12].get_connected_nodes()[1].id == nodes[11].id
    assert nodes[12].get_connected_nodes()[2].id == nodes[6].id
    assert nodes[12].get_connected_nodes()[3].id == nodes[15].id
    assert len(nodes[13].get_connected_nodes()) == 3
    assert nodes[13].get_connected_nodes()[0].id == nodes[11].id
    assert nodes[13].get_connected_nodes()[1].id == nodes[4].id
    assert nodes[13].get_connected_nodes()[2].id == nodes[14].id
    assert len(nodes[14].get_connected_nodes()) == 2
    assert nodes[14].get_connected_nodes()[0].id == nodes[13].id
    assert nodes[14].get_connected_nodes()[1].id == nodes[5].id
    assert len(nodes[15].get_connected_nodes()) == 2
    assert nodes[15].get_connected_nodes()[0].id == nodes[12].id
    assert nodes[15].get_connected_nodes()[1].id == nodes[7].id