Skip to content

Commit

Permalink
fix for adding to site
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Oct 9, 2023
1 parent e027344 commit 578ddc1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
22 changes: 20 additions & 2 deletions src/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ def create_new_site(
latitude: float,
longitude: float,
capacity_kw: float,
created_utc: str,
dno:dict,
gsp:dict,
region:str='uk',
orientation:float=180,
tilt:float=35,
inverter_capacity_kw: Optional[float] = None,
module_capacity_kw: Optional[float] = None,
) -> SiteSQL:
"""Creates a site and adds it to the database.
:param session: database session
Expand All @@ -216,14 +222,26 @@ def create_new_site(
if max_ml_id is None:
max_ml_id = 0

if inverter_capacity_kw is None:
inverter_capacity_kw = capacity_kw

if module_capacity_kw is None:
module_capacity_kw = capacity_kw

site = SiteSQL(
ml_id=max_ml_id + 1,
client_site_id=client_site_id,
client_site_name=client_site_name,
latitude=latitude,
longitude=longitude,
capacity_kw=capacity_kw,
created_utc=created_utc,
dno=dno,
gsp=gsp,
region=region,
orientation=orientation,
tilt=tilt,
inverter_capacity_kw=inverter_capacity_kw,
module_capacity_kw=module_capacity_kw,
)

session.add(site)
Expand Down
28 changes: 10 additions & 18 deletions src/sites_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,17 @@ def sites_toolbox_page():

if st.button(f"Create new site"):
if (
client_site_id
or client_site_name
or region
or dno_formatted
or gsp_formatted
or orientation
or tilt
or latitude
or longitude
or inverter_capacity_kw
or module_capacity_kw
or capacity_kw is None
or ""
None in [client_site_id ,client_site_name,region,dno_formatted ,gsp_formatted,orientation,
tilt, latitude,longitude, inverter_capacity_kw,module_capacity_kw,capacity_kw]
):
st.write("Please check that you've entered data for each field.")
elif type(client_site_id or dno_id or gsp_id) is not int:
st.write(
"Please check that you've entered an integer for client_site_id, dno_id and gsp_id."
)
st.write(f"Please check that you've entered data for each field."
f" {client_site_id} {client_site_name} {region} {dno_formatted} "
f"{gsp_formatted} {orientation} {tilt} {latitude} {longitude} "
f"{inverter_capacity_kw} {module_capacity_kw} {capacity_kw}")
# elif type(client_site_id or dno_id or gsp_id) is not int:
# st.write(
# "Please check that you've entered an integer for client_site_id, dno_id and gsp_id."
# )
else: # create new
site, message = create_new_site(
session=session,
Expand Down

0 comments on commit 578ddc1

Please sign in to comment.