mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-14 02:58:45 +02:00
Extracted Data-Extraction Metrhods into separate Files
This commit is contained in:
parent
e81b5fb518
commit
21c9e99ae3
@ -109,22 +109,6 @@ def networkGraph(company_id: int) -> go.Figure:
|
||||
# figure
|
||||
return go.Figure(data=[edge_trace, node_trace], layout=layout)
|
||||
|
||||
|
||||
# Dash App
|
||||
|
||||
|
||||
# app = Dash(__name__)
|
||||
|
||||
# app.title = "Dash Networkx"
|
||||
|
||||
# app.layout = html.Div(
|
||||
# [
|
||||
# html.I("Write your EDGE_VAR"),
|
||||
# html.Br(),
|
||||
# dcc.Input(id="EGDE_VAR", type="text", value="K", debounce=True),
|
||||
# dcc.Graph(id="my-graph"),
|
||||
# ]
|
||||
# )
|
||||
def networkx_component(company_id: int):
|
||||
|
||||
layout = html.Div(
|
||||
@ -135,14 +119,3 @@ def networkx_component(company_id: int):
|
||||
)
|
||||
return layout
|
||||
|
||||
# callback(
|
||||
# Output("my-graph", "figure", allow_duplicate=True),
|
||||
# [Input("EGDE_VAR", "value")],
|
||||
# prevent_initial_call=True,
|
||||
# )
|
||||
# def update_output() -> None:
|
||||
# return networkGraph()
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# app.run(debug=True)
|
||||
|
@ -4,9 +4,10 @@ from dash import html
|
||||
import pandas as pd
|
||||
import networkx as nx
|
||||
import plotly.graph_objects as go
|
||||
from dash import Dash, Input, Output, dcc, html, callback
|
||||
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
|
||||
|
||||
|
||||
dash.register_page(
|
||||
@ -20,36 +21,7 @@ dash.register_page(
|
||||
"/personendetails/",
|
||||
],
|
||||
)
|
||||
def find_all_company_relations() -> pd.DataFrame:
|
||||
session = connector.get_session(JsonFileConfigProvider("./secrets.json"))
|
||||
query_companies = session.query(entities.Company) #.all()
|
||||
query_relations = session.query(entities.CompanyRelation) # .all()
|
||||
|
||||
companies_df: pd.DataFrame = pd.read_sql(str(query_companies), session.bind) # type: ignore
|
||||
companies_relations_df: pd.DataFrame = pd.read_sql(str(query_relations), session.bind) # type: ignore
|
||||
# print(companies_relations_df)
|
||||
companies_relations_df = companies_relations_df[["relation_id","company_relation_company2_id"]]
|
||||
# print(companies_relations_df)
|
||||
company_name = []
|
||||
connected_company_name = []
|
||||
|
||||
companies_relations_df = companies_relations_df.head()
|
||||
# print(companies_relations_df)
|
||||
|
||||
for _, row in companies_relations_df.iterrows():
|
||||
# print(companies_df.loc[companies_df["company_id"] == row["relation_id"]]["company_name"].values[0])
|
||||
# print("TEst")
|
||||
company_name.append(companies_df.loc[companies_df["company_id"] == row["relation_id"]]["company_name"].values[0])
|
||||
|
||||
connected_company_name.append(companies_df.loc[companies_df["company_id"] == row["company_relation_company2_id"]]["company_name"].values[0])
|
||||
# print(connected_company_name)
|
||||
|
||||
# print(company_name)
|
||||
companies_relations_df["company_name"] = company_name
|
||||
companies_relations_df["connected_company_name"] = connected_company_name
|
||||
# print("Test")
|
||||
# print(companies_relations_df)
|
||||
return companies_relations_df
|
||||
|
||||
# Plotly figure
|
||||
def networkGraph(EGDE_VAR: None) -> go.Figure:
|
||||
@ -58,10 +30,6 @@ def networkGraph(EGDE_VAR: None) -> go.Figure:
|
||||
edges = []
|
||||
for index, row in find_all_company_relations().iterrows():
|
||||
edges.append([row["company_name"], row["connected_company_name"]])
|
||||
# print(row["company_name"], row["connected_company_name"])
|
||||
# print(edges)
|
||||
# edges = df[["relation_id","company_relation_company2_id"]]
|
||||
# edges = [[EGDE_VAR, "B"], ["B", "C"], ["B", "D"]]
|
||||
network_graph = nx.Graph()
|
||||
network_graph.add_edges_from(edges)
|
||||
pos = nx.spring_layout(network_graph)
|
||||
@ -154,14 +122,7 @@ def networkGraph(EGDE_VAR: None) -> go.Figure:
|
||||
# figure
|
||||
return go.Figure(data=[edge_trace, node_trace], layout=layout)
|
||||
|
||||
|
||||
# Dash App
|
||||
|
||||
|
||||
# app = Dash(__name__)
|
||||
|
||||
# app.title = "Dash Networkx"
|
||||
|
||||
df = find_top_companies()
|
||||
layout = html.Div(
|
||||
|
||||
children = html.Div(
|
||||
@ -169,12 +130,14 @@ layout = html.Div(
|
||||
html.Div(
|
||||
className="top_companytable_style",
|
||||
children=[
|
||||
html.I("Write your EDGE_VAR")
|
||||
html.I("Write your EDGE_VAR"),
|
||||
dash_table.DataTable(df.to_dict('records'), [{"name": i, "id": i} for i in df.columns])
|
||||
]
|
||||
),
|
||||
html.Div(
|
||||
className="networkx_style",
|
||||
children=[
|
||||
dcc.Dropdown(['eigenvector', 'degree', 'betweeness', 'closeness'], 'eigenvector', id='demo-dropdown'),
|
||||
html.I("Write your EDGE_VAR"),
|
||||
html.Br(),
|
||||
# dcc.Dropdown(['eigenvector', 'degree', 'betweeness', 'closeness'], 'eigenvector', id='metric-dropdown'),
|
||||
@ -193,4 +156,5 @@ layout = html.Div(
|
||||
[Input("EGDE_VAR", "value")],
|
||||
)
|
||||
def update_output(EGDE_VAR: None) -> None:
|
||||
find_top_companies()
|
||||
return networkGraph(EGDE_VAR)
|
||||
|
Loading…
x
Reference in New Issue
Block a user