Spaces:
Running
Running
File size: 4,287 Bytes
acc4386 |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
import pandas as pd
from pandas import DataFrame
from typing import Optional
from src.utils import extract_before_parenthesis
class Accommodations:
def __init__(self, path="/home/user/app/database/accommodations/clean_accommodations_2022.csv"):
self.path = path
self.data = pd.read_csv(self.path).dropna()[['NAME','price','room type', 'house_rules', 'minimum nights', 'maximum occupancy', 'review rate number', 'city']]
print("Accommodations loaded.")
def load_db(self):
self.data = pd.read_csv(self.path).dropna()
def run(self,
city: str,
) -> DataFrame:
"""Search for accommodations by city."""
results = self.data[self.data["city"] == city]
# results = results[results["date"] == date]
# if order == "ascPrice":
# results = results.sort_values(by=["price"], ascending=True)
# elif order == "descPrice":
# results = results.sort_values(by=["price"], ascending=False)
# elif order == "ascRate":
# results = results.sort_values(by=["review rate number"], ascending=True)
# elif order == "descRate":
# results = results.sort_values(by=["review rate number"], ascending=False)
# elif order == "ascMinumNights":
# results = results.sort_values(by=["minimum nights"], ascending=True)
# elif order == "descMinumNights":
# results = results.sort_values(by=["minimum nights"], ascending=False)
# elif order == "ascMaximumOccupancy":
# results = results.sort_values(by=["maximum occupancy"], ascending=True)
# elif order == "descMaximumOccupancy":
# results = results.sort_values(by=["maximum occupancy"], ascending=False)
# if room_type == "all":
# return results
# elif room_type == "Entire home/apt":
# return results[results["room type"]=="Entire home/apt"]
# elif room_type == "Hotel room":
# return results[results["room type"]=="Hotel room"]
# elif room_type == "Private room":
# return results[results["room type"]=="Private room"]
# elif room_type == "Shared room":
# return results[results["room type"]=="Shared room"]
# else:
# return None
if len(results) == 0:
return "There is no attraction in this city."
return results
def run_for_annotation(self,
city: str,
) -> DataFrame:
"""Search for accommodations by city."""
results = self.data[self.data["city"] == extract_before_parenthesis(city)]
# results = results[results["date"] == date]
# if order == "ascPrice":
# results = results.sort_values(by=["price"], ascending=True)
# elif order == "descPrice":
# results = results.sort_values(by=["price"], ascending=False)
# elif order == "ascRate":
# results = results.sort_values(by=["review rate number"], ascending=True)
# elif order == "descRate":
# results = results.sort_values(by=["review rate number"], ascending=False)
# elif order == "ascMinumNights":
# results = results.sort_values(by=["minimum nights"], ascending=True)
# elif order == "descMinumNights":
# results = results.sort_values(by=["minimum nights"], ascending=False)
# elif order == "ascMaximumOccupancy":
# results = results.sort_values(by=["maximum occupancy"], ascending=True)
# elif order == "descMaximumOccupancy":
# results = results.sort_values(by=["maximum occupancy"], ascending=False)
# if room_type == "all":
# return results
# elif room_type == "Entire home/apt":
# return results[results["room type"]=="Entire home/apt"]
# elif room_type == "Hotel room":
# return results[results["room type"]=="Hotel room"]
# elif room_type == "Private room":
# return results[results["room type"]=="Private room"]
# elif room_type == "Shared room":
# return results[results["room type"]=="Shared room"]
# else:
# return None
return results |