From 693698d5de8eeef263954f1eca7d4aa1d26eb3f0 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 10 Jul 2024 11:17:55 +0100 Subject: [PATCH] implemented storage of solar data to backend --- backend/apis/GoogleSolarApi.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/apis/GoogleSolarApi.py b/backend/apis/GoogleSolarApi.py index 55041b74..0faf8e72 100644 --- a/backend/apis/GoogleSolarApi.py +++ b/backend/apis/GoogleSolarApi.py @@ -65,6 +65,9 @@ class GoogleSolarApi: self.panel_wattage = None self.panel_performance = None + # Indicates if we need to store the data to the db + self.need_to_store = False + def get_building_insights(self, longitude, latitude, required_quality="MEDIUM", max_retries=None): """ Make an API request to retrieve building insights based on the given longitude and latitude, with retry @@ -129,6 +132,7 @@ class GoogleSolarApi: # If we have no data in the db, or updated_at is more than 6 months if self.insights_data is None or is_outdated: self.insights_data = self.get_building_insights(longitude, latitude, required_quality) + self.need_to_store = True # Extract key data from the insights response self.roof_segments = self.insights_data["solarPotential"].get('roofSegmentStats', []) @@ -159,6 +163,9 @@ class GoogleSolarApi: if self.insights_data is None: raise ValueError("No api data to store") + if not self.need_to_store: + return + logger.info("Storing to database") store_batch_data(