Skip to content

Commit

Permalink
refactor: switch to ProductionMix.add_value method
Browse files Browse the repository at this point in the history
Pass data to the ProductionMix object using the add_value method instead
of during object instantiaton.

Refs: electricitymaps#6011, electricitymaps#6062
  • Loading branch information
kruschk committed Nov 2, 2023
1 parent 358a14d commit 103b077
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions parsers/CA_YT.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from bs4 import BeautifulSoup
from requests import Session

from electricitymap.contrib.config import ZoneKey
from electricitymap.contrib.lib.models.event_lists import ProductionBreakdownList
from electricitymap.contrib.lib.models.events import ProductionMix, StorageMix
from electricitymap.contrib.lib.types import ZoneKey
from parsers.lib.exceptions import ParserException

SOURCE = "www.yukonenergy.ca"
Expand Down Expand Up @@ -87,24 +87,28 @@ def _parse_mw(text):
hydro_capacity = soup.find("div", class_="avail_hydro")
thermal = soup.find("div", class_="load_thermal").div

production_mix = ProductionMix()
production_mix.add_value("coal", 0)
production_mix.add_value("geothermal", 0)
production_mix.add_value(
"hydro", _parse_mw(soup.find("div", class_="load_hydro").div.text)
)
production_mix.add_value("nuclear", 0)
production_mix.add_value("unknown", _parse_mw(thermal.text) if thermal else 0)

production_breakdowns = ProductionBreakdownList(logger=logger)
production_breakdowns.append(
datetime=datetime.strptime(f"{date} {time}", "%A, %B %d, %Y %I:%M %p").replace(
tzinfo=TIMEZONE
),
production=ProductionMix(
coal=0,
geothermal=0,
hydro=_parse_mw(soup.find("div", class_="load_hydro").div.text),
nuclear=0,
unknown=_parse_mw(thermal.text) if thermal else 0,
),
production=production_mix,
source=SOURCE,
storage=StorageMix(
hydro=_parse_mw(hydro_capacity.div.text) if hydro_capacity else None
),
zoneKey=ZONE_KEY,
)

return production_breakdowns.to_list()


Expand Down

0 comments on commit 103b077

Please sign in to comment.