Skip to content

Commit

Permalink
Scenario fails with HH multi-month
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Oct 14, 2024
1 parent f91c587 commit fc777e8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
5 changes: 3 additions & 2 deletions chellow/e/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def future_func(ns):
def make_site_deltas(
sess, report_context, site, scenario_hh, forecast_from, supply_ids
):
site_scenario_hh = scenario_hh.get(site.code, {})
site_scenario_hh_str = scenario_hh.get(site.code, {})
site_scenario_hh = {}

site_deltas = {"hhs": {}}
delts = site_deltas["supply_deltas"] = {}
Expand All @@ -97,7 +98,7 @@ def make_site_deltas(

found_hh = False
for typ in ("used", "generated", "parasitic", "gen_grid"):
hh_str = site_scenario_hh.get(typ, "")
hh_str = site_scenario_hh_str.get(typ, "")
hh_data = site_scenario_hh[typ] = {}
for row in csv.reader(StringIO(hh_str)):
cells = [cell.strip() for cell in row]
Expand Down
66 changes: 66 additions & 0 deletions test/e/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,72 @@ def filter(self, *args):
assert len(res["supply_deltas"][False]["grid"]["site"]) == 0


def test_make_site_deltas_hh_multi_month(mocker):
era_1 = mocker.Mock()
era_1.start_date = utc_datetime(2018, 1, 1)
era_1.finish_date = None
filter_returns = iter([[era_1], []])

class Sess:
def query(self, *args):
return self

def join(self, *args):
return self

def filter(self, *args):
return next(filter_returns)

sess = Sess()
report_context = {}
site = mocker.Mock()
site.code = "1"
scenario_hh = {site.code: {"used": "2019-03-01 00:00, 0"}}
forecast_from = utc_datetime(2019, 4, 1)
supply_id = None

ss = mocker.patch("chellow.e.scenario.SiteSource", autospec=True)
ss_instance = ss.return_value
ss_instance.hh_data = [
{
"start-date": utc_datetime(2019, 3, 1),
"used-kwh": 0,
"export-grid-kwh": 0,
"import-grid-kwh": 0,
"msp-kwh": 0,
}
]

se = mocker.patch("chellow.e.scenario.SiteEra", autospec=True)
se.site = mocker.Mock()

sup_s = mocker.patch("chellow.e.scenario.SupplySource", autospec=True)
sup_s_instance = sup_s.return_value
sup_s_instance.hh_data = {}

res = make_site_deltas(
sess, report_context, site, scenario_hh, forecast_from, supply_id
)
filter_returns = iter([[era_1], []])

class Sess:
def query(self, *args):
return self

def join(self, *args):
return self

def filter(self, *args):
return next(filter_returns)

sess = Sess()
res = make_site_deltas(
sess, report_context, site, scenario_hh, forecast_from, supply_id
)

assert len(res["supply_deltas"][False]["grid"]["site"]) == 0


def test_make_site_deltas_nhh(mocker):
era_1 = mocker.Mock()
era_1.start_date = utc_datetime(2018, 1, 1)
Expand Down

0 comments on commit fc777e8

Please sign in to comment.