From 01c688da23de301b5d1b63d94a0485e7158a67a5 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 19 Aug 2024 21:38:53 +0100 Subject: [PATCH] debugging solar api --- backend/apis/GoogleSolarApi.py | 22 ++++++++++++++++++++-- backend/app/plan/router.py | 5 ++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/apis/GoogleSolarApi.py b/backend/apis/GoogleSolarApi.py index 905d4975..13c7abb4 100644 --- a/backend/apis/GoogleSolarApi.py +++ b/backend/apis/GoogleSolarApi.py @@ -258,7 +258,7 @@ class GoogleSolarApi: # Remove any north facing roof segments panel_performance = [] - for config in self.insights_data["solarPotential"]["solarPanelConfigs"]: + for config in self.insights_data["solarPotential"].get("solarPanelConfigs", []): roof_segment_summaries = config["roofSegmentSummaries"] # Filter on just the segments in self.roof_segment_indexes roof_segment_summaries = [ @@ -310,7 +310,25 @@ class GoogleSolarApi: ) panel_performance = pd.DataFrame(panel_performance) - # We can have duplicate configurations + + if panel_performance.empty: + self.panel_performance = pd.DataFrame( + columns=[ + "n_panels", + "yearly_dc_energy", + "total_cost", + "panneled_roof_area", + "array_wattage", + "initial_ac_kwh_per_year", + "lifetime_ac_kwh", + "roi", + "expected_payback_years", + "lifetime_dc_kwh" + ] + ) + return + + # We can have duplicate configurations panel_performance = panel_performance.drop_duplicates() # If we look at the building level, we don't include any projects fewer than 10 panels, otherwise the # minimum is 4 diff --git a/backend/app/plan/router.py b/backend/app/plan/router.py index a4292265..e773e303 100644 --- a/backend/app/plan/router.py +++ b/backend/app/plan/router.py @@ -472,8 +472,6 @@ async def trigger_plan(body: PlanTriggerRequest): materials = get_materials(session) cleaned = get_cleaned() - solar_api_client = GoogleSolarApi(api_key=get_settings().GOOGLE_SOLAR_API_KEY) - dataset_version = "2024-07-08" energy_consumption_client = EnergyConsumptionModel( model_paths={ @@ -588,6 +586,7 @@ async def trigger_plan(body: PlanTriggerRequest): energy_consumption = sum( [entry['energy_consumption'] for entry in building_ids if entry['building_id'] == building_id] ) + solar_api_client = GoogleSolarApi(api_key=get_settings().GOOGLE_SOLAR_API_KEY) solar_api_client.get( longitude=coordinates["longitude"], latitude=coordinates["latitude"], @@ -629,7 +628,7 @@ async def trigger_plan(body: PlanTriggerRequest): # We check if we have a solar non-invasive recommendation if [r for r in property_instance.non_invasive_recommendations if r["type"] == "solar_pv"]: continue - + solar_api_client = GoogleSolarApi(api_key=get_settings().GOOGLE_SOLAR_API_KEY) solar_api_client.get( longitude=unit["longitude"], latitude=unit["latitude"],