mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-22 04:23:56 +02:00
Visualization first running dashboard (#51)
* added session maker * Update prebuild psycopg-build2 * added table dash * Update company_stats_dash * Repaired a test. * update connector_test --------- Co-authored-by: Tim <tim.ronneburg@outlook.de> Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de>
This commit is contained in:
8361
poetry.lock
generated
8361
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -34,7 +34,7 @@ dash = "^2.11.1"
|
|||||||
loguru = "^0.7.0"
|
loguru = "^0.7.0"
|
||||||
matplotlib = "^3.7.1"
|
matplotlib = "^3.7.1"
|
||||||
plotly = "^5.14.1"
|
plotly = "^5.14.1"
|
||||||
psycopg2 = "^2.9.7"
|
psycopg2-binary = "^2.9.7"
|
||||||
pymongo = "^4.4.1"
|
pymongo = "^4.4.1"
|
||||||
python = "^3.11"
|
python = "^3.11"
|
||||||
seaborn = "^0.12.2"
|
seaborn = "^0.12.2"
|
||||||
|
@ -1,42 +1,24 @@
|
|||||||
"""Dash."""
|
"""Dash."""
|
||||||
import logging
|
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.express as px
|
from dash import Dash, dash_table
|
||||||
from dash import Dash, Input, Output, callback, dcc, html
|
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
|
||||||
|
|
||||||
# from ..utils.postgres.connector import get_engine, init_db
|
# from ..utils.postgres.connector import get_engine, init_db
|
||||||
from aki_prj23_transparenzregister.utils.postgres.connector import init_db
|
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||||
|
from aki_prj23_transparenzregister.utils.postgres.connector import (
|
||||||
df_sample_data = pd.read_csv(
|
get_session,
|
||||||
"https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
app = Dash(__name__)
|
|
||||||
|
|
||||||
app.layout = html.Div(
|
|
||||||
[
|
|
||||||
html.H1(children="Title of Dash App", style={"textAlign": "center"}),
|
|
||||||
dcc.Dropdown(
|
|
||||||
df_sample_data.country.unique(), "Canada", id="dropdown-selection"
|
|
||||||
),
|
|
||||||
dcc.Graph(id="graph-content"),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@callback(Output("graph-content", "figure"), Input("dropdown-selection", "value"))
|
|
||||||
def update_graph(value):
|
|
||||||
"""Update the graph with a value - thanks linter..."""
|
|
||||||
dff = df_sample_data[df_sample_data.country == value]
|
|
||||||
return px.line(dff, x="year", y="pop")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# pgConnector.init_db()
|
session = get_session()
|
||||||
init_db()
|
query = session.query(entities.Company)
|
||||||
logging.debug(entities.Company.name)
|
|
||||||
|
companies_df = pd.read_sql(str(query), session.bind)
|
||||||
|
app = Dash(__name__)
|
||||||
|
|
||||||
|
app.layout = dash_table.DataTable(
|
||||||
|
companies_df.to_dict("records"),
|
||||||
|
[{"name": i, "id": i} for i in companies_df.columns],
|
||||||
|
)
|
||||||
|
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Module containing connection utils for PostgreSQL DB."""
|
"""Module containing connection utils for PostgreSQL DB."""
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.engine import URL
|
from sqlalchemy.engine import URL
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
||||||
from aki_prj23_transparenzregister.config.config_template import PostgreConnectionString
|
from aki_prj23_transparenzregister.config.config_template import PostgreConnectionString
|
||||||
@ -8,7 +9,7 @@ from aki_prj23_transparenzregister.utils.postgres.entities import Base
|
|||||||
|
|
||||||
|
|
||||||
def get_engine(conn_args: PostgreConnectionString):
|
def get_engine(conn_args: PostgreConnectionString):
|
||||||
"""Creates an engine connected to a Postgre instance.
|
"""Creates an engine connected to a Postgres instance.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
sqlalchemy.engine: connection engine
|
sqlalchemy.engine: connection engine
|
||||||
@ -25,6 +26,14 @@ def get_engine(conn_args: PostgreConnectionString):
|
|||||||
return create_engine(url)
|
return create_engine(url)
|
||||||
|
|
||||||
|
|
||||||
|
def get_session():
|
||||||
|
"""Return PG Session."""
|
||||||
|
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||||
|
engine = get_engine(config_provider.get_postgre_connection_string())
|
||||||
|
session = sessionmaker(bind=engine)
|
||||||
|
return session()
|
||||||
|
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
"""Initialize DB with all defined entities."""
|
"""Initialize DB with all defined entities."""
|
||||||
config_provider = JsonFileConfigProvider("./secrets.json")
|
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||||
|
@ -18,7 +18,7 @@ def test_init_db():
|
|||||||
with patch(
|
with patch(
|
||||||
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
||||||
) as mock_get_engine, patch(
|
) as mock_get_engine, patch(
|
||||||
"aki_prj23_transparenzregister.utils.postgres.connector.declarative_base"
|
"aki_prj23_transparenzregister.utils.postgres.entities.declarative_base"
|
||||||
) as mock_declarative_base, patch(
|
) as mock_declarative_base, patch(
|
||||||
"aki_prj23_transparenzregister.utils.postgres.connector.JsonFileConfigProvider"
|
"aki_prj23_transparenzregister.utils.postgres.connector.JsonFileConfigProvider"
|
||||||
) as mock_provider:
|
) as mock_provider:
|
||||||
|
Reference in New Issue
Block a user