From f84882b945529d8cfb41b0b84424e7a644dfe184 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 23 Jan 2024 12:51:53 +0000 Subject: [PATCH 1/2] make seperate pvsite metadata objects, add tilt and orientation to return object --- pv_site_api/_db_helpers.py | 2 ++ pv_site_api/main.py | 5 +++-- pv_site_api/pydantic_models.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pv_site_api/_db_helpers.py b/pv_site_api/_db_helpers.py index f3ca3d0..e174b3b 100644 --- a/pv_site_api/_db_helpers.py +++ b/pv_site_api/_db_helpers.py @@ -239,6 +239,8 @@ def site_to_pydantic(site: SiteSQL) -> PVSiteMetadata: gsp=site.gsp, latitude=site.latitude, longitude=site.longitude, + tilt=site.tilt, + orientation=site.orientation, inverter_capacity_kw=site.inverter_capacity_kw, module_capacity_kw=site.module_capacity_kw, created_utc=site.created_utc, diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 7ec284b..3f8acfb 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -46,6 +46,7 @@ MultiplePVActual, MultipleSitePVActualCompact, PVSiteAPIStatus, + PVSiteInputMetadata, PVSiteMetadata, PVSites, ) @@ -244,9 +245,9 @@ def post_pv_actual( # raise Exception(NotImplemented) -@app.post("/sites", status_code=201) +@app.post("/sites", status_code=201, response_model=PVSiteMetadata) def post_site_info( - site_info: PVSiteMetadata, + site_info: PVSiteInputMetadata, session: Session = Depends(get_session), auth: dict = Depends(auth), ): diff --git a/pv_site_api/pydantic_models.py b/pv_site_api/pydantic_models.py index 645dcb1..ae561ea 100644 --- a/pv_site_api/pydantic_models.py +++ b/pv_site_api/pydantic_models.py @@ -27,8 +27,8 @@ class PVSiteAPIStatus(BaseModel): # get_sites # these are the sites available to the client given their login # schema will return a list of sites -class PVSiteMetadata(BaseModel): - """Site metadata""" +class PVSiteInputMetadata(BaseModel): + """Site metadata when adding a site""" client_site_id: str = Field(..., description="The site ID as given by the providing user.") client_site_name: str = Field( @@ -48,6 +48,15 @@ class PVSiteMetadata(BaseModel): ) +class PVSiteMetadata(PVSiteInputMetadata): + """Site metadata""" + + site_uuid: str = Field(..., description="The site's UUID") + capacity_kw: float = Field(..., description="The site's total capacity in kw", ge=0) + dno: str = Field(..., description="The site's DNO") + gsp: str = Field(..., description="The site's GSP") + + # post_pv_actual # get_pv_actual_date # posting data too the database From df4b0f42d91b1fb8c2932a247937fbc3ffbde7d1 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 23 Jan 2024 13:10:20 +0000 Subject: [PATCH 2/2] fix tests --- pv_site_api/_db_helpers.py | 1 + pv_site_api/fake.py | 1 + pv_site_api/main.py | 4 ++-- tests/test_sites.py | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pv_site_api/_db_helpers.py b/pv_site_api/_db_helpers.py index e174b3b..0fa30b8 100644 --- a/pv_site_api/_db_helpers.py +++ b/pv_site_api/_db_helpers.py @@ -244,6 +244,7 @@ def site_to_pydantic(site: SiteSQL) -> PVSiteMetadata: inverter_capacity_kw=site.inverter_capacity_kw, module_capacity_kw=site.module_capacity_kw, created_utc=site.created_utc, + capacity_kw=site.capacity_kw, ) return pv_site diff --git a/pv_site_api/fake.py b/pv_site_api/fake.py index 92fefcb..dd3417f 100644 --- a/pv_site_api/fake.py +++ b/pv_site_api/fake.py @@ -33,6 +33,7 @@ def make_fake_site() -> PVSites: longitude=0, inverter_capacity_kw=1, module_capacity_kw=1.3, + capacity_kw=1, ) pv_site_list = PVSites( site_list=[pv_site], diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 3f8acfb..1947235 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -258,8 +258,8 @@ def post_site_info( if is_fake(): print(f"Successfully added {site_info.dict()} for site {site_info.client_site_name}") - print("Not doing anything with it (yet!)") - return + site = make_fake_site().site_list[0] + return site user = get_user_by_email(session=session, email=auth["https://openclimatefix.org/email"]) diff --git a/tests/test_sites.py b/tests/test_sites.py index 7b5ada4..3264122 100644 --- a/tests/test_sites.py +++ b/tests/test_sites.py @@ -4,7 +4,7 @@ from pvsite_datamodel.sqlmodels import SiteSQL -from pv_site_api.pydantic_models import PVSiteMetadata, PVSites +from pv_site_api.pydantic_models import PVSiteInputMetadata, PVSites def test_get_site_list_fake(client, fake): @@ -48,7 +48,7 @@ def test_get_site_list_min(client, sites): def test_put_site_fake(client, fake): - pv_site = PVSiteMetadata( + pv_site = PVSiteInputMetadata( client_name="client_name_1", client_site_id="the site id used by the user", client_site_name="the site name", @@ -72,7 +72,7 @@ def test_put_site_fake(client, fake): def test_put_site(db_session, client): # make site object - pv_site = PVSiteMetadata( + pv_site = PVSiteInputMetadata( client_name="test_client", client_site_id="1", client_site_name="the site name",