mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-13 07:08:46 +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
|
||||
def network_graph() -> go.Figure:
|
||||
def create_network_graph() -> go.Figure:
|
||||
"""Create a NetworkX Graph.
|
||||
|
||||
Args:
|
||||
EGDE_VAR (None): _description_
|
||||
|
||||
Returns:
|
||||
go.Figure: _description_
|
||||
"""
|
||||
@ -175,16 +172,13 @@ app.layout = html.Div(
|
||||
# Input('metric-dropdown', '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.
|
||||
|
||||
Args:
|
||||
EGDE_VAR (None): _description_
|
||||
|
||||
Returns:
|
||||
go.Figure: _description_
|
||||
go.Figure: Returns a HTML Figure for Plotly.
|
||||
"""
|
||||
return network_graph(edge_var)
|
||||
return create_network_graph()
|
||||
|
||||
|
||||
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.
|
||||
|
||||
Args:
|
||||
selected_metric (_type_): _description_
|
||||
switch_value (bool): _description_
|
||||
c_relation_filter_value (_type_): _description_
|
||||
p_relation_filter_value (_type_): _description_
|
||||
selected_metric (_type_): Selected Value
|
||||
switch_value (bool): True if 2D, False if 3D
|
||||
switch_edge_annotaion_value: True if Edge should have a description, Flase = No Descritpion
|
||||
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:
|
||||
Network Graph(Plotly Figure): Plotly Figure in 3 or 2D
|
||||
@ -415,21 +420,21 @@ def update_figure( # noqa: PLR0913
|
||||
slider_value, # type: ignore
|
||||
),
|
||||
)
|
||||
else:
|
||||
return (
|
||||
table_dict,
|
||||
table_columns,
|
||||
create_3d_graph(
|
||||
graph,
|
||||
nodes,
|
||||
edges,
|
||||
metrics,
|
||||
selected_metric,
|
||||
layout,
|
||||
switch_edge_annotaion_value,
|
||||
slider_value, # type: ignore
|
||||
),
|
||||
)
|
||||
|
||||
return (
|
||||
table_dict,
|
||||
table_columns,
|
||||
create_3d_graph(
|
||||
graph,
|
||||
nodes,
|
||||
edges,
|
||||
metrics,
|
||||
selected_metric,
|
||||
layout,
|
||||
switch_edge_annotaion_value,
|
||||
slider_value, # type: ignore
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@callback(
|
||||
@ -438,7 +443,7 @@ def update_figure( # noqa: PLR0913
|
||||
Input("dropdown_data_soruce_filter", "value"),
|
||||
],
|
||||
)
|
||||
def update_Dropdown(datasource_value: str) -> str:
|
||||
def update_dropdown(datasource_value: str) -> str:
|
||||
"""_summary_.
|
||||
|
||||
Args:
|
||||
|
@ -5,7 +5,7 @@ import pandas as pd
|
||||
import plotly.graph_objects as go
|
||||
|
||||
|
||||
def create_2d_graph(
|
||||
def create_2d_graph( # noqa PLR0913
|
||||
graph: nx.Graph,
|
||||
nodes: dict,
|
||||
edges: list,
|
||||
@ -23,6 +23,9 @@ def create_2d_graph(
|
||||
edges (_type_): List of Edges
|
||||
metrics (_type_): DataFrame with the MEtrics
|
||||
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:
|
||||
_type_: Plotly Figure
|
||||
|
@ -277,6 +277,14 @@ def create_edge_and_node_list(
|
||||
def find_company_relations(
|
||||
selected_company_id: int,
|
||||
) -> 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 = (
|
||||
session.query(
|
||||
to_company.id.label("id_company_to"),
|
||||
@ -343,16 +351,14 @@ def create_edge_and_node_list_for_company(
|
||||
nodes: dict = {}
|
||||
edges: list = []
|
||||
|
||||
COLOR_COMPANY = "blue"
|
||||
|
||||
for _index, row in company_relations.iterrows():
|
||||
if node := nodes.get(row["id_company_from"]) is None:
|
||||
for _, row in company_relations.iterrows():
|
||||
if nodes.get(row["id_company_from"]) is None:
|
||||
nodes[row["id_company_from"]] = {
|
||||
"id": row["id_company_from"],
|
||||
"name": row["name_company_from"],
|
||||
"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"]] = {
|
||||
"id": row["id_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:
|
||||
"""_summary_
|
||||
"""Returns all Metric for the given ID.
|
||||
|
||||
Args:
|
||||
company_id (int): _description_
|
||||
company_id (int): Id of the Company.
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: _description_
|
||||
@ -391,10 +397,10 @@ def get_all_metrics_from_id(company_id: int) -> pd.Series:
|
||||
|
||||
@lru_cache
|
||||
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:
|
||||
company_id (int): _description_
|
||||
id (int): String of the Company or Person Id.
|
||||
|
||||
Returns:
|
||||
tuple[int,int,int]: _description_
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""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."""
|
||||
assert networkx_dash is not None
|
||||
|
@ -29,7 +29,10 @@ def test_initialize_network() -> None:
|
||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||
assert type(graph) is nx.Graph
|
||||
assert type(metrics) is pd.DataFrame
|
||||
assert (
|
||||
list(metrics.columns)
|
||||
== ["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
||||
)
|
||||
assert list(metrics.columns) == [
|
||||
"degree",
|
||||
"eigenvector",
|
||||
"betweeness",
|
||||
"closeness",
|
||||
"pagerank",
|
||||
]
|
||||
|
@ -1,14 +1,11 @@
|
||||
"""Test the initialize Network function."""
|
||||
import datetime
|
||||
from unittest import TestCase
|
||||
|
||||
import networkx as nx
|
||||
import pandas as pd
|
||||
|
||||
from aki_prj23_transparenzregister.utils.networkx.network_base import initialize_network
|
||||
|
||||
tc = TestCase()
|
||||
|
||||
|
||||
def test_initialize_network() -> None:
|
||||
edges: list = [
|
||||
@ -32,7 +29,10 @@ def test_initialize_network() -> None:
|
||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||
assert type(graph) is nx.Graph
|
||||
assert type(metrics) is pd.DataFrame
|
||||
tc.assertListEqual(
|
||||
list(metrics.columns),
|
||||
["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
||||
)
|
||||
assert list(metrics.columns) == [
|
||||
"degree",
|
||||
"eigenvector",
|
||||
"betweeness",
|
||||
"closeness",
|
||||
"pagerank",
|
||||
]
|
||||
|
@ -31,7 +31,10 @@ def test_initialize_network() -> None:
|
||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||
assert isinstance(graph, nx.Graph)
|
||||
assert isinstance(metrics, pd.DataFrame)
|
||||
assert (
|
||||
list(metrics.columns)
|
||||
== ["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
||||
)
|
||||
assert list(metrics.columns) == [
|
||||
"degree",
|
||||
"eigenvector",
|
||||
"betweeness",
|
||||
"closeness",
|
||||
"pagerank",
|
||||
]
|
||||
|
@ -1,14 +1,11 @@
|
||||
"""Test the initialize Network function."""
|
||||
import datetime
|
||||
from unittest import TestCase
|
||||
|
||||
import networkx as nx
|
||||
import pandas as pd
|
||||
|
||||
from aki_prj23_transparenzregister.utils.networkx.network_base import initialize_network
|
||||
|
||||
tc = TestCase()
|
||||
|
||||
|
||||
def test_initialize_network() -> None:
|
||||
edges: list = [
|
||||
@ -32,7 +29,10 @@ def test_initialize_network() -> None:
|
||||
graph, metrics = initialize_network(edges=edges, nodes=nodes)
|
||||
assert type(graph) is nx.Graph
|
||||
assert type(metrics) is pd.DataFrame
|
||||
tc.assertListEqual(
|
||||
list(metrics.columns),
|
||||
["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
||||
)
|
||||
assert list(metrics.columns) == [
|
||||
"degree",
|
||||
"eigenvector",
|
||||
"betweeness",
|
||||
"closeness",
|
||||
"pagerank",
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user