pulling out lighting averages

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-01 14:45:29 +01:00
parent 75a358ff4c
commit 45ecd767df
5 changed files with 35 additions and 5 deletions

View file

@ -82,3 +82,18 @@ def create_property_targets(property_id: int, portfolio_id: int, epc_target=None
session.commit()
return True
def update_property_data(property_data):
Session = sessionmaker(bind=db_engine)
now = datetime.datetime.now()
with Session() as session:
new_target = PropertyTargetsModel(
property_id=property_id,
portfolio_id=portfolio_id,
created_at=now,
epc=epc_target,
heat_demand=heat_demand_target
)
session.add(new_target)
session.commit()

View file

@ -70,6 +70,12 @@ walls_decile_data = {
'Decile 9', 'Decile 10'], 'decile_boundaries': [6., 49., 51., 55., 64., 71., 76., 83., 96.,
120., 2279.]}
lighting_averages = [
{'lighting-description': 'good lighting efficiency', 'low-energy-lighting': 99.26666666666667},
{'lighting-description': 'excellent lighting efficiency', 'low-energy-lighting': 100.0},
{'lighting-description': 'below average lighting efficiency', 'low-energy-lighting': 0.0}
]
@router.post("/trigger")
async def trigger_plan(body: PlanTriggerRequest):
@ -128,6 +134,7 @@ async def trigger_plan(body: PlanTriggerRequest):
)
p.set_is_in_conservation_area(in_conservation_area)
# TODO: This won't work perfectly as we need the table of lighting averages by constituency
cleaner = EpcClean(data=[x.data for x in input_properties])
cleaner.clean()

View file

@ -31,7 +31,8 @@ class EpcClean:
"lighting-description"
]
def __init__(self, data: List[Dict[str, Any]]) -> None:
def __init__(self, data: List[Dict[str, Any]],
lighting_averages: List[Dict[str, str | float]] | None = None) -> None:
"""
EpcClean constructor.
@ -41,7 +42,10 @@ class EpcClean:
self.unique_vals: Dict[str, Any] = {}
self.cleaned: Dict[str, List[Any]] = {}
self.lighting_averages = self._calculate_lighting_averages()
if not lighting_averages:
self.lighting_averages = self._calculate_lighting_averages()
else:
self.lighting_averages = lighting_averages
def _calculate_lighting_averages(self):

View file

@ -74,6 +74,8 @@ def app():
# Incorporate input data into cleaning
cleaner = EpcClean(data)
lighting_averages = cleaner.lighting_averages
# TODO: WE need to store lighting_averages to a db
cleaner.clean()
# TODO: cleaner.cleaned datasets to a db

View file

@ -22,10 +22,12 @@ class LightingAttributes:
if ('good lighting efficiency' in description) or ('excellent lighting efficiency' in description) or \
('below average lighting efficiency' in description):
average = [
x for x in self.averages if x["lighting-description"] == description
][0]["low-energy-lighting"]
return {
"low_energy_proportion": self.averages[
self.averages["lighting-description"] == description
]["low-energy-lighting"].values[0]
"low_energy_proportion": average
}
match = re.search(r'\d+', description)