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
13 changes: 10 additions & 3 deletions src/india_api/internal/inputs/indiadb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_predicted_power_production_for_location(
"""Gets the predicted power production for a location.

Args:
location: not used
location: the location to get the predicted power production for
asset_type: The type of asset to get the forecast for
forecast_horizon: The time horizon to get the data for. Can be latest or day ahead
forecast_horizon_minutes: The number of minutes to get the forecast for. forecast_horizon must be 'horizon'
Expand All @@ -89,8 +89,15 @@ def get_predicted_power_production_for_location(
with self._get_session() as session:
sites = get_sites_by_country(session, country="india")

# just select wind site
sites = [s for s in sites if s.asset_type == asset_type]
# just select wind site and region
sites = [s for s in sites if (s.asset_type == asset_type) and (s.region == location)]

if len(sites) == 0:
raise HTTPException(
status_code=204,
detail=f"Site for {location=} not found and {asset_type=} not found",
)

site = sites[0]

# read actual generations
Expand Down
2 changes: 2 additions & 0 deletions src/india_api/internal/inputs/indiadb/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def sites(db_session):
ml_id=1,
asset_type="pv",
country="india",
region='testID'
)
db_session.add(site)
sites.append(site)
Expand All @@ -78,6 +79,7 @@ def sites(db_session):
ml_id=2,
asset_type="wind",
country="india",
region='testID'
)
db_session.add(site)
sites.append(site)
Expand Down
7 changes: 7 additions & 0 deletions src/india_api/internal/inputs/indiadb/test_indiadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def test_get_predicted_wind_power_production_for_location(
for record in result:
assert isinstance(record, PredictedPower)

def test_get_predicted_wind_power_production_for_location_raise_error(
self, client, forecast_values
) -> None:

with pytest.raises(Exception):
result = client.get_predicted_wind_power_production_for_location("testID2")

def test_get_predicted_solar_power_production_for_location(
self, client, forecast_values
) -> None:
Expand Down
Loading