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

fix/feat(parsers, BD, BD_NP): fix to handle HTML changes and add BD_NP exchange #7746

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions config/exchanges/BD_NP.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
capacity:
- -40
- 40
lonlat:
- 88.259123
- 26.595468
parsers:
exchange: ERP_PGCB.fetch_exchange
rotation: -60
1 change: 1 addition & 0 deletions config/zones/BD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contributors:
- systemcatch
- alixunderplatz
- MuffinCompiler
- consideRatio
country: BD
delays:
production: 10
Expand Down
37 changes: 22 additions & 15 deletions parsers/ERP_PGCB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from datetime import datetime, time, timedelta
from datetime import date, datetime, time, timedelta
from logging import Logger, getLogger
from typing import Any
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -40,10 +40,12 @@
"Hydro",
"Solar",
"Wind",
"Bheramara HVDC",
"Tripura",
"Adani",
"India", # Visual grouping of India imports
"Nepal", # Import
"Remarks",
"Bheramara HVDC", # Import
"Tripura", # Import
"Adani", # Import
]
PARSER = "ERP_PGCB.py"

Expand Down Expand Up @@ -101,7 +103,8 @@ def parse_table_body(table_body: Tag) -> list[dict]:
"bd_import_bheramara": table_entry_to_float(row_items[11]),
"bd_import_tripura": table_entry_to_float(row_items[12]),
"bd_import_adani": table_entry_to_float(row_items[13]),
"remarks": row_items[14],
"bd_import_nepal": table_entry_to_float(row_items[14]),
"remarks": row_items[15],
}
)

Expand All @@ -120,8 +123,8 @@ def verify_table_header(table_header: Tag):
raise ParserException(
parser=PARSER,
message=(
f"Table headers mismatch with expected ones."
f"Expected: {TABLE_HEADERS}"
f"Table headers mismatch with expected ones.\n"
f"Expected: {TABLE_HEADERS}\n"
f"Parsed: {header_items}"
),
)
Expand All @@ -134,7 +137,7 @@ def query(
Query the table and read it into list.
"""

if target_datetime is not None and target_datetime < datetime(2015, 5, 1):
if target_datetime is not None and target_datetime.date() < date(2015, 5, 1):
raise ParserException(
parser=PARSER,
message="Data before 2015-05-01 is not reliable and will not be parsed.",
Expand Down Expand Up @@ -224,7 +227,7 @@ def fetch_production(
- row["bd_import_tripura"]
)
# Adani import was added after this date
if target_datetime is None or target_datetime > datetime(2024, 8, 27):
if target_datetime is None or target_datetime.date() > date(2024, 8, 27):
unknown_source_mw -= row["bd_import_adani"]

production.add_value(
Expand Down Expand Up @@ -293,25 +296,29 @@ def fetch_exchange(
sortedZoneKeys = ZoneKey("->".join(sorted([zone_key1, zone_key2])))

for row in row_data:
# BD -> IN_xx
if zone_key2 == "IN-NE":
# Export to India NorthEast via Tripura
# Import from India NorthEast via Tripura
bd_import = row["bd_import_tripura"]
elif zone_key2 == "IN-EA":
# Export to India East via Bheramara and Adani (Jharkhand plant)
# Import from India East via Bheramara and Adani (Jharkhand plant)
bd_import = row["bd_import_bheramara"]

if target_datetime is None or target_datetime > datetime(2024, 8, 27):
if (
target_datetime is None
or target_datetime.date() > datetime(2024, 8, 27).date()
):
bd_import += row["bd_import_adani"]

elif zone_key2 == "NP":
# Import from Nepal
bd_import = row["bd_import_nepal"]
else:
raise ParserException(
parser=PARSER,
message=f"Exchange pair {sortedZoneKeys} is not implemented.",
)

if bd_import is None:
continue # no data in table

bd_export = -1.0 * bd_import

exchange_list.append(
Expand Down
Loading
Loading