mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Scoring scenario data against solar data
This commit is contained in:
parent
09e5b01c7e
commit
050981ae82
2 changed files with 23 additions and 11 deletions
|
|
@ -172,8 +172,18 @@ class GoogleSolarApi:
|
|||
logger.info("Storing to database")
|
||||
|
||||
scenarios_data = self.panel_performance.head(1)[
|
||||
["n_panels", "yearly_dc_energy", "total_cost", "panneled_roof_area", "array_warrage",
|
||||
"initial_ac_kwh_per_year", "lifetime_ac_kwh", "roi"]
|
||||
[
|
||||
"n_panels",
|
||||
"yearly_dc_energy",
|
||||
"total_cost",
|
||||
"panneled_roof_area",
|
||||
"array_warrage",
|
||||
"initial_ac_kwh_per_year",
|
||||
"lifetime_ac_kwh",
|
||||
"roi",
|
||||
"expected_payback_years",
|
||||
"lifetime_dc_kwh"
|
||||
]
|
||||
].rename(
|
||||
columns={
|
||||
"n_panels": "number_panels",
|
||||
|
|
@ -182,13 +192,11 @@ class GoogleSolarApi:
|
|||
"panneled_roof_area": "panelled_roof_area",
|
||||
"array_warrage": "array_kwhp",
|
||||
"initial_ac_kwh_per_year": "yearly_ac_kwh",
|
||||
"lifetime_ac_kwh": "lifetime_ac_kwh",
|
||||
}
|
||||
)
|
||||
|
||||
# Adding missing fields with default values
|
||||
scenarios_data["is_default"] = True
|
||||
scenarios_data["scenario_type"] = scenario_type
|
||||
scenarios_data = scenarios_data.to_dict(orient="records")
|
||||
|
||||
store_batch_data(
|
||||
session=session,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ def store_batch_data(session: Session, api_data: dict, uprns_to_location: list,
|
|||
:param scenarios_data: A list of dictionaries containing scenario data for each UPRN
|
||||
"""
|
||||
try:
|
||||
|
||||
# Insert data into the Solar table and get the IDs
|
||||
solar_records = []
|
||||
for data in uprns_to_location:
|
||||
|
|
@ -55,18 +56,21 @@ def store_batch_data(session: Session, api_data: dict, uprns_to_location: list,
|
|||
updated_at=datetime.datetime.now(pytz.utc)
|
||||
)
|
||||
solar_records.append(solar_record)
|
||||
session.add(solar_record)
|
||||
|
||||
session.bulk_save_objects(solar_records)
|
||||
session.commit()
|
||||
session.flush() # Flush to get the IDs generated
|
||||
|
||||
for record in solar_records:
|
||||
session.refresh(record) # Refresh to populate the ID fields
|
||||
|
||||
# Retrieve the IDs of the inserted records
|
||||
inserted_ids = [record.id for record in solar_records]
|
||||
inserted_ids = {record.uprn: record.id for record in solar_records}
|
||||
|
||||
# Prepare the data for SolarScenario
|
||||
scenario_records = []
|
||||
for index, solar_id in enumerate(inserted_ids):
|
||||
scenarios = scenarios_data[index] # Assuming scenarios_data has the same order as uprns_to_location
|
||||
for scenario in scenarios:
|
||||
for data in uprns_to_location:
|
||||
solar_id = inserted_ids.get(data['uprn'])
|
||||
for scenario in scenarios_data:
|
||||
scenario_record = SolarScenario(
|
||||
solar_id=solar_id,
|
||||
scenario_type=scenario['scenario_type'],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue