Skip to content

Commit

Permalink
switch more functions to the new generic parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
fboerman committed Dec 20, 2023
1 parent a62e858 commit 5cfe3b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 61 deletions.
2 changes: 1 addition & 1 deletion entsoe/entsoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ def query_aggregate_water_reservoirs_and_hydro_storage(self, country_code: Union
self).query_aggregate_water_reservoirs_and_hydro_storage(
country_code=area, start=start, end=end)

df = parse_water_hydro(text, area.tz)
df = parse_water_hydro(text)

return df

Expand Down
66 changes: 6 additions & 60 deletions entsoe/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import pandas as pd

from .mappings import PSRTYPE_MAPPINGS, DOCSTATUS, BSNTYPE, Area
from .series_parsers import _extract_timeseries, _resolution_to_timedelta, _parse_datetimeindex, _parse_timeseries_generic
from .series_parsers import _extract_timeseries, _resolution_to_timedelta, _parse_datetimeindex, _parse_timeseries_generic,\
_parse_timeseries_generic_whole

warnings.filterwarnings('ignore', category=XMLParsedAsHTMLWarning)

Expand Down Expand Up @@ -223,7 +224,7 @@ def parse_installed_capacity_per_plant(xml_text):
return df


def parse_water_hydro(xml_text, tz):
def parse_water_hydro(xml_text):
"""
Parameters
----------
Expand All @@ -233,13 +234,8 @@ def parse_water_hydro(xml_text, tz):
-------
pd.Series
"""
all_series = []
for soup in _extract_timeseries(xml_text):
all_series.append(_parse_water_hydro_timeseries(soup, tz=tz))

series = pd.concat(all_series)

return series
return _parse_timeseries_generic_whole(xml_text)


def parse_crossborder_flows(xml_text):
Expand Down Expand Up @@ -683,17 +679,7 @@ def _parse_load_timeseries(soup):
-------
pd.Series
"""
positions = []
prices = []
for point in soup.find_all('point'):
positions.append(int(point.find('position').text))
prices.append(float(point.find('quantity').text))

series = pd.Series(index=positions, data=prices)
series = series.sort_index()
series.index = _parse_datetimeindex(soup)

return series
return _parse_timeseries_generic(soup)

def _parse_generation_timeseries(soup, per_plant: bool = False, include_eic: bool = False) -> pd.Series:
"""
Expand All @@ -708,19 +694,7 @@ def _parse_generation_timeseries(soup, per_plant: bool = False, include_eic: boo
-------
pd.Series
"""
positions = []
quantities = []
for point in soup.find_all('point'):
positions.append(int(point.find('position').text))
quantity = point.find('quantity')
if quantity is None:
raise LookupError(
f'No quantity found in this point, it should have one: {point}')
quantities.append(float(quantity.text))

series = pd.Series(index=positions, data=quantities)
series = series.sort_index()
series.index = _parse_datetimeindex(soup)
series = _parse_timeseries_generic(soup)

# Check if there is a psrtype, if so, get it.
_psrtype = soup.find('psrtype')
Expand Down Expand Up @@ -763,34 +737,6 @@ def _parse_generation_timeseries(soup, per_plant: bool = False, include_eic: boo

return series

def _parse_water_hydro_timeseries(soup, tz):
"""
Parses timeseries for water reservoirs and hydro storage plants
Parameters
----------
soup : bs4.element.tag
Returns
-------
pd.Series
"""

positions = []
quantities = []
for point in soup.find_all('point'):
positions.append(int(point.find('position').text))
quantity = point.find('quantity')
if quantity is None:
raise LookupError(
f'No quantity found in this point, it should have one: {point}')
quantities.append(float(quantity.text))
series = pd.Series(index=positions, data=quantities)
series = series.sort_index()
series.index = _parse_datetimeindex(soup, tz)

return series

def _parse_installed_capacity_per_plant(soup):
"""
Parameters
Expand Down

0 comments on commit 5cfe3b6

Please sign in to comment.