From 578ddc18169a91cbe8df625aae367925ba3495dc Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Mon, 9 Oct 2023 13:56:23 +0100 Subject: [PATCH] fix for adding to site --- src/get_data.py | 22 ++++++++++++++++++++-- src/sites_toolbox.py | 28 ++++++++++------------------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/get_data.py b/src/get_data.py index 2f50cc9..35bc55e 100644 --- a/src/get_data.py +++ b/src/get_data.py @@ -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 @@ -216,6 +222,12 @@ 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, @@ -223,7 +235,13 @@ def create_new_site( 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) diff --git a/src/sites_toolbox.py b/src/sites_toolbox.py index abff314..7f21e03 100644 --- a/src/sites_toolbox.py +++ b/src/sites_toolbox.py @@ -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,