mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-24 04:52:33 +02:00
fixed sqlAlchemy and db connection
Co-authored-by: Tristan Nolde <TrisNol@users.noreply.github.com>
This commit is contained in:
parent
7420e744a5
commit
ea7c955533
@ -35,6 +35,16 @@ We decided to use english on everything close to code but will write longer text
|
||||
- python normen ([pep8](https://peps.python.org/pep-0008/)) with [flake8](https://flake8.pycqa.org/en/latest/)
|
||||
- type checking with ([mypy](https://github.com/python/mypy))
|
||||
|
||||
- Install [Python 3.11](https://www.python.org/downloads/release/python-3111/)
|
||||
- Install Poetry
|
||||
```
|
||||
pip install poetry
|
||||
```
|
||||
- Install dependencies
|
||||
```
|
||||
poetry install
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
### Connection strings
|
||||
|
404
poetry.lock
generated
404
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,7 @@ version = "0.1.0"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
SQLAlchemy = {version = "^1.4.46", extras = ["mypy"]}
|
||||
dash = "^2.11.1"
|
||||
loguru = "^0.7.0"
|
||||
matplotlib = "^3.7.1"
|
||||
plotly = "^5.14.1"
|
||||
|
1
src/aki_prj23_transparenzregister/ui/__init__.py
Normal file
1
src/aki_prj23_transparenzregister/ui/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Ui for company data."""
|
42
src/aki_prj23_transparenzregister/ui/company_stats_dash.py
Normal file
42
src/aki_prj23_transparenzregister/ui/company_stats_dash.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""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 ..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"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
app.run(debug=True)
|
@ -1,10 +1,10 @@
|
||||
"""Module containing connection utils for PostgreSQL DB."""
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.engine import URL
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
||||
from aki_prj23_transparenzregister.config.config_template import PostgreConnectionString
|
||||
from aki_prj23_transparenzregister.utils.postgres.entities import Base
|
||||
|
||||
|
||||
def get_engine(conn_args: PostgreConnectionString):
|
||||
@ -30,9 +30,7 @@ def init_db():
|
||||
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||
engine = get_engine(config_provider.get_postgre_connection_string())
|
||||
with engine.connect():
|
||||
base = declarative_base()
|
||||
|
||||
base.metadata.create_all(engine)
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""ORM entities for Prod. DB."""
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import sqlalchemy as sa
|
||||
@ -31,9 +32,17 @@ class Company(Base): # type: ignore
|
||||
|
||||
__tablename__ = "company"
|
||||
|
||||
hr = sa.Column(sa.Integer, nullable=False, primary_key=True)
|
||||
__table_args__ = (
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("hr", "court_id"),
|
||||
)
|
||||
|
||||
id = sa.Column(sa.String, primary_key=True, default=uuid.uuid4, unique=True)
|
||||
hr = sa.Column(sa.Integer, nullable=False)
|
||||
court_id = sa.Column(
|
||||
sa.Integer, sa.ForeignKey("district_court.id"), nullable=False, primary_key=True
|
||||
sa.Integer,
|
||||
sa.ForeignKey("district_court.id"),
|
||||
nullable=False,
|
||||
)
|
||||
name = sa.Column(sa.String(100), nullable=False)
|
||||
street = sa.Column(sa.String(100), nullable=False)
|
||||
@ -41,10 +50,6 @@ class Company(Base): # type: ignore
|
||||
city = sa.Column(sa.String(100), nullable=False)
|
||||
sector = sa.Column(sa.String(100), nullable=False)
|
||||
|
||||
__table_args__ = (
|
||||
sa.PrimaryKeyConstraint("hr", "court_id", name="pk_company_hr_court"),
|
||||
)
|
||||
|
||||
|
||||
class Finance(Base): # type: ignore
|
||||
"""Finance."""
|
||||
@ -52,8 +57,7 @@ class Finance(Base): # type: ignore
|
||||
__tablename__ = "finance"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company_hr = sa.Column(sa.Integer, sa.ForeignKey(Company.hr))
|
||||
company_court = sa.Column(sa.Integer, sa.ForeignKey(Company.court_id))
|
||||
company_id = sa.Column(sa.String, sa.ForeignKey("company.id"))
|
||||
date = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
total_volume = sa.Column(sa.Float)
|
||||
ebit = sa.Column(sa.Float)
|
||||
@ -75,8 +79,7 @@ class Sentiment(Base): # type: ignore
|
||||
__tablename__ = "sentiment"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company_hr = sa.Column(sa.Integer, sa.ForeignKey(Company.hr))
|
||||
company_court = sa.Column(sa.Integer, sa.ForeignKey(Company.court_id))
|
||||
company_id = sa.Column(sa.String, sa.ForeignKey("company.id"))
|
||||
date = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
sentiment_type = sa.Column(
|
||||
sa.Enum(SentimentTypeEnum),
|
||||
@ -107,8 +110,7 @@ class PersonRelation(Base): # type: ignore
|
||||
__tablename__ = "person_relation"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company_hr = sa.Column(sa.Integer, sa.ForeignKey(Company.hr))
|
||||
company_court = sa.Column(sa.Integer, sa.ForeignKey(Company.court_id))
|
||||
company_id = sa.Column(sa.String, sa.ForeignKey("company.id"))
|
||||
person_id = sa.Column(sa.Integer, sa.ForeignKey(Person.id))
|
||||
date_from = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
date_to = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
@ -126,8 +128,8 @@ class CompanyRelation(Base): # type: ignore
|
||||
__tablename__ = "company_relation"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company1_id = sa.Column(sa.Integer, nullable=False)
|
||||
company2_id = sa.Column(sa.Integer, nullable=False)
|
||||
company1_id = sa.Column(sa.String, sa.ForeignKey("company.id"), nullable=False)
|
||||
company2_id = sa.Column(sa.String, sa.ForeignKey("company.id"), nullable=False)
|
||||
date_from = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
date_to = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
relation = sa.Column(sa.Enum(RelationTypeCompanyEnum), nullable=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user