Skip to content

Commit

Permalink
Merge pull request #138 from openclimatefix/issue/add-site
Browse files Browse the repository at this point in the history
tweaks to adding site
  • Loading branch information
peterdudfield authored Jan 23, 2024
2 parents 071966a + df4b0f4 commit aa16e62
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions pv_site_api/_db_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,12 @@ 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,
capacity_kw=site.capacity_kw,
)
return pv_site

Expand Down
1 change: 1 addition & 0 deletions pv_site_api/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
9 changes: 5 additions & 4 deletions pv_site_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
MultiplePVActual,
MultipleSitePVActualCompact,
PVSiteAPIStatus,
PVSiteInputMetadata,
PVSiteMetadata,
PVSites,
)
Expand Down Expand Up @@ -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),
):
Expand All @@ -257,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"])

Expand Down
13 changes: 11 additions & 2 deletions pv_site_api/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit aa16e62

Please sign in to comment.