Added a test-db.drawio diagram

This commit is contained in:
Philipp Horstenkamp 2023-12-29 01:09:36 +01:00
parent 27a6bce545
commit a833439ba7
3 changed files with 294 additions and 1 deletions

View File

@ -1,3 +1,154 @@
### Database Generator (Philipp Horstenkamp)
Zur Definition eines Relationalen Datenbankschemas und zur Interation mit der
Zur Definition eines Relationalen Datenbankschemas und um zur Härtung gegen SQL-Injections wurde SQLAlchemy als SQL Interface / Driver / Abstraction layer genutzt.
SQLAlchemy sorgt dabei für ein stark dialekt unabhängiges Interface.
Auch wenn es seit einiger Zeit SQLAlchemy2 gibt haben wir uns entschieden mit Version 1.4 zu nutzen da es zur Version 2 nur wenig Dokumentation externe Dokumentation und Beispiele gab.
SQLAlchemy ist ein sehr mächtiges und beliebtes Werkzeug, leider ist die Projektdokumentation sehr undurchsichtig.
Da aber SQLAlchemy1.4 zurzeit noch gewartet wird, ist dies für dieses Projekt kein Problem.
Hier ein kurzes Beipiel einer SQL-defintion via SQLAlchemy.
Dynamicly generated
```python
AnnualFinanceStatement = type(
"AnnualFinanceStatement",
(Base,),
{
"__tablename__": "annual_finance_statement",
"id": sa.Column(sa.Integer, primary_key=True),
"company_id": sa.Column(sa.Integer, sa.ForeignKey("company.id")),
"date": sa.Column(sa.Date, nullable=False),
}
| {_.value: sa.Column(sa.Float, default="NaN") for _ in FinancialKPIEnum},
)
```
```{eval-rst}
.. drawio-figure:: test-db.drawio
:format: png
:page-index: 1
```
```{mermaid}
classDiagram
direction BT
class annual_finance_statement {
integer company_id
date date
float revenue
float net_income
float ebit
float ebitda
float gross_profit
float operating_profit
float assets
float liabilities
float equity
float current_assets
float current_liabilities
float long_term_debt
float short_term_debt
float cash_and_cash_equivalents
float dividends
float cash_flow
integer id
}
class company {
varchar hr
integer court_id
varchar(150) name
varchar(26) company_type
date founding_date
varchar business_purpose
varchar(100) street
varchar(30) house_number
varchar(5) zip_code
varchar(100) city
float longitude
float latitude
float pos_accuracy
float capital_value
varchar(13) original_currency
varchar(12) capital_type
date last_update
varchar(100) sector
integer id
}
class district_court {
varchar(100) city
varchar(100) name
integer id
}
class news {
varchar(150) title
datetime timestamp
varchar text
varchar source_url
varchar source_domain
varchar(8) overall_sentiment_label
float overall_sentiment_certainty
integer number_of_companies
integer sum_of_times_named
integer id
}
class person {
varchar(100) firstname
varchar(100) lastname
date date_of_birth
varchar(100) works_for
varchar(100) street
varchar(10) house_number
varchar(5) zip_code
varchar(100) city
float longitude
float latitude
float pos_accuracy
integer id
}
class relation {
integer company_id
date date_from
date date_to
varchar(24) relation
integer id
}
class company_relation {
integer company2_id
integer id
}
class person_relation {
integer person_id
integer id
}
class sentiment {
integer company_id
integer article_id
integer times_named
varchar(8) specific_sentiment_label
float specific_sentiment_score
integer id
}
class missing_company {
varchar(5) zip_code
varchar(100) city
integer number_of_links
boolean searched_for
varchar(150) name
}
annual_finance_statement --> company : company_id->id
company --> district_court : court_id->id
company_relation --> company : company2_id->id
company_relation --> relation : id
person_relation --> person : person_id -> id
person_relation --> relation : id
relation --> company : company_id -> id
sentiment --> company : company_id -> id
sentiment --> news : article_id -> id
```

View File

@ -0,0 +1,140 @@
<mxfile host="Electron" modified="2023-12-28T23:56:10.064Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.7.5 Chrome/114.0.5735.289 Electron/25.8.1 Safari/537.36" version="21.7.5" etag="c6GnFWleMcZyy7GyK6ET" type="device">
<diagram id="jjorYr7iqQ5mkkBvd20T" name="Seite-1">
<mxGraphModel dx="2351" dy="1374" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1" pageWidth="827" pageHeight="1169" background="none" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="node4" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;annual_finance_statement&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; company_id: integer&lt;br/&gt; date: date&lt;br/&gt; revenue: float&lt;br/&gt; net_income: float&lt;br/&gt; ebit: float&lt;br/&gt; ebitda: float&lt;br/&gt; gross_profit: float&lt;br/&gt; operating_profit: float&lt;br/&gt; assets: float&lt;br/&gt; liabilities: float&lt;br/&gt; equity: float&lt;br/&gt; current_assets: float&lt;br/&gt; current_liabilities: float&lt;br/&gt; long_term_debt: float&lt;br/&gt; short_term_debt: float&lt;br/&gt; cash_and_cash_equivalents: float&lt;br/&gt; dividends: float&lt;br/&gt; cash_flow: float&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="169" y="918" width="254" height="477" as="geometry" />
</mxCell>
<mxCell id="node3" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;company&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; hr: varchar&lt;br/&gt; court_id: integer&lt;br/&gt; name: varchar(150)&lt;br/&gt; company_type: varchar(26)&lt;br/&gt; founding_date: date&lt;br/&gt; business_purpose: varchar&lt;br/&gt; street: varchar(100)&lt;br/&gt; house_number: varchar(30)&lt;br/&gt; zip_code: varchar(5)&lt;br/&gt; city: varchar(100)&lt;br/&gt; longitude: float&lt;br/&gt; latitude: float&lt;br/&gt; pos_accuracy: float&lt;br/&gt; capital_value: float&lt;br/&gt; original_currency: varchar(13)&lt;br/&gt; capital_type: varchar(12)&lt;br/&gt; last_update: date&lt;br/&gt; sector: varchar(100)&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="250" y="120" width="212" height="477" as="geometry" />
</mxCell>
<mxCell id="node0" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;company_relation&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; company2_id: integer&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="403" y="1513" width="186" height="93" as="geometry" />
</mxCell>
<mxCell id="node7" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;district_court&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; city: varchar(100)&lt;br/&gt; name: varchar(100)&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="281" y="-238" width="150" height="118" as="geometry" />
</mxCell>
<mxCell id="node2" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;missing_company&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; zip_code: varchar(5)&lt;br/&gt; city: varchar(100)&lt;br/&gt; number_of_links: integer&lt;br/&gt; searched_for: boolean&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; name: varchar(150)&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="-20" y="-70" width="185" height="155" as="geometry" />
</mxCell>
<mxCell id="node10" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;news&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; title: varchar(150)&lt;br/&gt; timestamp: datetime&lt;br/&gt; text: varchar&lt;br/&gt; source_url: varchar&lt;br/&gt; source_domain: varchar&lt;br/&gt; overall_sentiment_label: varchar(8)&lt;br/&gt; overall_sentiment_certainty: float&lt;br/&gt; number_of_companies: integer&lt;br/&gt; sum_of_times_named: integer&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="-50" y="200" width="245" height="270" as="geometry" />
</mxCell>
<mxCell id="node8" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;person&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; firstname: varchar(100)&lt;br/&gt; lastname: varchar(100)&lt;br/&gt; date_of_birth: date&lt;br/&gt; works_for: varchar(100)&lt;br/&gt; street: varchar(100)&lt;br/&gt; house_number: varchar(10)&lt;br/&gt; zip_code: varchar(5)&lt;br/&gt; city: varchar(100)&lt;br/&gt; longitude: float&lt;br/&gt; latitude: float&lt;br/&gt; pos_accuracy: float&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="-123" y="998" width="199" height="316" as="geometry" />
</mxCell>
<mxCell id="node1" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;person_relation&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; person_id: integer&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="-67" y="1513" width="167" height="93" as="geometry" />
</mxCell>
<mxCell id="node9" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;relation&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; company_id: integer&lt;br/&gt; date_from: date&lt;br/&gt; date_to: date&lt;br/&gt; relation: varchar(24)&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="379" y="719" width="155" height="155" as="geometry" />
</mxCell>
<mxCell id="node6" value="&lt;p style=&quot;margin:0px;margin-top:4px;text-align:center;&quot;&gt;&lt;b&gt;sentiment&lt;/b&gt;&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; company_id: integer&lt;br/&gt; article_id: integer&lt;br/&gt; times_named: integer&lt;br/&gt; specific_sentiment_label: varchar(8)&lt;br/&gt; specific_sentiment_score: float&lt;/p&gt;&lt;hr size=&quot;1&quot;/&gt;&lt;p style=&quot;margin:0 0 0 4px;line-height:1.6;&quot;&gt; id: integer&lt;/p&gt;" style="verticalAlign=top;align=left;overflow=fill;fontSize=14;fontFamily=Helvetica;html=1;rounded=0;shadow=0;comic=0;labelBackgroundColor=none;strokeWidth=1;" parent="1" vertex="1">
<mxGeometry x="10" y="707" width="252" height="178" as="geometry" />
</mxCell>
<mxCell id="edge7" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.500;exitY=0.000;exitDx=0;exitDy=0;entryX=0.250;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node4" target="node3" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="296" y="636" />
<mxPoint x="303" y="636" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="edge2" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.500;exitY=0.000;exitDx=0;exitDy=0;entryX=0.500;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node3" target="node7" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points" />
</mxGeometry>
</mxCell>
<mxCell id="label14" value="court_id:id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge2" vertex="1" connectable="0">
<mxGeometry x="295" y="-6" as="geometry" />
</mxCell>
<mxCell id="edge1" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.750;exitY=0.000;exitDx=0;exitDy=0;entryX=0.750;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node0" target="node3" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="543" y="1476" />
<mxPoint x="556" y="1476" />
<mxPoint x="556" y="656" />
<mxPoint x="409" y="656" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="label8" value="company2_id:id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge1" vertex="1" connectable="0">
<mxGeometry x="465" y="1056" as="geometry" />
</mxCell>
<mxCell id="edge0" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.250;exitY=0.000;exitDx=0;exitDy=0;entryX=0.500;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node0" target="node9" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="450" y="1476" />
<mxPoint x="456" y="1476" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="label2" value="id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge0" vertex="1" connectable="0">
<mxGeometry x="436" y="1485" as="geometry" />
</mxCell>
<mxCell id="edge5" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.250;exitY=0.000;exitDx=0;exitDy=0;entryX=0.500;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node1" target="node8" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="-26" y="1476" />
<mxPoint x="-24" y="1476" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="label32" value="person_id:id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge5" vertex="1" connectable="0">
<mxGeometry x="-99" y="1466" as="geometry" />
</mxCell>
<mxCell id="edge4" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.750;exitY=0.000;exitDx=0;exitDy=0;entryX=0.500;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node1" target="node9" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="58" y="1476" />
<mxPoint x="456" y="1476" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="label26" value="id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge4" vertex="1" connectable="0">
<mxGeometry x="250" y="1456" as="geometry" />
</mxCell>
<mxCell id="edge8" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.500;exitY=0.000;exitDx=0;exitDy=0;entryX=0.250;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node9" target="node3" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="456" y="676" />
<mxPoint x="296" y="676" />
<mxPoint x="296" y="636" />
<mxPoint x="303" y="636" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="label50" value="company_id:id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge8" vertex="1" connectable="0">
<mxGeometry x="212" y="646" as="geometry" />
</mxCell>
<mxCell id="edge3" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.750;exitY=0.000;exitDx=0;exitDy=0;entryX=0.250;entryY=1.000;entryDx=0;entryDy=0;" parent="1" source="node6" target="node3" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="199" y="676" />
<mxPoint x="296" y="676" />
<mxPoint x="296" y="636" />
<mxPoint x="303" y="636" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="label20" value="company_id:id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge3" vertex="1" connectable="0">
<mxGeometry x="212" y="646" as="geometry" />
</mxCell>
<mxCell id="edge6" value="" style="html=1;rounded=1;edgeStyle=orthogonalEdgeStyle;dashed=0;startArrow=none;endArrow=block;endSize=12;strokeColor=#595959;exitX=0.250;exitY=0.000;exitDx=0;exitDy=0;entryX=0.500;entryY=1.000;entryDx=0;entryDy=0;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<Array as="points">
<mxPoint x="87" y="676" />
</Array>
<mxPoint x="87" y="707" as="sourcePoint" />
<mxPoint x="86.5" y="470" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="label38" value="article_id:id" style="edgeLabel;resizable=0;html=1;align=left;verticalAlign=top;strokeColor=default;" parent="edge6" vertex="1" connectable="0">
<mxGeometry x="6" y="666" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -47,6 +47,8 @@ Diese sind, um Industriestandards zu entsprechen, auf Englisch gehalten.
:numbered:
Ergebnisse/Abschlussbericht_und_Praesentation/PhHo/05-DEV-OPS
Ergebnisse/Abschlussbericht_und_Praesentation/PhHo/4-4-2-database-generator
.. .. toctree::
:glob: