mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
added solar api back
This commit is contained in:
parent
d032263857
commit
a5e6dc3399
2 changed files with 101 additions and 100 deletions
|
|
@ -738,12 +738,11 @@ class Property:
|
||||||
k: AnnualBillSavings.adjust_energy_to_metered(
|
k: AnnualBillSavings.adjust_energy_to_metered(
|
||||||
epc_energy=v,
|
epc_energy=v,
|
||||||
current_epc_rating=self.data["current-energy-rating"],
|
current_epc_rating=self.data["current-energy-rating"],
|
||||||
) for k, v in unadjusted_heating_costs.items()
|
) for k, v in unadjusted_heating_costs.items() if v is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sum up the adjusted kwh figures
|
# Sum up the adjusted kwh figures
|
||||||
self.current_adjusted_energy = sum(list(adjusted_kwh_estimates.values()))
|
self.current_adjusted_energy = sum(list(adjusted_kwh_estimates.values()))
|
||||||
self.current_energy_bill = sum(list(adjusted_heating_costs.values()))
|
|
||||||
|
|
||||||
self.energy_cost_estimates = {
|
self.energy_cost_estimates = {
|
||||||
"adjusted": adjusted_heating_costs,
|
"adjusted": adjusted_heating_costs,
|
||||||
|
|
|
||||||
|
|
@ -470,7 +470,6 @@ async def trigger_plan(body: PlanTriggerRequest):
|
||||||
# extensions, since it doesn't seem to do a great job
|
# extensions, since it doesn't seem to do a great job
|
||||||
# TODO: For simple properties, we should do a comparison/check between the solar API's roof area and the
|
# TODO: For simple properties, we should do a comparison/check between the solar API's roof area and the
|
||||||
# basic estimate of roof area
|
# basic estimate of roof area
|
||||||
# TODO: TEMP SWITCHED OFF
|
|
||||||
building_ids = [
|
building_ids = [
|
||||||
{
|
{
|
||||||
"building_id": p.building_id,
|
"building_id": p.building_id,
|
||||||
|
|
@ -508,112 +507,115 @@ async def trigger_plan(body: PlanTriggerRequest):
|
||||||
"uprn": p.uprn
|
"uprn": p.uprn
|
||||||
} for p in input_properties if p.building_id is None
|
} for p in input_properties if p.building_id is None
|
||||||
]
|
]
|
||||||
if False:
|
if building_ids:
|
||||||
if building_ids:
|
# Find the unique longitude and latitude pairs for each building id
|
||||||
# Find the unique longitude and latitude pairs for each building id
|
unique_coordinates = {}
|
||||||
unique_coordinates = {}
|
building_uprns = {}
|
||||||
building_uprns = {}
|
for entry in building_ids:
|
||||||
for entry in building_ids:
|
building_id = entry['building_id']
|
||||||
building_id = entry['building_id']
|
coordinate_pair = {'longitude': entry['longitude'], 'latitude': entry['latitude']}
|
||||||
coordinate_pair = {'longitude': entry['longitude'], 'latitude': entry['latitude']}
|
|
||||||
|
|
||||||
if building_id not in unique_coordinates:
|
if building_id not in unique_coordinates:
|
||||||
unique_coordinates[building_id] = []
|
unique_coordinates[building_id] = []
|
||||||
|
|
||||||
if coordinate_pair not in unique_coordinates[building_id]:
|
if coordinate_pair not in unique_coordinates[building_id]:
|
||||||
unique_coordinates[building_id].append(coordinate_pair)
|
unique_coordinates[building_id].append(coordinate_pair)
|
||||||
|
|
||||||
if building_id not in building_uprns:
|
if building_id not in building_uprns:
|
||||||
building_uprns[building_id] = []
|
building_uprns[building_id] = []
|
||||||
|
|
||||||
if entry['uprn'] not in building_uprns[building_id]:
|
if entry['uprn'] not in building_uprns[building_id]:
|
||||||
building_uprns[building_id].append(
|
building_uprns[building_id].append(
|
||||||
{
|
{
|
||||||
"uprn": entry['uprn'], "longitude": entry['longitude'], "latitude": entry['latitude']
|
"uprn": entry['uprn'], "longitude": entry['longitude'], "latitude": entry['latitude']
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
solar_panel_configuration = {}
|
||||||
|
for building_id, coordinates in unique_coordinates.items():
|
||||||
|
if len(coordinates) > 1:
|
||||||
|
raise NotImplementedError("more than one coordinate for a building - handle me")
|
||||||
|
|
||||||
|
coordinates = coordinates[0]
|
||||||
|
energy_consumption = sum(
|
||||||
|
[entry['energy_consumption'] for entry in building_ids if entry['building_id'] == building_id]
|
||||||
|
)
|
||||||
|
solar_api_client.get(
|
||||||
|
longitude=coordinates["longitude"],
|
||||||
|
latitude=coordinates["latitude"],
|
||||||
|
energy_consumption=energy_consumption,
|
||||||
|
is_building=True,
|
||||||
|
session=session
|
||||||
|
)
|
||||||
|
solar_panel_configuration[building_id] = {
|
||||||
|
"insights_data": solar_api_client.insights_data,
|
||||||
|
"panel_performance": solar_api_client.panel_performance,
|
||||||
|
"n_units": len([entry for entry in building_ids if entry['building_id'] == building_id])
|
||||||
|
}
|
||||||
|
|
||||||
|
# Store the data in the database
|
||||||
|
# TODO: Rather than just doing a straight insert, we should overwrite what's already there if it
|
||||||
|
# exists
|
||||||
|
solar_api_client.save_to_db(
|
||||||
|
session=session, uprns_to_location=building_uprns[building_id], scenario_type="building"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Insert this into the properties that have this building id
|
||||||
|
for p in input_properties:
|
||||||
|
if p.building_id == building_id:
|
||||||
|
unit_solar_panel_configuration = solar_panel_configuration[building_id].copy()
|
||||||
|
|
||||||
|
unit_solar_panel_configuration["unit_share_of_energy"] = (
|
||||||
|
[x for x in building_ids if x["property_id"] == p.id][0]["energy_consumption"] /
|
||||||
|
energy_consumption
|
||||||
)
|
)
|
||||||
|
p.set_solar_panel_configuration(unit_solar_panel_configuration)
|
||||||
|
|
||||||
solar_panel_configuration = {}
|
if individual_units:
|
||||||
for building_id, coordinates in unique_coordinates.items():
|
# Model the solar potential at the property level
|
||||||
if len(coordinates) > 1:
|
for unit in individual_units:
|
||||||
raise NotImplementedError("more than one coordinate for a building - handle me")
|
property_instance = [p for p in input_properties if p.id == unit["property_id"]][0]
|
||||||
|
# At this level, we check if the property is suitable for solar and if now, skip
|
||||||
|
if not property_instance.is_solar_pv_valid():
|
||||||
|
continue
|
||||||
|
|
||||||
coordinates = coordinates[0]
|
# We check if we have a solar non-invasive recommendation
|
||||||
energy_consumption = sum(
|
if [r for r in property_instance.non_invasive_recommendations if r["type"] == "solar_pv"]:
|
||||||
[entry['energy_consumption'] for entry in building_ids if entry['building_id'] == building_id]
|
continue
|
||||||
)
|
|
||||||
solar_api_client.get(
|
solar_api_client.get(
|
||||||
longitude=coordinates["longitude"],
|
longitude=unit["longitude"],
|
||||||
latitude=coordinates["latitude"],
|
latitude=unit["latitude"],
|
||||||
energy_consumption=energy_consumption,
|
energy_consumption=unit["energy_consumption"],
|
||||||
is_building=True,
|
is_building=False,
|
||||||
session=session
|
session=session,
|
||||||
)
|
uprn=unit["uprn"],
|
||||||
solar_panel_configuration[building_id] = {
|
property_instance=property_instance
|
||||||
|
)
|
||||||
|
|
||||||
|
# Store the data in the database
|
||||||
|
# TODO: Rather than just doing a straight insert, we should overwrite what's already there if it
|
||||||
|
# exists
|
||||||
|
solar_api_client.save_to_db(
|
||||||
|
session=session,
|
||||||
|
uprns_to_location=[
|
||||||
|
{
|
||||||
|
"uprn": property_instance.uprn,
|
||||||
|
"longitude": property_instance.spatial["longitude"],
|
||||||
|
"latitude": property_instance.spatial["latitude"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
scenario_type="unit"
|
||||||
|
)
|
||||||
|
|
||||||
|
property_instance.set_solar_panel_configuration(
|
||||||
|
solar_panel_configuration={
|
||||||
"insights_data": solar_api_client.insights_data,
|
"insights_data": solar_api_client.insights_data,
|
||||||
"panel_performance": solar_api_client.panel_performance,
|
"panel_performance": solar_api_client.panel_performance,
|
||||||
"n_units": len([entry for entry in building_ids if entry['building_id'] == building_id])
|
"unit_share_of_energy": 1
|
||||||
}
|
},
|
||||||
|
roof_area=solar_api_client.roof_area
|
||||||
# Store the data in the database
|
)
|
||||||
# TODO: Rather than just doing a straight insert, we should overwrite what's already there if it
|
|
||||||
# exists
|
|
||||||
solar_api_client.save_to_db(
|
|
||||||
session=session, uprns_to_location=building_uprns[building_id], scenario_type="building"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Insert this into the properties that have this building id
|
|
||||||
for p in input_properties:
|
|
||||||
if p.building_id == building_id:
|
|
||||||
unit_solar_panel_configuration = solar_panel_configuration[building_id].copy()
|
|
||||||
|
|
||||||
unit_solar_panel_configuration["unit_share_of_energy"] = (
|
|
||||||
[x for x in building_ids if x["property_id"] == p.id][0]["energy_consumption"] /
|
|
||||||
energy_consumption
|
|
||||||
)
|
|
||||||
p.set_solar_panel_configuration(unit_solar_panel_configuration)
|
|
||||||
|
|
||||||
if individual_units:
|
|
||||||
# Model the solar potential at the property level
|
|
||||||
for unit in individual_units:
|
|
||||||
property_instance = [p for p in input_properties if p.id == unit["property_id"]][0]
|
|
||||||
# At this level, we check if the property is suitable for solar and if now, skip
|
|
||||||
if not property_instance.is_solar_pv_valid():
|
|
||||||
continue
|
|
||||||
|
|
||||||
solar_api_client.get(
|
|
||||||
longitude=unit["longitude"],
|
|
||||||
latitude=unit["latitude"],
|
|
||||||
energy_consumption=unit["energy_consumption"],
|
|
||||||
is_building=False,
|
|
||||||
session=session,
|
|
||||||
uprn=unit["uprn"],
|
|
||||||
property_instance=property_instance
|
|
||||||
)
|
|
||||||
|
|
||||||
# Store the data in the database
|
|
||||||
# TODO: Rather than just doing a straight insert, we should overwrite what's already there if it
|
|
||||||
# exists
|
|
||||||
solar_api_client.save_to_db(
|
|
||||||
session=session,
|
|
||||||
uprns_to_location=[
|
|
||||||
{
|
|
||||||
"uprn": property_instance.uprn,
|
|
||||||
"longitude": property_instance.spatial["longitude"],
|
|
||||||
"latitude": property_instance.spatial["latitude"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
scenario_type="unit"
|
|
||||||
)
|
|
||||||
|
|
||||||
property_instance.set_solar_panel_configuration(
|
|
||||||
solar_panel_configuration={
|
|
||||||
"insights_data": solar_api_client.insights_data,
|
|
||||||
"panel_performance": solar_api_client.panel_performance,
|
|
||||||
"unit_share_of_energy": 1
|
|
||||||
},
|
|
||||||
roof_area=solar_api_client.roof_area
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("Getting components and epc recommendations")
|
logger.info("Getting components and epc recommendations")
|
||||||
recommendations = {}
|
recommendations = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue