Skip to content

Commit 2c7de28

Browse files
authored
Merge pull request #440 from OpenEnergyPlatform/hotfix-439-missing-table
Hotfix: orm model change - API & bulk
2 parents 883bb53 + 7e6565f commit 2c7de28

File tree

13 files changed

+74
-37
lines changed

13 files changed

+74
-37
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.13.0
2+
current_version = 0.13.1
33
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>(a|na))+(?P<build>\d+))?
44
serialize =
55
{major}.{minor}.{patch}{release}{build}

.github/workflows/ci-production.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: create package
3535
run: python setup.py sdist
3636
- name: import open-mastr
37-
run: python -m pip install ./dist/open_mastr-0.13.0.tar.gz
37+
run: python -m pip install ./dist/open_mastr-0.13.1.tar.gz
3838
- name: Create credentials file
3939
env:
4040
MASTR_TOKEN: ${{ secrets.MASTR_TOKEN }}

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ For each version important additions, changes and removals are listed here.
66
The format is inspired from [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
77
and the versioning aims to respect [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## [v0.13.1] Hotfix - 2023-04-11
910

11+
### Added
12+
- Add new table and new columns to the data model [#440](https://github.com/OpenEnergyPlatform/open-MaStR/pull/440)
1013
## [v0.13.0] Maintenance release - 2023-02-16
1114
### Added
1215
- Add a `workflow_dispatch` to run CI pipelines from a button click [#389](https://github.com/OpenEnergyPlatform/open-MaStR/pull/389)

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ authors:
2828
title: "open-MaStR"
2929
type: software
3030
license: AGPL-3.0
31-
version: 0.13.0
31+
version: 0.13.1
3232
doi:
33-
date-released: 2023-02-16
33+
date-released: 2023-04-11
3434
url: "https://github.com/OpenEnergyPlatform/open-MaStR/"

open_mastr/mastr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def download(
134134
"balancing_area", "Yes", "No"
135135
"permit", "Yes", "Yes"
136136
"deleted_units", "Yes", "No"
137+
"retrofit_units", "Yes", "No"
137138
138139
date: None or :class:`datetime.datetime` or str, optional
139140
For bulk method:

open_mastr/soap_api/download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ def __init__(self, parallel_processes=None):
479479
"permit_data": "GetEinheitGenehmigung",
480480
},
481481
"gsgk": {
482-
"unit_data": "GetEinheitGeoSolarthermieGrubenKlaerschlammDruckentspannung",
482+
"unit_data": "GetEinheitGeothermieGrubengasDruckentspannung",
483483
"energietraeger": [
484484
"Geothermie",
485485
"Solarthermie",
486486
"Grubengas",
487487
"Klaerschlamm",
488488
],
489489
"kwk_data": "GetAnlageKwk",
490-
"eeg_data": "GetAnlageEegGeoSolarthermieGrubenKlaerschlammDruckentspannung",
490+
"eeg_data": "GetAnlageEegGeothermieGrubengasDruckentspannung",
491491
"permit_data": "GetEinheitGenehmigung",
492492
},
493493
"nuclear": {

open_mastr/soap_api/mirror.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def retrieve_additional_data(self, data, data_type, limit=10 ** 8, chunksize=100
318318
data, requested_ids, download_functions[data_type]
319319
)
320320

321-
unit_data = flatten_dict(unit_data)
321+
unit_data = flatten_dict(unit_data, serialize_with_json=False)
322322
number_units_merged = 0
323323

324324
# Prepare data and add to database table
@@ -839,20 +839,21 @@ def _preprocess_additional_data_entry(self, unit_dat, technology, data_type):
839839
ertuechtigung["ProzentualeErhoehungDesLv"] = float(
840840
ertuechtigung["ProzentualeErhoehungDesLv"]
841841
)
842-
# The NetzbetreiberMastrNummer is handed over as type:list, hence
843-
# non-compatible with sqlite)
844-
# This replaces the list with the first (string)element in the list
845-
# to make it sqlite compatible
846-
if (
847-
"NetzbetreiberMastrNummer" in unit_dat
848-
and type(unit_dat["NetzbetreiberMastrNummer"]) == list
849-
):
850-
if len(unit_dat["NetzbetreiberMastrNummer"]) > 0:
851-
unit_dat["NetzbetreiberMastrNummer"] = unit_dat[
852-
"NetzbetreiberMastrNummer"
853-
][0]
854-
else:
855-
unit_dat["NetzbetreiberMastrNummer"] = None
842+
# Some data (data_in_list) is handed over as type:list, hence
843+
# non-compatible with sqlite or postgresql
844+
# This replaces the list with the first element in the list
845+
846+
data_as_list = ["NetzbetreiberMastrNummer","Netzbetreiberzuordnungen"]
847+
848+
for dat in data_as_list:
849+
if (
850+
dat in unit_dat
851+
and type(unit_dat[dat]) == list
852+
):
853+
if len(unit_dat[dat]) > 0:
854+
unit_dat[dat] = f"{unit_dat[dat][0]}"
855+
else:
856+
unit_dat[dat] = None
856857

857858
# Rename the typo in column zugeordneteWirkleistungWechselrichter
858859
if "zugeordneteWirkleistungWechselrichter" in unit_dat.keys():

open_mastr/utils/constants.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"balancing_area",
1717
"permit",
1818
"deleted_units",
19+
"retrofit_units",
1920
]
2021

2122
# Possible values for parameter 'data' with API download method
@@ -59,7 +60,8 @@
5960
"market_actors",
6061
"market_roles",
6162
"permit",
62-
"deleted_units"
63+
"deleted_units",
64+
"retrofit_units",
6365
]
6466

6567
# Possible data types for API download
@@ -99,6 +101,7 @@
99101
"balancing_area": ["bilanzierungsgebiete"],
100102
"permit": ["einheitengenehmigung"],
101103
"deleted_units": ["geloeschteunddeaktivierteeinheiten"],
104+
"retrofit_units": ["ertuechtigungen"],
102105
}
103106

104107
# Map bulk data to database table names, for csv export
@@ -116,6 +119,7 @@
116119
"balancing_area": ["balancing_area"],
117120
"permit": ["permit"],
118121
"deleted_units": ["deleted_units"],
122+
"retrofit_units": ["retrofit_units"],
119123
}
120124

121125
# used to map the parameter options in open-mastr to the exact table class names in orm.py
@@ -152,10 +156,7 @@
152156
"eeg_data": "HydroEeg",
153157
"permit_data": "Permit",
154158
},
155-
"nuclear": {
156-
"unit_data": "NuclearExtended",
157-
"permit_data": "Permit"
158-
},
159+
"nuclear": {"unit_data": "NuclearExtended", "permit_data": "Permit"},
159160
"storage": {
160161
"unit_data": "StorageExtended",
161162
"eeg_data": "StorageEeg",
@@ -173,11 +174,11 @@
173174
"grids": "Grids",
174175
"balancing_area": "BalancingArea",
175176
"permit": "Permit",
176-
"deleted_units": "DeletedUnits"
177+
"deleted_units": "DeletedUnits",
178+
"retrofit_units": "RetrofitUnits",
177179
}
178180

179181

180-
181182
UNIT_TYPE_MAP = {
182183
"Windeinheit": "wind",
183184
"Solareinheit": "solar",

open_mastr/utils/orm.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class BasicUnit(Base):
4242
GenMastrNummer = Column(String)
4343
BestandsanlageMastrNummer = Column(String)
4444
NichtVorhandenInMigriertenEinheiten = Column(String)
45+
EinheitSystemstatus = Column(String)
4546

4647

4748
class AdditionalDataRequested(Base):
@@ -134,6 +135,7 @@ class Extended(object):
134135
Einspeisungsart = Column(String)
135136
PraequalifiziertFuerRegelenergie = Column(Boolean)
136137
GenMastrNummer = Column(String)
138+
Netzbetreiberzuordnungen = Column(String)
137139
# from bulk download
138140
Hausnummer_nv = Column(Boolean)
139141
Weic_nv = Column(Boolean)
@@ -227,6 +229,7 @@ class CombustionExtended(Extended, ParentAllTables, Base):
227229
Einsatzort = Column(String)
228230
KwkMastrNummer = Column(String)
229231
Technologie = Column(String)
232+
AusschliesslicheVerwendungImKombibetrieb = Column(Boolean)
230233

231234

232235
class GsgkExtended(Extended, ParentAllTables, Base):
@@ -292,6 +295,7 @@ class Eeg(object):
292295
AusschreibungZuschlag = Column(Boolean)
293296
AnlagenkennzifferAnlagenregister = Column(String)
294297
AnlagenkennzifferAnlagenregister_nv = Column(Boolean)
298+
Netzbetreiberzuordnungen = Column(String)
295299

296300

297301
class WindEeg(Eeg, ParentAllTables, Base):
@@ -385,6 +389,7 @@ class Kwk(ParentAllTables, Base):
385389
VerknuepfteEinheiten = Column(String)
386390
AnlageBetriebsstatus = Column(String)
387391
AusschreibungZuschlag = Column(Boolean)
392+
Netzbetreiberzuordnungen = Column(String)
388393

389394

390395
class Permit(ParentAllTables, Base):
@@ -404,6 +409,7 @@ class Permit(ParentAllTables, Base):
404409
VerknuepfteEinheiten = Column(String)
405410
Frist_nv = Column(Boolean)
406411
WasserrechtAblaufdatum_nv = Column(Boolean)
412+
Netzbetreiberzuordnungen = Column(String)
407413

408414

409415
class LocationBasic(Base):
@@ -741,6 +747,7 @@ class Grids(ParentAllTables, Base):
741747
GeschlossenesVerteilnetz = Column(String)
742748
Bezeichnung = Column(String)
743749
Marktgebiet = Column(String)
750+
Bundesland = Column(String)
744751

745752

746753
class GridConnections(ParentAllTables, Base):
@@ -774,6 +781,18 @@ class DeletedUnits(ParentAllTables, Base):
774781
EinheitBetriebsstatus = Column(String)
775782

776783

784+
class RetrofitUnits(ParentAllTables, Base):
785+
__tablename__ = "retrofit_units"
786+
787+
Id = Column(Integer, primary_key=True)
788+
EegMastrNummer = Column(String)
789+
Leistungserhoehung = Column(Float)
790+
WiederinbetriebnahmeDatum = Column(Date)
791+
DatumLetzteAktualisierung = Column(DateTime(timezone=True))
792+
Ertuechtigungsart = Column(String)
793+
ErtuechtigungIstZulassungspflichtig = Column(Boolean)
794+
795+
777796
tablename_mapping = {
778797
"anlageneegbiomasse": {
779798
"__name__": BiomassEeg.__tablename__,
@@ -793,15 +812,15 @@ class DeletedUnits(ParentAllTables, Base):
793812
"LokationMaStRNummer": "LokationMastrNummer",
794813
},
795814
},
796-
"anlageneeggeosolarthermiegrubenklaerschlammdruckentspannung": {
815+
"anlageneeggeothermiegrubengasdruckentspannung": {
797816
"__name__": GsgkEeg.__tablename__,
798817
"__class__": GsgkEeg,
799818
"replace_column_names": {
800819
"EegMaStRNummer": "EegMastrNummer",
801820
"VerknuepfteEinheitenMaStRNummern": "VerknuepfteEinheit",
802821
},
803822
},
804-
"einheitengeosolarthermiegrubenklaerschlammdruckentspannung": {
823+
"einheitengeothermiegrubengasdruckentspannung": {
805824
"__name__": GsgkExtended.__tablename__,
806825
"__class__": GsgkExtended,
807826
"replace_column_names": {
@@ -958,6 +977,11 @@ class DeletedUnits(ParentAllTables, Base):
958977
"KwkMaStRNummer": "KwkMastrNummer",
959978
},
960979
},
980+
"ertuechtigungen": {
981+
"__name__": RetrofitUnits.__tablename__,
982+
"__class__": RetrofitUnits,
983+
"replace_column_names": None,
984+
},
961985
"geloeschteunddeaktivierteeinheiten": {
962986
"__name__": DeletedUnits.__tablename__,
963987
"__class__": DeletedUnits,

open_mastr/xml_download/utils_cleansing_bulk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def replace_mastr_katalogeintraege(
3434
"""Replaces the IDs from the mastr database by its mapped string values from
3535
the table katalogwerte"""
3636
katalogwerte = create_katalogwerte_from_bulk_download(zipped_xml_file_path)
37-
3837
for column_name in df.columns:
3938
if column_name in columns_replace_list:
4039
if df[column_name].dtype == "O":
@@ -43,6 +42,7 @@ def replace_mastr_katalogeintraege(
4342
df[column_name]
4443
.str.split(",", expand=True)
4544
.apply(lambda x: x.str.strip())
45+
.replace("", None)
4646
.astype("Int64")
4747
.applymap(katalogwerte.get)
4848
.agg(lambda d: ",".join(i for i in d if isinstance(i, str)), axis=1)

0 commit comments

Comments
 (0)