Skip to content

Commit

Permalink
fix(US-MIDA-PJM): use appropriate timezone (#7061)
Browse files Browse the repository at this point in the history
* fix: use appropriate timezone

* fix: remove session default value

* fix: convert provided datetime to appropriate timezone

* clean up merge

---------

Co-authored-by: Viktor Andersson <30777521+VIKTORVAV99@users.noreply.github.com>
  • Loading branch information
elisezhg and VIKTORVAV99 authored Nov 14, 2024
1 parent efbca56 commit 9d95e1b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions parsers/US_PJM.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""Parser for the PJM area of the United States."""

import re
from datetime import datetime, time, timedelta, timezone
from datetime import datetime, time, timedelta
from logging import Logger, getLogger
from zoneinfo import ZoneInfo

Expand Down Expand Up @@ -103,15 +103,20 @@ def fetch_api_data(kind: str, params: dict, session: Session) -> dict:
@refetch_frequency(timedelta(days=1))
def fetch_production(
zone_key: str = "US-PJM",
session: Session = Session(),
session: Session | None = None,
target_datetime: datetime | None = None,
logger: Logger = getLogger(__name__),
) -> list:
"""uses PJM API to get generation by fuel. we assume that storage is battery storage (see https://learn.pjm.com/energy-innovations/energy-storage)"""
"""uses PJM API to get generation by fuel. we assume that storage is battery storage (see https://learn.pjm.com/energy-innovations/energy-storage)"""
if target_datetime is None:
target_datetime = datetime.now(timezone.utc).replace(
target_datetime = datetime.now(TIMEZONE).replace(
hour=0, minute=0, second=0, microsecond=0
)
else:
target_datetime = target_datetime.astimezone(TIMEZONE)

if not session:
session = Session()

params = {
"startRow": 1,
Expand Down Expand Up @@ -271,14 +276,17 @@ def combine_NY_exchanges(session: Session) -> list:
def fetch_exchange(
zone_key1: str,
zone_key2: str,
session: Session = Session(),
session: Session | None = None,
target_datetime: datetime | None = None,
logger: Logger = getLogger(__name__),
) -> list[dict] | dict:
"""Requests the last known power exchange (in MW) between two zones."""
if target_datetime is not None:
raise NotImplementedError("This parser is not yet able to parse past dates")

if not session:
session = Session()

# PJM reports exports as negative.
sortedcodes = "->".join(sorted([zone_key1, zone_key2]))

Expand Down Expand Up @@ -323,14 +331,17 @@ def fetch_exchange(

def fetch_price(
zone_key: str = "US-PJM",
session: Session = Session(),
session: Session | None = None,
target_datetime: datetime | None = None,
logger: Logger = getLogger(__name__),
) -> dict:
"""Requests the last known power price of a given country."""
if target_datetime is not None:
raise NotImplementedError("This parser is not yet able to parse past dates")

if not session:
session = Session()

res: Response = session.get(url)
soup = BeautifulSoup(res.text, "html.parser")

Expand Down

0 comments on commit 9d95e1b

Please sign in to comment.