Skip to content
Closed
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
3 changes: 3 additions & 0 deletions src/quartz_api/internal/service/uk_national/endpoint_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def convert_list_of_gsp_ids(gsp_ids:str | None) -> list[int] | None:
if gsp_ids is None:
return gsp_ids

if gsp_ids == "":
return None

return [int(gsp_id) for gsp_id in gsp_ids.split(",")]

class EnhancedBaseModel(BaseModel):
Expand Down
7 changes: 3 additions & 4 deletions src/quartz_api/internal/service/uk_national/gsp_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ async def get_all_available_forecasts(
"""
# Default (no gsp_ids): served from warm cache only. If we're here it's a cache miss —
# trigger a warm in the background and ask the client to retry.
gsp_ids = convert_list_of_gsp_ids(gsp_ids)

start_datetime_utc_set = start_datetime_utc != default_now_window_start()
end_datetime_utc_set = end_datetime_utc != default_window_end()
Expand Down Expand Up @@ -365,7 +366,7 @@ async def get_all_available_forecasts(
# gsp_ids path: custom query, fetch live.
gsps_to_convert: dict[int, models.Location] = {
k: v for k, v in gsp_id_map.items()
if k in convert_list_of_gsp_ids(gsp_ids)
if k in gsp_ids
}
tasks = [
db.get_predicted_generation(
Expand Down Expand Up @@ -567,10 +568,8 @@ async def get_truths_for_all_gsps(
- **start_datetime_utc**: optional start datetime for the query.
- **end_datetime_utc**: optional end datetime for the query.
"""
# Why not just make the endpoint type list[int] and let fast API do this?
gsp_ids: list[int] | None = convert_list_of_gsp_ids(gsp_ids)
out: list[GSPYieldGroupByDatetime] = []

gsp_ids = convert_list_of_gsp_ids(gsp_ids)
gsp_uuid_id_map: dict[UUID, int] = {v.uuid: k for k, v in gsp_id_map.items()}

if gsp_ids is None:
Expand Down
Loading