feat: NetworkX in Plotly Dash

This commit is contained in:
TrisNol
2023-09-30 13:44:16 +02:00
committed by Tim
parent afb1c70460
commit 5cd03306d6
2 changed files with 77 additions and 32 deletions

View File

@ -1,13 +1,15 @@
"""Content of home page."""
import dash
from dash import html
import pandas as pd
import networkx as nx
import pandas as pd
import plotly.graph_objects as go
from dash import Dash, Input, Output, dcc, html, callback, dash_table
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
from aki_prj23_transparenzregister.utils.sql import connector, entities
from aki_prj23_transparenzregister.utils.networkx.networkx_data import find_top_companies, find_all_company_relations
from dash import Input, Output, callback, html
from aki_prj23_transparenzregister.utils.networkx.networkx_data import (
find_all_company_relations,
find_top_companies,
)
dash.register_page(
@ -99,7 +101,6 @@ def networkGraph(EGDE_VAR: None) -> go.Figure:
measure_vector = {}
network_metrics_df = pd.DataFrame()
measure_vector = nx.eigenvector_centrality(network_graph)
network_metrics_df["eigenvector"] = measure_vector.values()
@ -122,31 +123,43 @@ def networkGraph(EGDE_VAR: None) -> go.Figure:
# figure
return go.Figure(data=[edge_trace, node_trace], layout=layout)
df = find_top_companies()
layout = html.Div(
children = html.Div(
children=[
html.Div(
className="top_companytable_style",
children=[
html.Title(title="Top Ten Unternehmen", style={"align": "mid"}),
dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])
]
),
html.Div(
className="networkx_style",
children=[
html.Header(title="Social Graph"),
dcc.Dropdown(['eigenvector', 'degree', 'betweeness', 'closeness'], 'eigenvector', id='demo-dropdown'),
"Text",
dcc.Input(id="EGDE_VAR", type="text", value="K", debounce=True),
# dcc.Dropdown(['eigenvector', 'degree', 'betweeness', 'closeness'], 'eigenvector', id='metric-dropdown'),
dcc.Graph(id="my-graph"),
]
)
]
)
df = find_top_companies()
with open("src/aki_prj23_transparenzregister/ui/assets/network_graph.html") as file:
html_content = file.read()
layout = html.Div(
children=[
# NOTE lib dir created by NetworkX has to be placed in assets
html.Iframe(
src="assets/network_graph.html",
style={"height": "100vh", "width": "100vw"},
allow="*",
)
]
# children = html.Div(
# children=[
# html.Div(
# className="top_companytable_style",
# children=[
# html.Title(title="Top Ten Unternehmen", style={"align": "mid"}),
# dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])
# ]
# ),
# html.Div(
# className="networkx_style",
# children=[
# html.Header(title="Social Graph"),
# dcc.Dropdown(['eigenvector', 'degree', 'betweeness', 'closeness'], 'eigenvector', id='demo-dropdown'),
# "Text",
# dcc.Input(id="EGDE_VAR", type="text", value="K", debounce=True),
# # dcc.Dropdown(['eigenvector', 'degree', 'betweeness', 'closeness'], 'eigenvector', id='metric-dropdown'),
# dcc.Graph(id="my-graph"),
# ]
# )
# ]
# )
)

View File

@ -11,6 +11,38 @@ class SentimentLabel(MultiValueEnum):
NEGATIVE = -1, "negative"
NEUTRAL = 0, "neutral"
@staticmethod
def get_string_from_enum(value: int | None) -> str:
"""Translates relation name into a RelationTypeEnum.
If no translation can be found a warning is given.
Args:
relation_name: The name of the relation to be translated.
Returns:
The identified translation or None if no translation can be found.
"""
tmp = RelationTypeEnum(value)
if value is None:
raise ValueError("A relation type needs to be given.")
name = {
RelationTypeEnum.GESCHAEFTSFUEHRER: "Geschäftsführer",
RelationTypeEnum.KOMMANDITIST: "Kommanditist",
RelationTypeEnum.VORSTAND: "Vorstand",
RelationTypeEnum.PROKURIST: "Prokurist",
RelationTypeEnum.LIQUIDATOR: "Liquidator",
RelationTypeEnum.INHABER: "Inhaber",
RelationTypeEnum.PERSOENLICH_HAFTENDER_GESELLSCHAFTER: "Persönlich haftender Gesellschafter",
RelationTypeEnum.ORGANISATION: "Organisation",
RelationTypeEnum.PARTNER: "Partner",
RelationTypeEnum.DIREKTOR: "Direktor",
RelationTypeEnum.RECHTSNACHFOLGER: "Rechtsnachfolger",
}.get(tmp)
if name is not None:
return name
raise ValueError(f'Relation type "{value}" is not yet implemented!')
class FinancialKPIEnum(Enum):
"""Financial KPI keys."""