mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-14 07:58:46 +02:00
solved errors
This commit is contained in:
parent
7e8adfafd5
commit
30f9e4506f
@ -1,10 +1,11 @@
|
|||||||
"""Content of home page."""
|
"""Content of home page."""
|
||||||
|
from functools import lru_cache
|
||||||
import dash
|
import dash
|
||||||
import dash_daq as daq
|
import dash_daq as daq
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
from dash import Input, Output, callback, dash_table, dcc, html
|
from dash import Input, Output, callback, dash_table, dcc, html, ctx
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.utils.networkx.network_2d import (
|
from aki_prj23_transparenzregister.utils.networkx.network_2d import (
|
||||||
create_2d_graph,
|
create_2d_graph,
|
||||||
@ -157,53 +158,7 @@ layout = html.Div(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# @lru_cache(200)
|
||||||
@callback(
|
|
||||||
Output("my-graph", "figure"),
|
|
||||||
[
|
|
||||||
Input("dropdown", "value"),
|
|
||||||
Input("switch", "on"),
|
|
||||||
Input("dropdown_company_relation_filter", "value"),
|
|
||||||
Input("dropdown_person_relation_filter", "value"),
|
|
||||||
],
|
|
||||||
prevent_initial_call=True,
|
|
||||||
allow_duplicate=True,
|
|
||||||
)
|
|
||||||
def update_figure(
|
|
||||||
selected_metric: str,
|
|
||||||
switch_value: bool,
|
|
||||||
c_relation_filter_value: str,
|
|
||||||
p_relation_filter_value: str,
|
|
||||||
) -> go.Figure:
|
|
||||||
"""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_
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Network Graph(Plotly Figure): Plotly Figure in 3 or 2D
|
|
||||||
"""
|
|
||||||
_ = c_relation_filter_value, p_relation_filter_value
|
|
||||||
|
|
||||||
# find_top_companies()
|
|
||||||
|
|
||||||
metric = None if selected_metric == "None" else selected_metric
|
|
||||||
|
|
||||||
# if triggered_id == 'dropdown_companyrelation_filter' or triggered_id == 'dropdown_personrelation_filter':
|
|
||||||
# print(selected_value)
|
|
||||||
# print(metrics)
|
|
||||||
# print(graph)
|
|
||||||
# graph, metrics = update_graph_data(person_relation_type= p_relation_filter, company_relation_type= c_relation_filter)
|
|
||||||
|
|
||||||
if switch_value:
|
|
||||||
return create_2d_graph(graph, nodes, edges, metrics, metric)
|
|
||||||
else:
|
|
||||||
return create_3d_graph(graph, nodes, edges, metrics, metric)
|
|
||||||
|
|
||||||
|
|
||||||
def update_graph_data(
|
def update_graph_data(
|
||||||
person_relation_type: str = "HAFTENDER_GESELLSCHAFTER",
|
person_relation_type: str = "HAFTENDER_GESELLSCHAFTER",
|
||||||
company_relation_type: str = "GESCHAEFTSFUEHRER",
|
company_relation_type: str = "GESCHAEFTSFUEHRER",
|
||||||
@ -222,3 +177,50 @@ def update_graph_data(
|
|||||||
|
|
||||||
graph, metrics = initialize_network(nodes=nodes, edges=edges)
|
graph, metrics = initialize_network(nodes=nodes, edges=edges)
|
||||||
return graph, metrics
|
return graph, metrics
|
||||||
|
|
||||||
|
|
||||||
|
@callback(
|
||||||
|
Output("my-graph", "figure"),
|
||||||
|
[
|
||||||
|
Input("dropdown", "value"),
|
||||||
|
Input("switch", "on"),
|
||||||
|
Input("dropdown_company_relation_filter", "value"),
|
||||||
|
Input("dropdown_person_relation_filter", "value"),
|
||||||
|
],
|
||||||
|
prevent_initial_call=True,
|
||||||
|
allow_duplicate=True,
|
||||||
|
)
|
||||||
|
# @lru_cache(20)
|
||||||
|
def update_figure(
|
||||||
|
selected_metric: str,
|
||||||
|
switch_value: bool,
|
||||||
|
c_relation_filter_value: str,
|
||||||
|
p_relation_filter_value: str,
|
||||||
|
) -> go.Figure:
|
||||||
|
"""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_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Network Graph(Plotly Figure): Plotly Figure in 3 or 2D
|
||||||
|
"""
|
||||||
|
_ = c_relation_filter_value, p_relation_filter_value
|
||||||
|
# triggered_id = ctx.triggered_id
|
||||||
|
|
||||||
|
# if triggered_id == 'dropdown_companyrelation_filter' or triggered_id == 'dropdown_personrelation_filter':
|
||||||
|
# print(selected_value)
|
||||||
|
# print(metrics)
|
||||||
|
# print(graph)
|
||||||
|
graph, metrics = update_graph_data(person_relation_type= p_relation_filter_value, company_relation_type= c_relation_filter_value)
|
||||||
|
|
||||||
|
if switch_value:
|
||||||
|
return create_2d_graph(graph, nodes, edges, metrics, selected_metric)
|
||||||
|
else:
|
||||||
|
return create_3d_graph(graph, nodes, edges, metrics, selected_metric)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""This Module contains the Method to create a 2D Network Graph with NetworkX."""
|
"""This Module contains the Method to create a 2D Network Graph with NetworkX."""
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
|
|
||||||
@ -107,8 +108,8 @@ def create_2d_graph(
|
|||||||
node_trace.text = node_names
|
node_trace.text = node_names
|
||||||
|
|
||||||
# Highlight the Node Size in regards to the selected Metric.
|
# Highlight the Node Size in regards to the selected Metric.
|
||||||
if metric is not None:
|
if metric != "None":
|
||||||
node_trace.marker.size = list(metrics[metric] * 500)
|
node_trace.marker.size = list(np.sqrt(metrics[metric]) * 200)
|
||||||
|
|
||||||
# Add Relation_Type as a Descriptin for the edges.
|
# Add Relation_Type as a Descriptin for the edges.
|
||||||
edge_type_list = []
|
edge_type_list = []
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""This Module contains the Method to create a 3D Network Graph with NetworkX."""
|
"""This Module contains the Method to create a 3D Network Graph with NetworkX."""
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
|
|
||||||
@ -129,8 +130,8 @@ def create_3d_graph(
|
|||||||
node_trace.text = node_names
|
node_trace.text = node_names
|
||||||
|
|
||||||
# Highlight the Node Size in regards to the selected Metric.
|
# Highlight the Node Size in regards to the selected Metric.
|
||||||
if metric is not None:
|
if metric != "None":
|
||||||
node_trace.marker.size = list(metrics[metric] * 500)
|
node_trace.marker.size = list(np.cbrt(metrics[metric]) * 200)
|
||||||
|
|
||||||
# Set the Color and width of Edges for better highlighting.
|
# Set the Color and width of Edges for better highlighting.
|
||||||
edge_colors = []
|
edge_colors = []
|
||||||
|
@ -97,7 +97,7 @@ def get_all_company_relations() -> pd.DataFrame:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
str(relations_company_query)
|
str(relations_company_query)
|
||||||
company_relations = pd.read_sql_query(str(relations_company_query), session.bind)
|
company_relations = pd.read_sql_query(str(relations_company_query), session.bind) # type: ignore
|
||||||
|
|
||||||
company_relations["id_company_from"] = company_relations["id_company_from"].apply(
|
company_relations["id_company_from"] = company_relations["id_company_from"].apply(
|
||||||
lambda x: f"c_{x}"
|
lambda x: f"c_{x}"
|
||||||
@ -134,7 +134,7 @@ def get_all_person_relations() -> pd.DataFrame:
|
|||||||
entities.PersonRelation.person_id == entities.Person.id,
|
entities.PersonRelation.person_id == entities.Person.id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
person_relations = pd.read_sql_query(str(relations_person_query), session.bind)
|
person_relations = pd.read_sql_query(str(relations_person_query), session.bind) # type: ignore
|
||||||
|
|
||||||
person_relations["id_company"] = person_relations["id_company"].apply(
|
person_relations["id_company"] = person_relations["id_company"].apply(
|
||||||
lambda x: f"c_{x}"
|
lambda x: f"c_{x}"
|
||||||
@ -267,9 +267,6 @@ 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()]:
|
||||||
print("In Method:" + str(selected_company_id))
|
|
||||||
selected_company_id = 312
|
|
||||||
# print( entities.Company.id == selected_company_id)
|
|
||||||
relations_company_query = (
|
relations_company_query = (
|
||||||
session.query(
|
session.query(
|
||||||
to_company.id.label("id_company_to"),
|
to_company.id.label("id_company_to"),
|
||||||
@ -286,9 +283,10 @@ def find_company_relations(
|
|||||||
from_company,
|
from_company,
|
||||||
entities.CompanyRelation.company2_id == from_company.id,
|
entities.CompanyRelation.company2_id == from_company.id,
|
||||||
)
|
)
|
||||||
.where(to_company.id == selected_company_id)
|
.filter((from_company.id == selected_company_id) | (to_company.id == selected_company_id))
|
||||||
)
|
)
|
||||||
logger.debug(str(relations_company_query))
|
company_relations = pd.DataFrame(relations_company_query.all())
|
||||||
|
# logger.debug(str(relations_company_query))
|
||||||
# relations_company_query = relations_company_query.filter(entities.CompanyRelation.company2_id == selected_company_id) # or (entities.CompanyRelation.company2_id == selected_company_id))
|
# relations_company_query = relations_company_query.filter(entities.CompanyRelation.company2_id == selected_company_id) # or (entities.CompanyRelation.company2_id == selected_company_id))
|
||||||
# logger.debug(str(relations_company_query))
|
# logger.debug(str(relations_company_query))
|
||||||
# tmp = str(relations_company_query) + " WHERE from_company.id = " + str(selected_company_id)
|
# tmp = str(relations_company_query) + " WHERE from_company.id = " + str(selected_company_id)
|
||||||
@ -306,10 +304,6 @@ def find_company_relations(
|
|||||||
"id_company_from",
|
"id_company_from",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
logger.debug(str(relations_company_query))
|
|
||||||
print("query ergebnis:")
|
|
||||||
|
|
||||||
print(company_relations)
|
|
||||||
|
|
||||||
company_relations["id_company_from"] = company_relations["id_company_from"].apply(
|
company_relations["id_company_from"] = company_relations["id_company_from"].apply(
|
||||||
lambda x: f"c_{x}"
|
lambda x: f"c_{x}"
|
||||||
|
@ -40,13 +40,12 @@ def get_engine(conn_args: SQLConnectionString) -> Engine:
|
|||||||
database=conn_args.database,
|
database=conn_args.database,
|
||||||
port=conn_args.port,
|
port=conn_args.port,
|
||||||
)
|
)
|
||||||
return sa.create_engine(url, echo=True)
|
return sa.create_engine(url)
|
||||||
if isinstance(conn_args, SQLiteConnectionString):
|
if isinstance(conn_args, SQLiteConnectionString):
|
||||||
return sa.create_engine(
|
return sa.create_engine(
|
||||||
str(conn_args),
|
str(conn_args),
|
||||||
connect_args={"check_same_thread": True},
|
connect_args={"check_same_thread": True},
|
||||||
poolclass=SingletonThreadPool,
|
poolclass=SingletonThreadPool
|
||||||
echo=True,
|
|
||||||
)
|
)
|
||||||
raise TypeError("The type of the configuration is invalid.")
|
raise TypeError("The type of the configuration is invalid.")
|
||||||
|
|
||||||
|
@ -8,8 +8,9 @@ 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()
|
tc = TestCase()
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.mark.tim
|
||||||
def test_initialize_network() -> None:
|
def test_initialize_network() -> None:
|
||||||
edges: list = [
|
edges: list = [
|
||||||
{"from": "p_545", "to": "c_53", "type": "HAFTENDER_GESELLSCHAFTER"},
|
{"from": "p_545", "to": "c_53", "type": "HAFTENDER_GESELLSCHAFTER"},
|
||||||
@ -30,8 +31,8 @@ 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 isinstance(graph, nx.Graph)
|
||||||
assert type(metrics) is pd.DataFrame
|
assert isinstance(metrics, pd.DataFrame)
|
||||||
tc.assertListEqual(
|
tc.assertListEqual(
|
||||||
list(metrics.columns),
|
list(metrics.columns),
|
||||||
["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
["degree", "eigenvector", "betweeness", "closeness", "pagerank"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user