Skip to content

Commit

Permalink
+mRID parameter for query_unavailability
Browse files Browse the repository at this point in the history
Added mRID as a parameter to the query_unavailability_ ... functions to enable users to fetch previous revisions of documents
  • Loading branch information
tng_alwa committed Mar 27, 2024
1 parent 4560a5d commit f9773fa
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions entsoe/entsoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ def _query_unavailability(
end: pd.Timestamp, doctype: str, docstatus: Optional[str] = None,
periodstartupdate: Optional[pd.Timestamp] = None,
periodendupdate: Optional[pd.Timestamp] = None,
mRID=None,
offset: int = 0) -> bytes:
"""
Generic unavailibility query method.
Expand Down Expand Up @@ -979,6 +980,8 @@ def _query_unavailability(
params['periodStartUpdate'] = self._datetime_to_str(
periodstartupdate)
params['periodEndUpdate'] = self._datetime_to_str(periodendupdate)
if mRID:
params['mRID'] = mRID
response = self._base_request(params=params, start=start, end=end)
return response.content

Expand All @@ -987,6 +990,7 @@ def query_unavailability_of_generation_units(
end: pd.Timestamp, docstatus: Optional[str] = None,
periodstartupdate: Optional[pd.Timestamp] = None,
periodendupdate: Optional[pd.Timestamp] = None,
mRID = None,
offset: int = 0) -> bytes:
"""
This endpoint serves ZIP files.
Expand All @@ -1010,14 +1014,15 @@ def query_unavailability_of_generation_units(
content = self._query_unavailability(
country_code=country_code, start=start, end=end, doctype="A80",
docstatus=docstatus, periodstartupdate=periodstartupdate,
periodendupdate=periodendupdate, offset=offset)
periodendupdate=periodendupdate, mRID=mRID, offset=offset)
return content

def query_unavailability_of_production_units(
self, country_code: Union[Area, str], start: pd.Timestamp,
end: pd.Timestamp, docstatus: Optional[str] = None,
periodstartupdate: Optional[pd.Timestamp] = None,
periodendupdate: Optional[pd.Timestamp] = None) -> bytes:
periodendupdate: Optional[pd.Timestamp] = None,
mRID: Optional[str] = None) -> bytes:
"""
This endpoint serves ZIP files.
The query is limited to 200 items per request.
Expand All @@ -1038,7 +1043,8 @@ def query_unavailability_of_production_units(
content = self._query_unavailability(
country_code=country_code, start=start, end=end, doctype="A77",
docstatus=docstatus, periodstartupdate=periodstartupdate,
periodendupdate=periodendupdate)
periodendupdate=periodendupdate,
mRID = mRID)
return content

def query_unavailability_transmission(
Expand Down Expand Up @@ -1088,7 +1094,7 @@ def query_unavailability_transmission(

def query_withdrawn_unavailability_of_generation_units(
self, country_code: Union[Area, str], start: pd.Timestamp,
end: pd.Timestamp) -> bytes:
end: pd.Timestamp, mRID: Optional[str] = None) -> bytes:
"""
Parameters
----------
Expand All @@ -1102,7 +1108,7 @@ def query_withdrawn_unavailability_of_generation_units(
"""
content = self._query_unavailability(
country_code=country_code, start=start, end=end,
doctype="A80", docstatus='A13')
doctype="A80", docstatus='A13', mRID=mRID)
return content

class EntsoePandasClient(EntsoeRawClient):
Expand Down Expand Up @@ -1930,6 +1936,7 @@ def _query_unavailability(
end: pd.Timestamp, doctype: str, docstatus: Optional[str] = None,
periodstartupdate: Optional[pd.Timestamp] = None,
periodendupdate: Optional[pd.Timestamp] = None,
mRID: Optional[str] = None,
offset: int = 0) -> pd.DataFrame:
"""
Parameters
Expand All @@ -1951,7 +1958,7 @@ def _query_unavailability(
content = super(EntsoePandasClient, self)._query_unavailability(
country_code=area, start=start, end=end, doctype=doctype,
docstatus=docstatus, periodstartupdate=periodstartupdate,
periodendupdate=periodendupdate, offset=offset)
periodendupdate=periodendupdate, mRID=mRID, offset=offset)
df = parse_unavailabilities(content, doctype)
df = df.tz_convert(area.tz)
df['start'] = df['start'].apply(lambda x: x.tz_convert(area.tz))
Expand All @@ -1963,7 +1970,8 @@ def query_unavailability_of_generation_units(
self, country_code: Union[Area, str], start: pd.Timestamp,
end: pd.Timestamp, docstatus: Optional[str] = None,
periodstartupdate: Optional[pd.Timestamp] = None,
periodendupdate: Optional[pd.Timestamp] = None) -> pd.DataFrame:
periodendupdate: Optional[pd.Timestamp] = None,
mRID = None) -> pd.DataFrame:
"""
Parameters
----------
Expand All @@ -1981,14 +1989,15 @@ def query_unavailability_of_generation_units(
df = self._query_unavailability(
country_code=country_code, start=start, end=end, doctype="A80",
docstatus=docstatus, periodstartupdate=periodstartupdate,
periodendupdate=periodendupdate)
periodendupdate=periodendupdate, mRID=mRID)
return df

def query_unavailability_of_production_units(
self, country_code: Union[Area, str], start: pd.Timestamp,
end: pd.Timestamp, docstatus: Optional[str] = None,
periodstartupdate: Optional[pd.Timestamp] = None,
periodendupdate: Optional[pd.Timestamp] = None) -> pd.DataFrame:
periodendupdate: Optional[pd.Timestamp] = None,
mRID: Optional[str] = None) -> pd.DataFrame:
"""
Parameters
----------
Expand All @@ -2006,7 +2015,7 @@ def query_unavailability_of_production_units(
df = self._query_unavailability(
country_code=country_code, start=start, end=end, doctype="A77",
docstatus=docstatus, periodstartupdate=periodstartupdate,
periodendupdate=periodendupdate)
periodendupdate=periodendupdate, mRID=mRID)
return df

@paginated
Expand Down

0 comments on commit f9773fa

Please sign in to comment.