Skip to content

Commit 4aefd85

Browse files
committed
fix(dummy): Correct dummyclient
1 parent 447aa8f commit 4aefd85

File tree

7 files changed

+45
-54
lines changed

7 files changed

+45
-54
lines changed

src/quartz_api/cmd/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
from starlette.responses import FileResponse
4646
from starlette.staticfiles import StaticFiles
4747

48+
from quartz_api.internal import service
4849
from quartz_api.internal.backends import DataPlatformClient, DummyClient, QuartzClient
4950
from quartz_api.internal.middleware import audit, auth
5051
from quartz_api.internal.models import DatabaseInterface, get_db_client
51-
from quartz_api.internal import service
5252

5353
log = logging.getLogger(__name__)
5454
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)

src/quartz_api/internal/backends/dataplatform/client.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,20 @@ async def save_api_call_to_db(self, url: str, authdata: dict[str, str]) -> None:
183183
async def get_substations(
184184
self,
185185
authdata: dict[str, str],
186-
) -> list[models.Site]:
186+
) -> list[models.Substation]:
187187
req = dp.ListLocationsRequest(
188188
energy_source_filter=dp.EnergySource.SOLAR,
189189
location_type_filter=dp.LocationType.PRIMARY_SUBSTATION,
190190
user_oauth_id_filter=authdata["sub"],
191191
)
192192
resp = await self.dp_client.list_locations(req)
193193
return [
194-
models.Site(
195-
site_uuid=loc.location_uuid,
196-
client_site_name=loc.location_name,
197-
orientation=loc.metadata.fields["orientation"].number_value
198-
if "orientation" in loc.metadata.fields
199-
else None,
200-
tilt=loc.metadata.fields["tilt"].number_value
201-
if "tilt" in loc.metadata.fields
202-
else None,
194+
models.Substation(
195+
substation_uuid=loc.location_uuid,
196+
substation_name=loc.location_name,
197+
substation_type="primary"
198+
if loc.location_type == dp.LocationType.PRIMARY_SUBSTATION
199+
else "unknown",
203200
capacity_kw=loc.effective_capacity_watts // 1000.0,
204201
latitude=loc.latlng.latitude,
205202
longitude=loc.latlng.longitude,
@@ -213,7 +210,6 @@ async def get_substation_forecast(
213210
substation_uuid: UUID,
214211
authdata: dict[str, str],
215212
) -> list[models.PredictedPower]:
216-
217213
# Get the substation
218214
req = dp.ListLocationsRequest(
219215
location_uuids_filter=[substation_uuid],
@@ -249,25 +245,25 @@ async def get_substation_forecast(
249245
)
250246

251247
# Scale the forecast to the substation capacity
252-
scale_factor: float = (
253-
substation.effective_capacity_watts / gsp.effective_capacity_watts
254-
)
248+
scale_factor: float = substation.effective_capacity_watts / gsp.effective_capacity_watts
255249
for value in forecast:
256250
value.PowerKW = value.PowerKW * scale_factor
257251

258252
log.debug(
259253
"gsp=%s, substation=%s, scalefactor=%s, scaling GSP to substation",
260-
gsp.location_uuid, substation.location_uuid, scale_factor,
254+
gsp.location_uuid,
255+
substation.location_uuid,
256+
scale_factor,
261257
)
262258

263259
return forecast
264260

265261
@override
266-
async def get_location(
262+
async def get_substation(
267263
self,
268264
location_uuid: UUID,
269265
authdata: dict[str, str],
270-
) -> models.SiteProperties:
266+
) -> models.SubstationProperties:
271267
req = dp.ListLocationsRequest(
272268
location_uuids_filter=[location_uuid],
273269
energy_source_filter=dp.EnergySource.SOLAR,
@@ -281,15 +277,9 @@ async def get_location(
281277
)
282278
loc = resp.locations[0]
283279

284-
return models.Site(
285-
site_uuid=loc.location_uuid,
286-
client_site_name=loc.location_name,
287-
orientation=loc.metadata.fields["orientation"].number_value
288-
if "orientation" in loc.metadata.fields
289-
else None,
290-
tilt=loc.metadata.fields["tilt"].number_value
291-
if "tilt" in loc.metadata.fields
292-
else None,
280+
return models.SubstationProperties(
281+
substation_name=loc.location_name,
282+
substation_type="primary",
293283
capacity_kw=loc.effective_capacity_watts // 1000.0,
294284
latitude=loc.latlng.latitude,
295285
longitude=loc.latlng.longitude,
@@ -339,7 +329,7 @@ async def _get_predicted_power_production_for_location(
339329
oauth_id: str | None,
340330
forecast_horizon: models.ForecastHorizon = models.ForecastHorizon.latest,
341331
forecast_horizon_minutes: int | None = None,
342-
smooth_flag: bool = True, # noqa: ARG002
332+
smooth_flag: bool = True, # noqa: ARG002
343333
) -> list[models.PredictedPower]:
344334
"""Local function to retrieve predicted values regardless of energy type."""
345335
if oauth_id is not None:

src/quartz_api/internal/backends/dataplatform/test_client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212

1313
TEST_TIMESTAMP_UTC = dt.datetime(2024, 2, 1, 12, 0, 0, tzinfo=dt.UTC)
1414

15+
1516
def mock_list_locations(req: dp.ListLocationsRequest) -> dp.ListLocationsResponse:
1617
if req.user_oauth_id_filter != "access_user":
1718
return dp.ListLocationsResponse(locations=[])
1819

1920
match req.location_type_filter:
2021
case dp.LocationType.SITE:
21-
capacity = 1e3
22+
capacity = 1e3
2223
case dp.LocationType.PRIMARY_SUBSTATION:
2324
capacity = 1e5
2425
case _:
2526
capacity = 1e6
2627

27-
2828
return dp.ListLocationsResponse(
2929
locations=[
3030
dp.ListLocationsResponseLocationSummary(
@@ -253,7 +253,7 @@ class TestCase:
253253
self.assertEqual(len(resp), tc.expected_num_substations)
254254

255255
@patch("dp_sdk.ocf.dp.DataPlatformDataServiceStub")
256-
async def test_get_location(
256+
async def test_get_substation(
257257
self,
258258
client_mock: dp.DataPlatformDataServiceStub,
259259
) -> None:
@@ -266,7 +266,7 @@ class TestCase:
266266

267267
testcases: list[TestCase] = [
268268
TestCase(
269-
name="Should return location when user has access",
269+
name="Should return substation when user has access",
270270
location_uuid=str(uuid.uuid4()),
271271
authdata={"sub": "access_user"},
272272
should_error=False,
@@ -286,12 +286,12 @@ class TestCase:
286286
with self.subTest(tc.name):
287287
if tc.should_error:
288288
with self.assertRaises(HTTPException):
289-
await client.get_location(
289+
await client.get_substation(
290290
location_uuid=tc.location_uuid,
291291
authdata=tc.authdata,
292292
)
293293
else:
294-
resp = await client.get_location(
294+
resp = await client.get_substation(
295295
location_uuid=tc.location_uuid,
296296
authdata=tc.authdata,
297297
)
@@ -350,4 +350,3 @@ class TestCase:
350350
)
351351
actual_values = [v.PowerKW for v in resp]
352352
self.assertListEqual(actual_values, tc.expected_values)
353-

src/quartz_api/internal/backends/dummydb/client.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,29 @@ async def post_site_generation(
182182
async def get_substations(
183183
self,
184184
authdata: dict[str, str],
185-
) -> list[models.Site]:
185+
) -> list[models.Substation]:
186186
uuid = str(uuid4())
187187

188-
site = models.Site(
189-
site_uuid=uuid,
190-
client_site_id=1,
188+
sub = models.Substation(
189+
substation_uuid=uuid,
190+
substation_name="Dummy Substation",
191+
substation_type="primary",
191192
latitude=26,
192193
longitude=76,
193194
capacity_kw=76,
194195
)
195196

196-
return [site]
197+
return [sub]
197198

198199
@override
199-
async def get_location(
200+
async def get_substation(
200201
self,
201202
location_uuid: str,
202203
authdata: dict[str, str],
203-
) -> models.Site:
204-
return models.Site(
205-
site_uuid=uuid4(),
206-
client_site_id=1,
204+
) -> models.SubstationProperties:
205+
return models.SubstationProperties(
206+
substation_name="Dummy Substation",
207+
substation_type="primary",
207208
latitude=26,
208209
longitude=76,
209210
capacity_kw=76,
@@ -215,7 +216,7 @@ async def get_substation_forecast(
215216
location: str,
216217
authdata: dict[str, str],
217218
) -> list[models.PredictedPower]:
218-
values = self.get_predicted_solar_power_production_for_location(location="dummy")
219+
values = await self.get_predicted_solar_power_production_for_location(location="dummy")
219220

220221
return values
221222

src/quartz_api/internal/backends/quartzdb/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ async def get_substation_forecast(
447447
raise NotImplementedError("QuartzDB backend does not support substations")
448448

449449
@override
450-
async def get_location(
450+
async def get_substation(
451451
self,
452452
location_uuid: str,
453453
auth: AuthDependency,
454-
) -> models.Site:
455-
raise NotImplementedError("QuartzDB backend does not support locations")
454+
) -> models.SubstationProperties:
455+
raise NotImplementedError("QuartzDB backend does not support substations")
456456

457457
def check_user_has_access_to_site(
458458
session: Session,

src/quartz_api/internal/models/db_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from .endpoint_types import (
1010
ActualPower,
1111
ForecastHorizon,
12-
LocationPropertiesBase,
1312
PredictedPower,
1413
Site,
1514
SiteProperties,
1615
Substation,
16+
SubstationProperties,
1717
)
1818

1919

@@ -133,12 +133,12 @@ async def get_substation_forecast(
133133
pass
134134

135135
@abc.abstractmethod
136-
async def get_location(
136+
async def get_substation(
137137
self,
138138
location_uuid: UUID,
139139
authdata: dict[str, str],
140-
) -> LocationPropertiesBase:
141-
"""Get location metadata."""
140+
) -> SubstationProperties:
141+
"""Get substation metadata."""
142142
pass
143143

144144
def get_db_client() -> DatabaseInterface:

src/quartz_api/internal/service/substations/router.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def get_substation(
3838
auth: AuthDependency,
3939
) -> models.SubstationProperties:
4040
"""Get a substation by UUID."""
41-
substation = await db.get_location(
41+
substation = await db.get_substation(
4242
location_uuid=substation_uuid,
4343
authdata=auth,
4444
)
@@ -59,3 +59,4 @@ async def get_substation_forecast(
5959
authdata=auth,
6060
)
6161
return forecast
62+

0 commit comments

Comments
 (0)