mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
pulling out lighting averages
This commit is contained in:
parent
75a358ff4c
commit
45ecd767df
5 changed files with 35 additions and 5 deletions
|
|
@ -82,3 +82,18 @@ def create_property_targets(property_id: int, portfolio_id: int, epc_target=None
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
return True
|
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()
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,12 @@ walls_decile_data = {
|
||||||
'Decile 9', 'Decile 10'], 'decile_boundaries': [6., 49., 51., 55., 64., 71., 76., 83., 96.,
|
'Decile 9', 'Decile 10'], 'decile_boundaries': [6., 49., 51., 55., 64., 71., 76., 83., 96.,
|
||||||
120., 2279.]}
|
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")
|
@router.post("/trigger")
|
||||||
async def trigger_plan(body: PlanTriggerRequest):
|
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)
|
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 = EpcClean(data=[x.data for x in input_properties])
|
||||||
cleaner.clean()
|
cleaner.clean()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ class EpcClean:
|
||||||
"lighting-description"
|
"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.
|
EpcClean constructor.
|
||||||
|
|
||||||
|
|
@ -41,7 +42,10 @@ class EpcClean:
|
||||||
self.unique_vals: Dict[str, Any] = {}
|
self.unique_vals: Dict[str, Any] = {}
|
||||||
self.cleaned: Dict[str, List[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):
|
def _calculate_lighting_averages(self):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ def app():
|
||||||
|
|
||||||
# Incorporate input data into cleaning
|
# Incorporate input data into cleaning
|
||||||
cleaner = EpcClean(data)
|
cleaner = EpcClean(data)
|
||||||
|
lighting_averages = cleaner.lighting_averages
|
||||||
|
# TODO: WE need to store lighting_averages to a db
|
||||||
cleaner.clean()
|
cleaner.clean()
|
||||||
# TODO: cleaner.cleaned datasets to a db
|
# TODO: cleaner.cleaned datasets to a db
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,12 @@ class LightingAttributes:
|
||||||
|
|
||||||
if ('good lighting efficiency' in description) or ('excellent lighting efficiency' in description) or \
|
if ('good lighting efficiency' in description) or ('excellent lighting efficiency' in description) or \
|
||||||
('below average lighting efficiency' in description):
|
('below average lighting efficiency' in description):
|
||||||
|
average = [
|
||||||
|
x for x in self.averages if x["lighting-description"] == description
|
||||||
|
][0]["low-energy-lighting"]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"low_energy_proportion": self.averages[
|
"low_energy_proportion": average
|
||||||
self.averages["lighting-description"] == description
|
|
||||||
]["low-energy-lighting"].values[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match = re.search(r'\d+', description)
|
match = re.search(r'\d+', description)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue