implemented storage of solar data to backend

This commit is contained in:
Khalim Conn-Kowlessar 2024-07-10 11:17:55 +01:00
parent 389e9f51da
commit 693698d5de

View file

@ -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(