mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Posting property_details_epc to db
This commit is contained in:
parent
90099edcb4
commit
7326425320
2 changed files with 66 additions and 19 deletions
|
|
@ -49,6 +49,8 @@ class Property(BaseUtility):
|
|||
self.number_of_extensions = None
|
||||
self.number_of_storeys = None
|
||||
self.heat_loss_corridor = None
|
||||
self.mains_gas = None
|
||||
self.floor_height = None
|
||||
|
||||
if epc_client:
|
||||
self.epc_client = epc_client
|
||||
|
|
@ -236,6 +238,9 @@ class Property(BaseUtility):
|
|||
self.set_solar_hot_water()
|
||||
self.set_wind_turbine()
|
||||
self.set_count_variables()
|
||||
self.set_heat_loss_corridor()
|
||||
self.set_mains_gas()
|
||||
self.set_floor_height()
|
||||
|
||||
for description, attribute in cleaned.items():
|
||||
|
||||
|
|
@ -295,9 +300,47 @@ class Property(BaseUtility):
|
|||
}
|
||||
|
||||
if self.data["heat-loss-corridor"] in self.DATA_ANOMALY_MATCHES:
|
||||
self.heat_loss_corridor = False
|
||||
has_heat_loss_corridor = False
|
||||
else:
|
||||
self.heat_loss_corridor = map[self.data["heat-loss-corridor"]]
|
||||
has_heat_loss_corridor = map[self.data["heat-loss-corridor"]]
|
||||
|
||||
length = self.data["unheated-corridor-length"]
|
||||
if length == "":
|
||||
length = None
|
||||
else:
|
||||
length = float(length)
|
||||
|
||||
self.heat_loss_corridor = {
|
||||
"heat_loss_corridor": has_heat_loss_corridor,
|
||||
"length": length
|
||||
}
|
||||
|
||||
def set_mains_gas(self):
|
||||
"""
|
||||
Sets whether the property has mains gas
|
||||
:return:
|
||||
"""
|
||||
|
||||
map = {
|
||||
"Y": True,
|
||||
"N": False,
|
||||
}
|
||||
|
||||
if self.data["mains-gas-flag"] == "" or self.data["mains-gas-flag"] in self.DATA_ANOMALY_MATCHES:
|
||||
self.mains_gas = None
|
||||
else:
|
||||
self.mains_gas = map[self.data["mains-gas-flag"]]
|
||||
|
||||
def set_floor_height(self):
|
||||
"""
|
||||
Sets the floor height of the property
|
||||
:return:
|
||||
"""
|
||||
|
||||
if self.data["floor-height"] == "" or self.data["floor-height"] in self.DATA_ANOMALY_MATCHES:
|
||||
self.floor_height = None
|
||||
else:
|
||||
self.floor_height = float(self.data["floor-height"])
|
||||
|
||||
def _clean_upload_data(self, to_update):
|
||||
for k, v in to_update.items():
|
||||
|
|
@ -338,7 +381,7 @@ class Property(BaseUtility):
|
|||
"""
|
||||
Utility function for usage in the lambda, for preparing the _rating fields
|
||||
"""
|
||||
return rating_lookup[field] if field not in cls.DATA_ANOMALY_MATCHES else None
|
||||
return rating_lookup[field].value if field not in cls.DATA_ANOMALY_MATCHES else None
|
||||
|
||||
def get_property_details_epc(self, portfolio_id: int, rating_lookup):
|
||||
|
||||
|
|
@ -368,13 +411,13 @@ class Property(BaseUtility):
|
|||
"solar_pv": self.solar_pv["solar_pv"],
|
||||
"solar_hot_water": self.solar_hot_water["solar_hot_water"],
|
||||
"wind_turbine": self.wind_turbine["wind_turbine"],
|
||||
"floor_height": self.data["floor-height"],
|
||||
"heat_loss_corridor": self.data["heat-loss-corridor"],
|
||||
"unheated_corridor_length": self.data["unheated-corridor-length"],
|
||||
"floor_height": self.floor_height,
|
||||
"heat_loss_corridor": self.heat_loss_corridor["heat_loss_corridor"],
|
||||
"unheated_corridor_length": self.heat_loss_corridor["length"],
|
||||
"number_of_open_fireplaces": self.number_of_open_fireplaces,
|
||||
"number_of_extensions": self.number_of_extensions,
|
||||
"number_of_storeys": self.number_of_storeys,
|
||||
"mains_gas": self.data["mains-gas-flag"],
|
||||
"mains_gas": self.mains_gas,
|
||||
"energy_tariff": self.data["energy-tariff"],
|
||||
"primary_energy_consumption": self.energy["primary_energy_consumption"],
|
||||
"co2_emissions": self.energy["co2_emissions"],
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import enum
|
||||
import pytz
|
||||
import datetime
|
||||
from sqlalchemy import Column, Integer, Text, Boolean, Float, DateTime, Enum, ForeignKey
|
||||
from sqlalchemy import Column, Integer, Text, Boolean, Float, DateTime, Enum, ForeignKey, CheckConstraint
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
|
|
@ -90,14 +90,16 @@ class PropertyModel(Base):
|
|||
class FeatureRating(enum.Enum):
|
||||
VERY_GOOD = 5
|
||||
GOOD = 4
|
||||
POOR = 3
|
||||
VERY_POOR = 2
|
||||
NA = 1
|
||||
AVERAGE = 3
|
||||
POOR = 2
|
||||
VERY_POOR = 1
|
||||
NA = None
|
||||
|
||||
|
||||
rating_lookup = {
|
||||
"Very Good": FeatureRating.VERY_GOOD,
|
||||
"Good": FeatureRating.GOOD,
|
||||
"Average": FeatureRating.AVERAGE,
|
||||
"Poor": FeatureRating.POOR,
|
||||
"Very Poor": FeatureRating.VERY_POOR,
|
||||
"N/A": FeatureRating.NA
|
||||
|
|
@ -116,21 +118,23 @@ class PropertyDetailsEpcModel(Base):
|
|||
full_address = Column(Text)
|
||||
total_floor_area = Column(Float)
|
||||
walls = Column(Text)
|
||||
walls_rating = Column(Enum(FeatureRating, ))
|
||||
walls_rating = Column(Integer, CheckConstraint('walls_rating>=1 AND walls_rating<=5'))
|
||||
roof = Column(Text)
|
||||
roof_rating = Column(Enum(FeatureRating, ))
|
||||
roof_rating = Column(Integer, CheckConstraint('roof_rating>=1 AND roof_rating<=5'))
|
||||
floor = Column(Text)
|
||||
floor_rating = Column(Enum(FeatureRating, ))
|
||||
floor_rating = Column(Integer, CheckConstraint('floor_rating>=1 AND floor_rating<=5'))
|
||||
windows = Column(Text)
|
||||
windows_rating = Column(Enum(FeatureRating, ))
|
||||
windows_rating = Column(Integer, CheckConstraint('windows_rating>=1 AND windows_rating<=5'))
|
||||
heating = Column(Text)
|
||||
heating_rating = Column(Enum(FeatureRating, ))
|
||||
heating_rating = Column(Integer, CheckConstraint('heating_rating>=1 AND heating_rating<=5'))
|
||||
heating_controls = Column(Text)
|
||||
heating_controls_rating = Column(Enum(FeatureRating, ))
|
||||
heating_controls_rating = Column(
|
||||
Integer, CheckConstraint('heating_controls_rating>=1 AND heating_controls_rating<=5')
|
||||
)
|
||||
hot_water = Column(Text)
|
||||
hot_water_rating = Column(Enum(FeatureRating, ))
|
||||
hot_water_rating = Column(Integer, CheckConstraint('hot_water_rating>=1 AND hot_water_rating<=5'))
|
||||
lighting = Column(Text)
|
||||
lighting_rating = Column(Enum(FeatureRating))
|
||||
lighting_rating = Column(Integer, CheckConstraint('lighting_rating>=1 AND lighting_rating<=5'))
|
||||
mainfuel = Column(Text)
|
||||
ventilation = Column(Text)
|
||||
solar_pv = Column(Text)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue