Added Datatable

This commit is contained in:
Tim
2023-10-30 22:54:29 +01:00
parent b594add257
commit deee0cd09d
2 changed files with 63 additions and 4 deletions

View File

@ -24,6 +24,7 @@ from aki_prj23_transparenzregister.utils.networkx.networkx_data import (
find_top_companies,
get_all_company_relations,
get_all_person_relations,
return_metric_table_df
)
@ -73,7 +74,8 @@ network = create_3d_graph(graph, nodes, edges, metrics, metric, layout, switch_n
company_relation_type_filter = get_all_person_relations()["relation_type"].unique()
person_relation_type_filter = get_all_company_relations()["relation_type"].unique()
top_companies_df = find_top_companies()
top_companies_df = return_metric_table_df(metrics, nodes, "closeness") #find_top_companies()
# with open("src/aki_prj23_transparenzregister/ui/assets/network_graph.html") as file:
# html_content = file.read()
@ -83,10 +85,31 @@ layout = html.Div(
html.Div(
className="top_companytable_style",
children=[
html.Title(title="Top Ten Unternehmen", style={"align": "mid"}),
html.H1(title="Top Ten Nodes in Graph by Metric", style={"align": "mid"}),
html.Div(
className="filter-wrapper-item",
children=[
html.H5(
className="filter-description",
children=["Filter Metric:"],
),
dcc.Dropdown(
[
"eigenvector",
"degree",
"betweeness",
"closeness",
],
"closeness",
id="dropdown_table_metric",
className="dropdown_style",
),
],
),
dash_table.DataTable(
top_companies_df.to_dict("records"),
[{"name": i, "id": i} for i in top_companies_df.columns],
id="metric_table",
),
],
),
@ -337,4 +360,17 @@ def update_figure(
return create_3d_graph(graph, nodes, edges, metrics, selected_metric, layout, switch_node_annotaion_value, switch_edge_annotaion_value, slider_value)
@callback(
Output("metric_table", "data"),
[
Input("dropdown_table_metric", "value"),
],
)
def update_table(metric_dropdown_value: str) -> dict:
table_df = return_metric_table_df(metrics, nodes, metric_dropdown_value)
table_df.to_dict("records")
# print(table_df.to_dict("records"))
columns =[{"name": i, "id": i} for i in table_df.columns]
# print(columns)
return table_df.to_dict("records")

View File

@ -353,3 +353,26 @@ def create_edge_and_node_list_for_company(
}
)
return nodes, edges
def return_metric_table_df(metrics: pd.DataFrame, nodes: dict, metric: str)-> pd.DataFrame:
# tmp = pd.DataFrame(columns=["Platzierung", "company_name", "Umsatz M€"])
tmp_list = []
category = []
for key, values in nodes.items():
# print(values["id"])
if str(values["id"]).split("_")[0] == "c":
tmp_list.append(values["name"])
category.append("company")
if str(values["id"]).split("_")[0] == "p":
tmp_list.append(str(values["firstname"]) + " " + str(values["lastname"]))
category.append("person")
metrics["designation"] = tmp_list
metrics["category"] = category
tmp_df = metrics.sort_values(metric, ascending=False)
tmp_df = tmp_df[["designation", metric, "category"]].head(10)
tmp_df.rename(columns={metric: "Metric"}, inplace=True)
# print(tmp_df[["designation", metric, "category"]].head(10))
return tmp_df