mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-24 04:52:33 +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:
parent
105aab8122
commit
1e7e55e649
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"
|
||||
matplotlib = "^3.7.1"
|
||||
plotly = "^5.14.1"
|
||||
psycopg2 = "^2.9.7"
|
||||
psycopg2-binary = "^2.9.7"
|
||||
pymongo = "^4.4.1"
|
||||
python = "^3.11"
|
||||
seaborn = "^0.12.2"
|
||||
|
@ -1,42 +1,24 @@
|
||||
"""Dash."""
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
import plotly.express as px
|
||||
from dash import Dash, Input, Output, callback, dcc, html
|
||||
|
||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||
from dash import Dash, dash_table
|
||||
|
||||
# from ..utils.postgres.connector import get_engine, init_db
|
||||
from aki_prj23_transparenzregister.utils.postgres.connector import init_db
|
||||
|
||||
df_sample_data = pd.read_csv(
|
||||
"https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv"
|
||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||
from aki_prj23_transparenzregister.utils.postgres.connector import (
|
||||
get_session,
|
||||
)
|
||||
|
||||
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__":
|
||||
# pgConnector.init_db()
|
||||
init_db()
|
||||
logging.debug(entities.Company.name)
|
||||
session = get_session()
|
||||
query = session.query(entities.Company)
|
||||
|
||||
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)
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Module containing connection utils for PostgreSQL DB."""
|
||||
from sqlalchemy import create_engine
|
||||
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_template import PostgreConnectionString
|
||||
@ -8,7 +9,7 @@ from aki_prj23_transparenzregister.utils.postgres.entities import Base
|
||||
|
||||
|
||||
def get_engine(conn_args: PostgreConnectionString):
|
||||
"""Creates an engine connected to a Postgre instance.
|
||||
"""Creates an engine connected to a Postgres instance.
|
||||
|
||||
Returns:
|
||||
sqlalchemy.engine: connection engine
|
||||
@ -25,6 +26,14 @@ def get_engine(conn_args: PostgreConnectionString):
|
||||
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():
|
||||
"""Initialize DB with all defined entities."""
|
||||
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||
|
@ -18,7 +18,7 @@ def test_init_db():
|
||||
with patch(
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
||||
) 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(
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.JsonFileConfigProvider"
|
||||
) as mock_provider:
|
||||
|
Loading…
x
Reference in New Issue
Block a user