Skip to content

Commit

Permalink
GSYE-636: Reactivated HeatPumpEnergyParameters unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrostz committed Oct 11, 2023
1 parent 10833ec commit 64f3d45
Showing 1 changed file with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# pylint: disable=protected-access

from math import isclose
import pytest
from gsy_framework.constants_limits import GlobalConfig, TIME_ZONE
from gsy_framework.utils import generate_market_slot_list
from pendulum import duration, today

from gsy_e.models.strategy.energy_parameters.heat_pump import HeatPumpEnergyParameters
Expand All @@ -17,7 +19,24 @@ def fixture_heatpump_energy_params() -> HeatPumpEnergyParameters:
GlobalConfig.start_date = CURRENT_MARKET_SLOT
GlobalConfig.sim_duration = duration(days=1)
GlobalConfig.slot_length = duration(minutes=60)
yield HeatPumpEnergyParameters()

external_temp_profile = {
timestamp: 25
for timestamp in generate_market_slot_list(CURRENT_MARKET_SLOT)
}
consumption_profile = {
timestamp: 5
for timestamp in generate_market_slot_list(CURRENT_MARKET_SLOT)
}
energy_params = HeatPumpEnergyParameters(
min_temp_C=10,
max_temp_C=60,
initial_temp_C=20,
tank_volume_l=500,
external_temp_C_profile=external_temp_profile,
consumption_kWh_profile=consumption_profile,
)
yield energy_params
GlobalConfig.start_date = original_start_date
GlobalConfig.sim_duration = original_sim_duration
GlobalConfig.slot_length = original_slot_length
Expand All @@ -44,11 +63,12 @@ def test_event_market_cycle_populates_state(energy_params):
assert CURRENT_MARKET_SLOT not in energy_params.state._min_energy_demand_kWh
assert CURRENT_MARKET_SLOT not in energy_params.state._max_energy_demand_kWh
energy_params.event_market_cycle(CURRENT_MARKET_SLOT)
assert energy_params.state._temp_decrease_K[CURRENT_MARKET_SLOT] == 28.27586206896552
assert energy_params.state._storage_temp_C[CURRENT_MARKET_SLOT] == 50
assert energy_params.state._min_energy_demand_kWh[CURRENT_MARKET_SLOT] == 0.5
assert (energy_params.state._max_energy_demand_kWh[CURRENT_MARKET_SLOT] ==
0.7652439024390245)
assert energy_params.state._temp_decrease_K[CURRENT_MARKET_SLOT] == 10.0
assert energy_params.state._storage_temp_C[CURRENT_MARKET_SLOT] == 20
assert isclose(energy_params.state._min_energy_demand_kWh[CURRENT_MARKET_SLOT],
0.8865112724493694)
assert isclose(energy_params.state._max_energy_demand_kWh[CURRENT_MARKET_SLOT],
3.0)

@staticmethod
def test_event_traded_energy_decrements_posted_energy(energy_params):
Expand All @@ -57,6 +77,8 @@ def test_event_traded_energy_decrements_posted_energy(energy_params):
original_min_demand = energy_params.state._min_energy_demand_kWh[CURRENT_MARKET_SLOT]
original_max_demand = energy_params.state._max_energy_demand_kWh[CURRENT_MARKET_SLOT]
energy_params.event_traded_energy(CURRENT_MARKET_SLOT, traded_energy)
print(original_max_demand)
print(original_min_demand)
assert (energy_params.state._min_energy_demand_kWh[CURRENT_MARKET_SLOT] ==
original_min_demand - traded_energy)
assert (energy_params.state._max_energy_demand_kWh[CURRENT_MARKET_SLOT] ==
Expand All @@ -67,17 +89,19 @@ def test_event_traded_energy_updates_temp_increase(energy_params):
energy_params.event_market_cycle(CURRENT_MARKET_SLOT)
traded_energy = 0.1
energy_params.event_traded_energy(CURRENT_MARKET_SLOT, traded_energy)
assert energy_params.state._temp_increase_K[CURRENT_MARKET_SLOT] == 5.655172413793104
assert isclose(energy_params.state._temp_increase_K[CURRENT_MARKET_SLOT],
1.1280172413793106)

@staticmethod
def test_get_min_energy_demand_kWh_returns_correct_value(energy_params):
energy_params.event_market_cycle(CURRENT_MARKET_SLOT)
energy_params.get_min_energy_demand_kWh(CURRENT_MARKET_SLOT)
assert energy_params.get_min_energy_demand_kWh(CURRENT_MARKET_SLOT) == 0.5
assert isclose(energy_params.get_min_energy_demand_kWh(CURRENT_MARKET_SLOT),
0.8865112724493694)

@staticmethod
def test_get_max_energy_demand_kWh_returns_correct_value(energy_params):
energy_params.event_market_cycle(CURRENT_MARKET_SLOT)
energy_params.get_max_energy_demand_kWh(CURRENT_MARKET_SLOT)
assert (energy_params.get_max_energy_demand_kWh(CURRENT_MARKET_SLOT) ==
0.7652439024390245)
3.0)

0 comments on commit 64f3d45

Please sign in to comment.