Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions src/batcontrol/forecastsolar/baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ def get_forecast(self) -> dict[int, float]:

# Validate minimum forecast length
if self.target_resolution == 60:
min_intervals = 18 # 18 hours
min_intervals = 12 # 12 hours
else: # 15 minutes
min_intervals = 72 # 18 hours * 4 = 72 intervals
min_intervals = 48 # 12 hours * 4 = 48 intervals

max_interval = max(current_aligned_forecast.keys()) if current_aligned_forecast else 0
if max_interval < min_intervals:
logger.error('Less than 18 hours of forecast data. Got %d intervals, need %d.',
max_interval, min_intervals)
raise RuntimeError('Less than 18 hours of forecast data.')
num_intervals = len(current_aligned_forecast)
if num_intervals < min_intervals:
logger.error('Less than 12 hours of forecast data. Got %d intervals, need %d.',
num_intervals, min_intervals)
raise RuntimeError('Less than 12 hours of forecast data.')

return current_aligned_forecast

Expand Down
2 changes: 1 addition & 1 deletion tests/batcontrol/forecastsolar/test_baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def mock_forecast():
mock_forecast_func=mock_forecast
)

with pytest.raises(RuntimeError, match="Less than 18 hours"):
with pytest.raises(RuntimeError, match="Less than 12 hours"):
instance.get_forecast()

def test_base_class_not_implemented_errors(self, single_installation, timezone):
Expand Down
12 changes: 6 additions & 6 deletions tests/batcontrol/forecastsolar/test_baseclass_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_minimum_forecast_validation_hourly(self, pvinstallations, timezone):
mock_datetime.timezone = datetime.timezone

with patch.object(provider, 'refresh_data'):
with pytest.raises(RuntimeError, match="Less than 18 hours"):
with pytest.raises(RuntimeError, match="Less than 12 hours"):
provider.get_forecast()

def test_minimum_forecast_validation_15min(self, pvinstallations, timezone):
Expand All @@ -327,8 +327,8 @@ def test_minimum_forecast_validation_15min(self, pvinstallations, timezone):
target_resolution=15, native_resolution=15
)

# Set insufficient data (less than 72 intervals = 18 hours)
data_15min = {i: 250 for i in range(50)}
# Set insufficient data (less than 48 intervals = 12 hours)
data_15min = {i: 250 for i in range(40)}
provider.set_mock_data(data_15min)

mock_time = datetime.datetime(2024, 1, 1, 10, 0, 0, tzinfo=timezone)
Expand All @@ -338,7 +338,7 @@ def test_minimum_forecast_validation_15min(self, pvinstallations, timezone):
mock_datetime.timezone = datetime.timezone

with patch.object(provider, 'refresh_data'):
with pytest.raises(RuntimeError, match="Less than 18 hours"):
with pytest.raises(RuntimeError, match="Less than 12 hours"):
provider.get_forecast()


Expand Down Expand Up @@ -394,8 +394,8 @@ def test_scenario_1020_with_15min(self, pvinstallations, timezone):
assert 0 in result
assert result[0] > 0 # Should have some solar production

# Result should have many intervals (at least 72 for 18 hours)
assert len(result) >= 72
# Result should have many intervals (at least 48 for 12 hours)
assert len(result) >= 48

def test_scenario_matching_doc_example(self, pvinstallations, timezone):
"""
Expand Down