Removed double execution of Layouting in 2 and 3d. (#385)

Prior to layouting the sping layout was allways calculated and later
overwritten. (Double execution)
This commit is contained in:
Philipp Horstenkamp 2023-11-16 17:25:15 +01:00 committed by GitHub
parent 96d216fb74
commit ce1598c42e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 64 deletions

View File

@ -23,36 +23,30 @@ def create_2d_graph( # noqa PLR0913
edges: List of Edges
metrics: DataFrame with the Metrics
metric: Selected Metric
layout: String which defines the Graph Layout
edge_annotation: Enables the Description of Edges
edge_thickness: Int Value of the Edge thickness
layout: String which defines the Graph Layout
Returns:
Plotly Figure
"""
# Set 2D Layout
pos = nx.spring_layout(graph)
match layout:
case "Spring":
pos = nx.spring_layout(graph)
# case "Bipartite":
# pos = nx.bipartite_layout(graph)
case "Circular":
pos = nx.circular_layout(graph)
case "Kamada Kawai":
pos = nx.kamada_kawai_layout(graph)
# case "Planar":
# pos = nx.planar_layout(graph)
case "Random":
pos = nx.random_layout(graph)
case "Shell":
pos = nx.shell_layout(graph)
# case "Spectral":
# pos = nx.spectral_layout(graph)
case "Spiral":
pos = nx.spiral_layout(graph)
# case "Multipartite":
# pos = nx.multipartite_layout(graph)
case _:
raise ValueError(f'Unknown 2d layout "{layout}" requested.')
# Initialize Variables to set the Position of the Edges.
edge_x = []

View File

@ -28,28 +28,17 @@ def create_3d_graph( # noqa : PLR0913
Plotly Figure
"""
# 3d spring layout
pos = nx.spring_layout(graph, dim=3)
match layout:
case "Spring":
pos = nx.spring_layout(graph, dim=3)
# case "Bipartite":
# pos = nx.bipartite_layout(graph, dim=3)
case "Circular":
pos = nx.circular_layout(graph, dim=3)
case "Kamada Kawai":
pos = nx.kamada_kawai_layout(graph, dim=3)
# case "Planar":
# pos = nx.planar_layout(graph, dim=3)
case "Random":
pos = nx.random_layout(graph, dim=3)
# case "Shell":
# pos = nx.shell_layout(graph, dim=3)
# case "Spectral":
# pos = nx.spectral_layout(graph, dim=3)
# case "Spiral":
# pos = nx.spiral_layout(graph, dim=3)
# case "Multipartite":
# pos = nx.multipartite_layout(graph, dim=3)
case _:
raise ValueError(f'Unknown 3d layout "{layout}" requested.')
# Initialize Variables to set the Position of the Edges.
edge_x = []

View File

@ -348,11 +348,11 @@ def get_all_metrics_from_id(company_id: int) -> pd.Series:
@lru_cache
def get_relations_number_from_id(id: int) -> tuple[int, int, int]:
def get_relations_number_from_id(id: str) -> tuple[int, int, int]:
"""Returns all Relation in 1, 2 and 3 lvl of one Node.
Args:
id (int): String of the Company or Person Id.
id: String of the Company or Person Id.
Returns:
tuple[int,int,int]: _description_
@ -381,4 +381,4 @@ def get_relations_number_from_id(id: int) -> tuple[int, int, int]:
relations_lv2.difference(relations_lv3)
return (len(relations_lv1), len(relations_lv2), len(relations_lv3))
return len(relations_lv1), len(relations_lv2), len(relations_lv3)

View File

@ -25,7 +25,19 @@ def _set_session(full_db: Session) -> Generator[None, None, None]:
SessionHandler.session = None
def test_create_2d_graph() -> None:
@pytest.mark.parametrize(
("layout", "metric", "edge_annotation", "edge_thickness"),
[
("Kamada Kawai", "None", True, 1),
("Random", "degree", False, 2),
("Shell", "degree", True, 3),
("Spiral", "None", False, 4),
("Circular", "None", True, 1),
],
)
def test_create_2d_graph(
layout: str, metric: str, edge_annotation: bool, edge_thickness: int
) -> None:
"""Tests the creation of a 2D Graph."""
edges: list = [
{"from": "p_545", "to": "c_53", "type": "HAFTENDER_GESELLSCHAFTER"},
@ -61,42 +73,6 @@ def test_create_2d_graph() -> None:
},
}
graph, metrics = initialize_network(edges=edges, nodes=nodes)
metric = "None"
layout = "Spring"
edge_annotation = False
edge_thickness = 1
figure = create_2d_graph(
graph, nodes, edges, metrics, metric, layout, edge_annotation, edge_thickness
)
assert type(figure) is go.Figure
metric = "degree"
layout = "Circular"
figure = create_2d_graph(
graph, nodes, edges, metrics, metric, layout, edge_annotation, edge_thickness
)
assert type(figure) is go.Figure
edge_annotation = True
layout = "Kamada Kawai"
figure = create_2d_graph(
graph, nodes, edges, metrics, metric, layout, edge_annotation, edge_thickness
)
assert type(figure) is go.Figure
layout = "Random"
figure = create_2d_graph(
graph, nodes, edges, metrics, metric, layout, edge_annotation, edge_thickness
)
assert type(figure) is go.Figure
layout = "Shell (only 2D)"
figure = create_2d_graph(
graph, nodes, edges, metrics, metric, layout, edge_annotation, edge_thickness
)
assert type(figure) is go.Figure
layout = "Spiral (only 2D)"
figure = create_2d_graph(
graph, nodes, edges, metrics, metric, layout, edge_annotation, edge_thickness
)

View File

@ -228,7 +228,6 @@ def test_get_all_metrics_from_id() -> None:
def test_get_relations_number_from_id() -> None:
"""This Test methods tests if the correct type and number of relations is received."""
# id = "c_2549"
id = 2
(
relations_lvl_1,