mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-13 09:58:47 +02:00
now ruff confirm
This commit is contained in:
parent
f2ac0eda91
commit
f38728450d
@ -56,12 +56,9 @@ def find_all_company_relations() -> pd.DataFrame:
|
|||||||
|
|
||||||
|
|
||||||
# Plotly figure
|
# Plotly figure
|
||||||
def network_graph() -> go.Figure:
|
def create_network_graph() -> go.Figure:
|
||||||
"""Create a NetworkX Graph.
|
"""Create a NetworkX Graph.
|
||||||
|
|
||||||
Args:
|
|
||||||
EGDE_VAR (None): _description_
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
go.Figure: _description_
|
go.Figure: _description_
|
||||||
"""
|
"""
|
||||||
@ -175,16 +172,13 @@ app.layout = html.Div(
|
|||||||
# Input('metric-dropdown', 'value'),
|
# Input('metric-dropdown', 'value'),
|
||||||
[Input("EGDE_VAR", "value")],
|
[Input("EGDE_VAR", "value")],
|
||||||
)
|
)
|
||||||
def update_output(edge_var: None) -> go.Figure:
|
def update_output() -> go.Figure:
|
||||||
"""Just Returns the go Figure of Plotly.
|
"""Just Returns the go Figure of Plotly.
|
||||||
|
|
||||||
Args:
|
|
||||||
EGDE_VAR (None): _description_
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
go.Figure: _description_
|
go.Figure: Returns a HTML Figure for Plotly.
|
||||||
"""
|
"""
|
||||||
return network_graph(edge_var)
|
return create_network_graph()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -383,10 +383,15 @@ def update_figure( # noqa: PLR0913
|
|||||||
"""In this Callback the Value of the Dropdown is used to filter the Data. In Addition it takes the filter for the Graph metrics and creates a new graph, or switches between 3D and 2D.
|
"""In this Callback the Value of the Dropdown is used to filter the Data. In Addition it takes the filter for the Graph metrics and creates a new graph, or switches between 3D and 2D.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
selected_metric (_type_): _description_
|
selected_metric (_type_): Selected Value
|
||||||
switch_value (bool): _description_
|
switch_value (bool): True if 2D, False if 3D
|
||||||
c_relation_filter_value (_type_): _description_
|
switch_edge_annotaion_value: True if Edge should have a description, Flase = No Descritpion
|
||||||
p_relation_filter_value (_type_): _description_
|
c_relation_filter_value (_type_): Variable with String value of Relation Type for Companies
|
||||||
|
p_relation_filter_value (_type_): Variable with String value of Relation Type for Persons
|
||||||
|
layout: String of the Layout Dropdown
|
||||||
|
metric_dropdown_value: String of the Metric Dropdown
|
||||||
|
slider_value: Sets the size of the Edge Connections
|
||||||
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Network Graph(Plotly Figure): Plotly Figure in 3 or 2D
|
Network Graph(Plotly Figure): Plotly Figure in 3 or 2D
|
||||||
@ -415,21 +420,21 @@ def update_figure( # noqa: PLR0913
|
|||||||
slider_value, # type: ignore
|
slider_value, # type: ignore
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
return (
|
return (
|
||||||
table_dict,
|
table_dict,
|
||||||
table_columns,
|
table_columns,
|
||||||
create_3d_graph(
|
create_3d_graph(
|
||||||
graph,
|
graph,
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
metrics,
|
metrics,
|
||||||
selected_metric,
|
selected_metric,
|
||||||
layout,
|
layout,
|
||||||
switch_edge_annotaion_value,
|
switch_edge_annotaion_value,
|
||||||
slider_value, # type: ignore
|
slider_value, # type: ignore
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
@ -438,7 +443,7 @@ def update_figure( # noqa: PLR0913
|
|||||||
Input("dropdown_data_soruce_filter", "value"),
|
Input("dropdown_data_soruce_filter", "value"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def update_Dropdown(datasource_value: str) -> str:
|
def update_dropdown(datasource_value: str) -> str:
|
||||||
"""_summary_.
|
"""_summary_.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -5,7 +5,7 @@ import pandas as pd
|
|||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
|
|
||||||
|
|
||||||
def create_2d_graph(
|
def create_2d_graph( # noqa PLR0913
|
||||||
graph: nx.Graph,
|
graph: nx.Graph,
|
||||||
nodes: dict,
|
nodes: dict,
|
||||||
edges: list,
|
edges: list,
|
||||||
@ -23,6 +23,9 @@ def create_2d_graph(
|
|||||||
edges (_type_): List of Edges
|
edges (_type_): List of Edges
|
||||||
metrics (_type_): DataFrame with the MEtrics
|
metrics (_type_): DataFrame with the MEtrics
|
||||||
metric (_type_): Selected Metric
|
metric (_type_): Selected Metric
|
||||||
|
edge_annotation: Enables the Description of Edges
|
||||||
|
edge_thickness: Int Value of the Edge thickness
|
||||||
|
layout: String which defines the Graph Layout
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
_type_: Plotly Figure
|
_type_: Plotly Figure
|
||||||
|
@ -277,6 +277,14 @@ def create_edge_and_node_list(
|
|||||||
def find_company_relations(
|
def find_company_relations(
|
||||||
selected_company_id: int,
|
selected_company_id: int,
|
||||||
) -> tuple[pd.DataFrame, pd.DataFrame]:
|
) -> tuple[pd.DataFrame, pd.DataFrame]:
|
||||||
|
"""Finds all Relations for the given Company id.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
selected_company_id: Id of the Company which Relations should be returned.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Two Dataframes
|
||||||
|
"""
|
||||||
relations_company_query = (
|
relations_company_query = (
|
||||||
session.query(
|
session.query(
|
||||||
to_company.id.label("id_company_to"),
|
to_company.id.label("id_company_to"),
|
||||||
@ -343,16 +351,14 @@ def create_edge_and_node_list_for_company(
|
|||||||
nodes: dict = {}
|
nodes: dict = {}
|
||||||
edges: list = []
|
edges: list = []
|
||||||
|
|
||||||
COLOR_COMPANY = "blue"
|
for _, row in company_relations.iterrows():
|
||||||
|
if nodes.get(row["id_company_from"]) is None:
|
||||||
for _index, row in company_relations.iterrows():
|
|
||||||
if node := nodes.get(row["id_company_from"]) is None:
|
|
||||||
nodes[row["id_company_from"]] = {
|
nodes[row["id_company_from"]] = {
|
||||||
"id": row["id_company_from"],
|
"id": row["id_company_from"],
|
||||||
"name": row["name_company_from"],
|
"name": row["name_company_from"],
|
||||||
"color": COLOR_COMPANY,
|
"color": COLOR_COMPANY,
|
||||||
}
|
}
|
||||||
if node := nodes.get(row["id_company_to"]) is None:
|
if nodes.get(row["id_company_to"]) is None:
|
||||||
nodes[row["id_company_to"]] = {
|
nodes[row["id_company_to"]] = {
|
||||||
"id": row["id_company_to"],
|
"id": row["id_company_to"],
|
||||||
"name": row["name_company_to"],
|
"name": row["name_company_to"],
|
||||||
@ -369,10 +375,10 @@ def create_edge_and_node_list_for_company(
|
|||||||
|
|
||||||
|
|
||||||
def get_all_metrics_from_id(company_id: int) -> pd.Series:
|
def get_all_metrics_from_id(company_id: int) -> pd.Series:
|
||||||
"""_summary_
|
"""Returns all Metric for the given ID.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
company_id (int): _description_
|
company_id (int): Id of the Company.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
pd.DataFrame: _description_
|
pd.DataFrame: _description_
|
||||||
@ -391,10 +397,10 @@ def get_all_metrics_from_id(company_id: int) -> pd.Series:
|
|||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def get_relations_number_from_id(id: str) -> tuple[int, int, int]:
|
def get_relations_number_from_id(id: str) -> tuple[int, int, int]:
|
||||||
"""_summary_
|
"""Returns all Relation in 1, 2 and 3 lvl of one Node.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
company_id (int): _description_
|
id (int): String of the Company or Person Id.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple[int,int,int]: _description_
|
tuple[int,int,int]: _description_
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Test for the NetworkX Component."""
|
"""Test for the NetworkX Component."""
|
||||||
from aki_prj23_transparenzregister.ui import networkx_dash
|
from aki_prj23_transparenzregister.ui.archive import networkx_dash
|
||||||
|
|
||||||
|
|
||||||
def network_graph(Edges: None) -> None:
|
def network_graph(edges: None) -> None:
|
||||||
"""Checks if an import co company_stats_dash can be made."""
|
"""Checks if an import co company_stats_dash can be made."""
|
||||||
assert networkx_dash is not None
|
assert networkx_dash is not None
|
||||||
|
@ -29,7 +29,10 @@ def test_initialize_network() -> None:
|
|||||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||||
assert type(graph) is nx.Graph
|
assert type(graph) is nx.Graph
|
||||||
assert type(metrics) is pd.DataFrame
|
assert type(metrics) is pd.DataFrame
|
||||||
assert (
|
assert list(metrics.columns) == [
|
||||||
list(metrics.columns)
|
"degree",
|
||||||
== ["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
"eigenvector",
|
||||||
)
|
"betweeness",
|
||||||
|
"closeness",
|
||||||
|
"pagerank",
|
||||||
|
]
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
"""Test the initialize Network function."""
|
"""Test the initialize Network function."""
|
||||||
import datetime
|
import datetime
|
||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.utils.networkx.network_base import initialize_network
|
from aki_prj23_transparenzregister.utils.networkx.network_base import initialize_network
|
||||||
|
|
||||||
tc = TestCase()
|
|
||||||
|
|
||||||
|
|
||||||
def test_initialize_network() -> None:
|
def test_initialize_network() -> None:
|
||||||
edges: list = [
|
edges: list = [
|
||||||
@ -32,7 +29,10 @@ def test_initialize_network() -> None:
|
|||||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||||
assert type(graph) is nx.Graph
|
assert type(graph) is nx.Graph
|
||||||
assert type(metrics) is pd.DataFrame
|
assert type(metrics) is pd.DataFrame
|
||||||
tc.assertListEqual(
|
assert list(metrics.columns) == [
|
||||||
list(metrics.columns),
|
"degree",
|
||||||
["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
"eigenvector",
|
||||||
)
|
"betweeness",
|
||||||
|
"closeness",
|
||||||
|
"pagerank",
|
||||||
|
]
|
||||||
|
@ -31,7 +31,10 @@ def test_initialize_network() -> None:
|
|||||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||||
assert isinstance(graph, nx.Graph)
|
assert isinstance(graph, nx.Graph)
|
||||||
assert isinstance(metrics, pd.DataFrame)
|
assert isinstance(metrics, pd.DataFrame)
|
||||||
assert (
|
assert list(metrics.columns) == [
|
||||||
list(metrics.columns)
|
"degree",
|
||||||
== ["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
"eigenvector",
|
||||||
)
|
"betweeness",
|
||||||
|
"closeness",
|
||||||
|
"pagerank",
|
||||||
|
]
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
"""Test the initialize Network function."""
|
"""Test the initialize Network function."""
|
||||||
import datetime
|
import datetime
|
||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.utils.networkx.network_base import initialize_network
|
from aki_prj23_transparenzregister.utils.networkx.network_base import initialize_network
|
||||||
|
|
||||||
tc = TestCase()
|
|
||||||
|
|
||||||
|
|
||||||
def test_initialize_network() -> None:
|
def test_initialize_network() -> None:
|
||||||
edges: list = [
|
edges: list = [
|
||||||
@ -32,7 +29,10 @@ def test_initialize_network() -> None:
|
|||||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||||
assert type(graph) is nx.Graph
|
assert type(graph) is nx.Graph
|
||||||
assert type(metrics) is pd.DataFrame
|
assert type(metrics) is pd.DataFrame
|
||||||
tc.assertListEqual(
|
assert list(metrics.columns) == [
|
||||||
list(metrics.columns),
|
"degree",
|
||||||
["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
"eigenvector",
|
||||||
)
|
"betweeness",
|
||||||
|
"closeness",
|
||||||
|
"pagerank",
|
||||||
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user