Spaces:
Sleeping
Sleeping
from dateutil.parser import parse | |
import geopy.distance | |
import json | |
from datetime import datetime | |
RPI_dict = {'2Q2022': 163.9, '1Q2022': 159.5, '4Q2021': 155.7, '3Q2021': 150.6, '2Q2021': 146.4, '1Q2021': 142.2, '4Q2020': 138.1, '3Q2020': 133.9, '2Q2020': 131.9, '1Q2020': 131.5, '4Q2019': 131.5, '3Q2019': 130.9, '2Q2019': 130.8, '1Q2019': 131, '4Q2018': 131.4, '3Q2018': 131.6, '2Q2018': 131.7, '1Q2018': 131.6, '4Q2017': 132.6, '3Q2017': 132.8, '2Q2017': 133.7, '1Q2017': 133.9} | |
def is_date(string, fuzzy=False): | |
""" | |
Return whether the string can be interpreted as a date. | |
:param string: str, string to check for date | |
:param fuzzy: bool, ignore unknown tokens in string if True | |
""" | |
try: | |
parse(string, fuzzy=fuzzy) | |
return True | |
except ValueError: | |
return False | |
def distance_to_mrt(lat, long, location): | |
coord_mrt = tuple(location) | |
coord_house = (lat, long) | |
distance_km = geopy.distance.distance(coord_mrt, coord_house).km | |
#print(distance_km) | |
return distance_km | |
def nearest_mrt(lat, long, mrt_name, mrt_loc): | |
count = 0 | |
distance_km = 100 | |
for mrt in mrt_name: | |
distance_cal = distance_to_mrt(lat, long, mrt_loc[count]) | |
if distance_cal < distance_km: | |
nearest_mr = mrt | |
distance_km = distance_cal | |
count += 1 | |
return distance_km, nearest_mr | |
def price_adj(price, qrtr_transaction): | |
RPI = float(RPI_dict[qrtr_transaction]) | |
resale_price_adj = price*(133.9/RPI) #133.9 is the CPI at 1Q2017, which is our baseline | |
return resale_price_adj | |