File size: 1,964 Bytes
90a3f68 13ccb16 90a3f68 ecb5f3e 90a3f68 ecb5f3e 13ccb16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from typing import Union, Tuple
import datetime
class NextPlaceBaseModel:
def __init__(self):
self._load_model()
def _load_model(self):
"""
Perform any actions needed to load the model.
EX: Establish API connections, download an ML model for inference, etc...
"""
print("Loading model...")
# Optional model loading
print("Model loaded.")
def _sale_date_predictor(self, daysOnMarket: int):
"""
Calculate the expected sale date based on the national average
:param daysOnMarket: number of days this house has been on the market
:return: the predicted sale date, based on the national average of 34 days
"""
national_average = 34
if daysOnMarket < national_average:
days_until_sale = national_average - daysOnMarket
sale_date = datetime.date.today() + datetime.timedelta(days=days_until_sale)
return sale_date
else:
return datetime.date.today() + datetime.timedelta(days=1)
def run_inference(self, input_data: dict[str, Union[str, int, float]]) -> Tuple[float, str]:
"""
Predict the sale price and sale date for the house represented by `input_data`
:param input_data: a formatted Synapse from the validator, representing a currently listed house
:return: the predicted sale price and predicted sale date for this home
"""
predicted_sale_price = float(input_data['price']) if ('price' in input_data) else 1.0
predicted_sale_date = self._sale_date_predictor(input_data['dom']) if ('dom' in input_data) else datetime.date.today() + datetime.timedelta(days=1)
predicted_sale_date = predicted_sale_date.strftime("%Y-%m-%d")
print(f"Predicted sale price: {predicted_sale_price}")
print(f"Predicted sale date: {predicted_sale_date}")
return predicted_sale_price, predicted_sale_date
|