Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pumping storage fix for CZ parser #7530

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 66 additions & 4 deletions parsers/CZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,51 @@ def __get_exchange_data(
return exchanges.to_list()


def get_pumping_load(
zone_key: ZoneKey = ZoneKey("CZ"),
session: Session = Session(),
target_datetime: datetime | None = None,
logger: Logger = getLogger(__name__),
) -> list:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the return type list.

target_datetime = get_target_datetime(target_datetime)
from_datetime = target_datetime - timedelta(hours=48)

payload = """<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Load xmlns="https://www.ceps.cz/CepsData/">
<dateFrom>{}</dateFrom>
<dateTo>{}</dateTo>
<agregation>{}</agregation>
<function>{}</function>
<version>{}</version>
</Load>
</soap12:Body>
</soap12:Envelope>""".format(
from_datetime.isoformat(), target_datetime.isoformat(), "QH", "AVG", "RT"
)

content = make_request(session, payload, zone_key).text
xml = BeautifulSoup(content, "xml")
data_tag = xml.find("data")
pumping_load_at_time_dict = {}

if data_tag is not None:
for values in data_tag:
pumping_load_at_time_dict[values["date"]] = float(values["value1"]) - float(
values["value2"]
)
Comment on lines +174 to +177
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also contains type errors. Such as "__getitem__" method not defined on type "PageElement"


else:
ParserException(
"CZ.py",
f"There was no pumping load data returned for {zone_key} at {target_datetime}",
zone_key,
)

return pumping_load_at_time_dict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is returning a dict.



@refetch_frequency(timedelta(days=2))
def fetch_production(
zone_key: ZoneKey = ZoneKey("CZ"),
Expand Down Expand Up @@ -174,17 +219,28 @@ def fetch_production(
data_tag = xml.find("data")
production_breakdowns = ProductionBreakdownList(logger)

pumping_load_at_time = get_pumping_load(
zone_key=zone_key,
session=session,
target_datetime=target_datetime,
logger=logger,
)

if data_tag is not None:
for values in data_tag:
production = ProductionMix()
storage = StorageMix()

for k, v in mapper.items():
generator = translate_table_gen[k]
if k != "PsPP":
production.add_value(mode=generator, value=float(values[v]))
else:
storage.add_value(mode=generator, value=float(values[v]) * -1)
pumping_storage = float(values[v]) * -1
if values["date"] in pumping_load_at_time:
pumping_storage += pumping_load_at_time[values["date"]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you summing things up here?

If there are multiple storage entries they should be looped over and add_value should be called on each of them as it handles summing up values of the same type.

storage.add_value(mode=generator, value=float(pumping_storage))

# # sum production to get

production_breakdowns.append(
zoneKey=zone_key,
Expand Down Expand Up @@ -233,10 +289,16 @@ def fetch_exchange_forecast(
"""Main method, never used by the Electricity Map backend, but handy for testing."""

# print("fetch_production() ->")
print(fetch_production())
# temp = fetch_production()
# for i in temp:
# print(i['storage'], i['datetime'])
# print(fetch_production())
# print(get_pumping_load())
# print("fetch_price() ->")
# print(fetch_price())
# print("fetch_exchange_forecast('AT', 'CZ') ->")
# print(fetch_exchange_forecast("AT", "CZ"))
print("fetch_exchange('AT', 'CZ') ->")
print(fetch_exchange(ZoneKey("AT"), ZoneKey("CZ")))
# print("fetch_exchange('AT', 'CZ') ->")
# print(fetch_exchange(ZoneKey("AT"), ZoneKey("CZ")))
# print(get_pumping_load)
Loading