Passed
Pull Request — dev (#1112)
by
unknown
01:36
created

data.datasets.power_plants.mastr_db_classes   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 167
Duplicated Lines 35.33 %

Importance

Changes 0
Metric Value
wmc 0
eloc 124
dl 59
loc 167
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from geoalchemy2 import Geometry
2
from sqlalchemy import (
3
    Boolean,
4
    Column,
5
    DateTime,
6
    Float,
7
    Integer,
8
    Sequence,
9
    String,
10
)
11
from sqlalchemy.ext.declarative import declarative_base
12
13
Base = declarative_base()
14
15
16
class EgonMastrGeocoded(Base):
17
    __tablename__ = "egon_mastr_geocoded"
18
    __table_args__ = {"schema": "supply"}
19
20
    index = Column(
21
        Integer, Sequence("mastr_geocoded_seq"), primary_key=True, index=True
22
    )
23
    zip_and_municipality = Column(String)
24
    latitude = Column(Float)
25
    longitude = Column(Float)
26
    altitude = Column(Float)
27
    geometry = Column(Geometry("POINT", 4326))
28
29
30
class EgonPowerPlantsPv(Base):
31
    __tablename__ = "egon_power_plants_pv"
32
    __table_args__ = {"schema": "supply"}
33
34
    id = Column(Integer, Sequence("pp_pv_seq"), primary_key=True)
35
    bus_id = Column(Integer, nullable=True)  # Grid district id
36
    gens_id = Column(String, nullable=True)  # EinheitMastrNummer
37
38
    status = Column(String, nullable=True)  # EinheitBetriebsstatus
39
    commissioning_date = Column(DateTime, nullable=True)  # Inbetriebnahmedatum
40
    postcode = Column(String(5), nullable=True)  # Postleitzahl
41
    city = Column(String(50), nullable=True)  # Ort
42
    municipality = Column(String, nullable=True)  # Gemeinde
43
    federal_state = Column(String(31), nullable=True)  # Bundesland
44
    site = Column(String, nullable=True)  # Standort
45
    zip_and_municipality = Column(String, nullable=True)
46
47
    site_type = Column(String(69), nullable=True)  # Lage
48
    usage_sector = Column(String(36), nullable=True)  # Nutzungsbereich
49
    orientation_primary = Column(String(11), nullable=True)  # Hauptausrichtung
50
    orientation_primary_angle = Column(
51
        String(18), nullable=True
52
    )  # HauptausrichtungNeigungswinkel
53
    orientation_secondary = Column(
54
        String(11), nullable=True
55
    )  # Nebenausrichtung
56
    orientation_secondary_angle = Column(
57
        String(18), nullable=True
58
    )  # NebenausrichtungNeigungswinkel
59
    orientation_uniform = Column(
60
        Boolean, nullable=True
61
    )  # EinheitlicheAusrichtungUndNeigungswinkel
62
    module_count = Column(Float, nullable=True)  # AnzahlModule
63
64
    capacity = Column(Float, nullable=True)  # Nettonennleistung
65
    capacity_inverter = Column(
66
        Float, nullable=True
67
    )  # ZugeordneteWirkleistungWechselrichter in MW
68
    feedin_type = Column(String(47), nullable=True)  # Einspeisungsart
69
    voltage_level = Column(Integer, nullable=True)
70
    voltage_level_inferred = Column(Boolean, nullable=True)
71
72
    geometry_geocoded = Column(Boolean)
73
74
    geom = Column(Geometry("POINT", 4326), index=True, nullable=True)
75
76
77 View Code Duplication
class EgonPowerPlantsWind(Base):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
78
    __tablename__ = "egon_power_plants_wind"
79
    __table_args__ = {"schema": "supply"}
80
81
    id = Column(Integer, Sequence("pp_wind_seq"), primary_key=True)
82
    bus_id = Column(Integer, nullable=True)  # Grid district id
83
    gens_id = Column(String, nullable=True)  # EinheitMastrNummer
84
85
    status = Column(String, nullable=True)  # EinheitBetriebsstatus
86
    commissioning_date = Column(DateTime, nullable=True)  # Inbetriebnahmedatum
87
    postcode = Column(String(5), nullable=True)  # Postleitzahl
88
    city = Column(String(50), nullable=True)  # Ort
89
    municipality = Column(String, nullable=True)  # Gemeinde
90
    federal_state = Column(String(31), nullable=True)  # Bundesland
91
    zip_and_municipality = Column(String, nullable=True)
92
93
    site_type = Column(String(17), nullable=True)  # Lage
94
    manufacturer_name = Column(String(100), nullable=True)  # Hersteller
95
    type_name = Column(String(100), nullable=True)  # Typenbezeichnung
96
    hub_height = Column(Float, nullable=True)  # Nabenhoehe
97
    rotor_diameter = Column(Float, nullable=True)  # Rotordurchmesser
98
99
    capacity = Column(Float, nullable=True)  # Nettonennleistung
100
    feedin_type = Column(String(47), nullable=True)  # Einspeisungsart
101
    voltage_level = Column(Integer, nullable=True)
102
    voltage_level_inferred = Column(Boolean, nullable=True)
103
104
    geometry_geocoded = Column(Boolean)
105
106
    geom = Column(Geometry("POINT", 4326), index=True, nullable=True)
107
108
109 View Code Duplication
class EgonPowerPlantsBiomass(Base):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
110
    __tablename__ = "egon_power_plants_biomass"
111
    __table_args__ = {"schema": "supply"}
112
113
    id = Column(Integer, Sequence("pp_biomass_seq"), primary_key=True)
114
    bus_id = Column(Integer, nullable=True)  # Grid district id
115
    gens_id = Column(String, nullable=True)  # EinheitMastrNummer
116
117
    status = Column(String, nullable=True)  # EinheitBetriebsstatus
118
    commissioning_date = Column(DateTime, nullable=True)  # Inbetriebnahmedatum
119
    postcode = Column(String(5), nullable=True)  # Postleitzahl
120
    city = Column(String(50), nullable=True)  # Ort
121
    municipality = Column(String, nullable=True)  # Gemeinde
122
    federal_state = Column(String(31), nullable=True)  # Bundesland
123
    zip_and_municipality = Column(String, nullable=True)
124
125
    technology = Column(String(45), nullable=True)  # Technologie
126
    fuel_name = Column(String(52), nullable=True)  # Hauptbrennstoff
127
    fuel_type = Column(String(19), nullable=True)  # Biomasseart
128
129
    capacity = Column(Float, nullable=True)  # Nettonennleistung
130
    th_capacity = Column(Float, nullable=True)  # ThermischeNutzleistung
131
    feedin_type = Column(String(47), nullable=True)  # Einspeisungsart
132
    voltage_level = Column(Integer, nullable=True)
133
    voltage_level_inferred = Column(Boolean, nullable=True)
134
135
    geometry_geocoded = Column(Boolean)
136
137
    geom = Column(Geometry("POINT", 4326), index=True, nullable=True)
138
139
140
class EgonPowerPlantsHydro(Base):
141
    __tablename__ = "egon_power_plants_hydro"
142
    __table_args__ = {"schema": "supply"}
143
144
    id = Column(Integer, Sequence("pp_hydro_seq"), primary_key=True)
145
    bus_id = Column(Integer, nullable=True)  # Grid district id
146
    gens_id = Column(String, nullable=True)  # EinheitMastrNummer
147
148
    status = Column(String, nullable=True)  # EinheitBetriebsstatus
149
    commissioning_date = Column(DateTime, nullable=True)  # Inbetriebnahmedatum
150
    postcode = Column(String(5), nullable=True)  # Postleitzahl
151
    city = Column(String(50), nullable=True)  # Ort
152
    municipality = Column(String, nullable=True)  # Gemeinde
153
    federal_state = Column(String(31), nullable=True)  # Bundesland
154
    zip_and_municipality = Column(String, nullable=True)
155
156
    plant_type = Column(String(39), nullable=True)  # ArtDerWasserkraftanlage
157
    water_origin = Column(String(20), nullable=True)  # ArtDesZuflusses
158
159
    capacity = Column(Float, nullable=True)  # Nettonennleistung
160
    feedin_type = Column(String(47), nullable=True)  # Einspeisungsart
161
    voltage_level = Column(Integer, nullable=True)
162
    voltage_level_inferred = Column(Boolean, nullable=True)
163
164
    geometry_geocoded = Column(Boolean)
165
166
    geom = Column(Geometry("POINT", 4326), index=True, nullable=True)
167