Skip to content
Draft
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
148 changes: 0 additions & 148 deletions src/quartz_api/internal/eclipse.py

This file was deleted.

14 changes: 1 addition & 13 deletions src/quartz_api/internal/service/uk_national/gsp_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pydantic import AfterValidator, TypeAdapter
from starlette import status

from quartz_api.internal import eclipse, models
from quartz_api.internal import models
from quartz_api.internal.middleware.auth import AuthDependency
from quartz_api.internal.service.uk_national.metadata import format_metadata

Expand Down Expand Up @@ -123,10 +123,6 @@ async def get_forecasts_for_a_specific_gsp(
)
log.info(f"Fetched {len(pgvs)} predicted generation values for gsp_id {gsp_id}")

# gsp_id 0 is the national location; real GSPs are left alone.
if gsp_id == 0:
pgvs = eclipse.adjust_predicted_generation(pgvs, "GB")

out: list[ForecastValue] = [
ForecastValue(
target_time=pp.valid_timestamp,
Expand Down Expand Up @@ -383,14 +379,6 @@ async def get_all_available_forecasts(
]
log.info(f"Fetched predicted generation values for {len(results)} GSPs")

# Both live paths can include gsp_id 0; the pre-warmed cache path excludes it.
if 0 in gsps_to_convert:
national_uuid = gsps_to_convert[0].uuid
results = [
eclipse.adjust_national_only(snapshot, "GB", national_uuid)
for snapshot in results
]

gsp_uuid_id_map = {v.uuid: k for k, v in gsps_to_convert.items()}
if compact:
return _build_compact_response(results=results, gsp_uuid_id_map=gsp_uuid_id_map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import AfterValidator
from starlette import status

from quartz_api.internal import eclipse, models
from quartz_api.internal import models
from quartz_api.internal.middleware.auth import AuthDependency
from quartz_api.internal.service.uk_national.metadata import format_metadata

Expand Down Expand Up @@ -187,7 +187,6 @@ async def get_national_forecast(
log.info(f"Fetched {len(pgvs)} predicted generation values")

all_pgvs = sorted(all_pgvs, key=lambda x: x.valid_timestamp, reverse=False)
all_pgvs = eclipse.adjust_predicted_generation(all_pgvs, "GB")
out: list[NationalForecastValue] = [
NationalForecastValue(
target_time=v.valid_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import time_machine

from quartz_api.internal import eclipse, models
from quartz_api.internal import models

from .endpoint_types import gsp_id_map

Expand Down Expand Up @@ -235,46 +235,3 @@ async def test_national_last_updated_default(api_client, mock_storage: AsyncMock
assert kwargs["window_start"] == frozen_time - dt.timedelta(minutes=30)
assert kwargs["window_end"] == frozen_time + dt.timedelta(minutes=30)



@pytest.mark.asyncio
async def test_national_forecast_eclipse_adjustment(
api_client,
mock_storage: AsyncMock,
monkeypatch,
):
monkeypatch.setattr(eclipse, "ECLIPSE_ENABLED", True)
monkeypatch.setattr(eclipse, "ECLIPSE_DATE", dt.date(2026, 8, 12))
frozen_time = dt.datetime(2026, 8, 12, 17, 0, tzinfo=dt.UTC)

def _value(hour: int, minute: int) -> models.PredictedGenerationValue:
return models.PredictedGenerationValue(
power_kilowatts=10000.0,
valid_timestamp=dt.datetime(2026, 8, 12, hour, minute, tzinfo=dt.UTC),
location_uuid=gsp_id_map[0].uuid,
capacity_kilowatts=20000.0,
forecaster_name="blend_adjust",
forecaster_version="1.3.0",
created_timestamp=frozen_time,
init_timestamp=frozen_time,
plevels_kilowatts={"p10": 8000.0, "p90": 12000.0},
metadata={},
)

mock_storage.get_locations.return_value = [gsp_id_map[0]]
# 17:00 is before the eclipse bites, 18:00 is mid-eclipse.
mock_storage.get_predicted_generation.return_value = [_value(17, 0), _value(18, 0)]


with time_machine.travel(frozen_time, tick=False):
response = await api_client.get("/v0/solar/GB/national/forecast")

assert response.status_code == 200
before, during = response.json()

assert before["expectedPowerGenerationMegawatts"] == 10.0
# v0 rounds MW to 2dp.
assert during["expectedPowerGenerationMegawatts"] == round(10.0 * 0.566288, 2)
assert during["plevels"]["plevel_10"] == pytest.approx(8.0 * 0.566288)
assert during["plevels"]["plevel_90"] == pytest.approx(12.0 * 0.566288)
assert before["plevels"]["plevel_10"] == 8.0
8 changes: 1 addition & 7 deletions src/quartz_api/internal/service/v1/routes/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from fastapi_cache.decorator import cache
from starlette import status

from quartz_api.internal import eclipse, models
from quartz_api.internal import models
from quartz_api.internal.middleware.auth import AuthDependency

from ..cache import (
Expand Down Expand Up @@ -136,9 +136,6 @@ async def get_forecast(
),
)

if location_type == models.LocationType.NATION:
pgvs = eclipse.adjust_predicted_generation(pgvs, country.code)

first = pgvs[0] if pgvs else None
return ForecastResponse(
region_name=location_display_name(region, country),
Expand Down Expand Up @@ -286,9 +283,6 @@ async def get_forecasts_at_time(
authdata={},
)

if location_type == models.LocationType.NATION:
snapshot = eclipse.adjust_snapshot(snapshot, country.code)

region_names = {to_uuid(r.uuid): location_display_name(r, country) for r in regions}
first = snapshot[0] if snapshot else None
return ForecastSnapshot(
Expand Down
Loading
Loading