mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
added weighted datetime calc
This commit is contained in:
parent
0d7479d96c
commit
41749e8557
2 changed files with 24 additions and 1 deletions
|
|
@ -58,7 +58,7 @@ class Property(Definitions):
|
||||||
self.full_sap_epc = full_sap_epc
|
self.full_sap_epc = full_sap_epc
|
||||||
self.property_dimensions = None
|
self.property_dimensions = None
|
||||||
|
|
||||||
self.uprn = None if data is None else data["uprn"]
|
self.uprn = None if data is None else int(data["uprn"])
|
||||||
|
|
||||||
self.in_conservation_area, self.is_listed, self.is_heritage = None, None, None
|
self.in_conservation_area, self.is_listed, self.is_heritage = None, None, None
|
||||||
self.restricted_measures = False
|
self.restricted_measures = False
|
||||||
|
|
|
||||||
|
|
@ -584,6 +584,11 @@ class SearchEpc:
|
||||||
|
|
||||||
estimated_epc[key] = estimated_value
|
estimated_epc[key] = estimated_value
|
||||||
|
|
||||||
|
# Insert an estimated lodgement datetime, with a weighted average
|
||||||
|
estimated_epc["lodgement-datetime"] = self.calculate_weighted_lodgement_datetime(epc_data=epc_data)
|
||||||
|
# Extract logement date
|
||||||
|
estimated_epc["lodgement-date"] = estimated_epc["lodgement-datetime"].strftime("%Y-%m-%d")
|
||||||
|
|
||||||
estimated_epc["postcode"] = self.postcode
|
estimated_epc["postcode"] = self.postcode
|
||||||
estimated_epc["uprn"] = self.uprn
|
estimated_epc["uprn"] = self.uprn
|
||||||
# Indicate that this epc was estimated
|
# Indicate that this epc was estimated
|
||||||
|
|
@ -591,6 +596,24 @@ class SearchEpc:
|
||||||
|
|
||||||
return estimated_epc
|
return estimated_epc
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def calculate_weighted_lodgement_datetime(epc_data):
|
||||||
|
numeric_dates = pd.to_datetime(epc_data['lodgement-datetime']).view('int64')
|
||||||
|
|
||||||
|
# Calculate the weighted sum of dates
|
||||||
|
weighted_sum = (numeric_dates * epc_data['weight']).sum()
|
||||||
|
|
||||||
|
# Calculate the sum of weights
|
||||||
|
total_weights = epc_data['weight'].sum()
|
||||||
|
|
||||||
|
# Calculate the weighted mean in numeric format
|
||||||
|
weighted_mean_numeric = weighted_sum / total_weights
|
||||||
|
|
||||||
|
# Convert the numeric weighted mean back to datetime
|
||||||
|
weighted_mean_datetime = pd.to_datetime(weighted_mean_numeric)
|
||||||
|
|
||||||
|
return weighted_mean_datetime
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _estimate_int(estimation_data, key):
|
def _estimate_int(estimation_data, key):
|
||||||
return round(np.average(a=estimation_data[key], weights=estimation_data["weight"]))
|
return round(np.average(a=estimation_data[key], weights=estimation_data["weight"]))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue