mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
implemented storage of solar data to backend
This commit is contained in:
parent
389e9f51da
commit
693698d5de
1 changed files with 7 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue