diff --git a/tools/__init__.py b/tools/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/accommodations/__init__.py b/tools/accommodations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/accommodations/apis.py b/tools/accommodations/apis.py deleted file mode 100644 index 9bf9b9f..0000000 --- a/tools/accommodations/apis.py +++ /dev/null @@ -1,91 +0,0 @@ -import pandas as pd -from pandas import DataFrame -from typing import Optional -from annotation.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 \ No newline at end of file diff --git a/tools/attractions/apis.py b/tools/attractions/apis.py deleted file mode 100644 index 5de6c9c..0000000 --- a/tools/attractions/apis.py +++ /dev/null @@ -1,34 +0,0 @@ -import pandas as pd -from pandas import DataFrame -from typing import Optional -from annotation.src.utils import extract_before_parenthesis - - -class Attractions: - def __init__(self, path="/home/user/app/database/attractions/attractions.csv"): - self.path = path - self.data = pd.read_csv(self.path).dropna()[['Name','Latitude','Longitude','Address','Phone','Website',"City"]] - print("Attractions loaded.") - - def load_db(self): - self.data = pd.read_csv(self.path) - - def run(self, - city: str, - ) -> DataFrame: - """Search for Accommodations by city and date.""" - results = self.data[self.data["City"] == city] - # the results should show the index - results = results.reset_index(drop=True) - 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 and date.""" - results = self.data[self.data["City"] == extract_before_parenthesis(city)] - # the results should show the index - results = results.reset_index(drop=True) - return results \ No newline at end of file diff --git a/tools/cities/apis.py b/tools/cities/apis.py deleted file mode 100644 index b39f950..0000000 --- a/tools/cities/apis.py +++ /dev/null @@ -1,23 +0,0 @@ -from pandas import DataFrame - -class Cities: - def __init__(self ,path="/home/user/app/database/background/citySet_with_states.txt") -> None: - self.path = path - self.load_data() - print("Cities loaded.") - - def load_data(self): - cityStateMapping = open(self.path, "r").read().strip().split("\n") - self.data = {} - for unit in cityStateMapping: - city, state = unit.split("\t") - if state not in self.data: - self.data[state] = [city] - else: - self.data[state].append(city) - - def run(self, state) -> dict: - if state not in self.data: - return ValueError("Invalid State") - else: - return self.data[state] \ No newline at end of file diff --git a/tools/flights/__init__.py b/tools/flights/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/flights/apis.py b/tools/flights/apis.py deleted file mode 100644 index 8f86cb9..0000000 --- a/tools/flights/apis.py +++ /dev/null @@ -1,70 +0,0 @@ -import pandas as pd -from pandas import DataFrame -from typing import Optional -from annotation.src.utils import extract_before_parenthesis - -class Flights: - - def __init__(self, path="/home/user/app/database/flights/clean_Flights_2022.csv"): - self.path = path - self.data = None - - self.data = pd.read_csv(self.path).dropna()[['Flight Number', 'Price', 'DepTime', 'ArrTime', 'ActualElapsedTime','FlightDate','OriginCityName','DestCityName','Distance']] - print("Flights API loaded.") - - def load_db(self): - self.data = pd.read_csv(self.path).dropna().rename(columns={'Unnamed: 0': 'Flight Number'}) - - def run(self, - origin: str, - destination: str, - departure_date: str, - ) -> DataFrame: - """Search for flights by origin, destination, and departure date.""" - results = self.data[self.data["OriginCityName"] == origin] - results = results[results["DestCityName"] == destination] - results = results[results["FlightDate"] == departure_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 == "ascDepTime": - # results = results.sort_values(by=["DepTime"], ascending=True) - # elif order == "descDepTime": - # results = results.sort_values(by=["DepTime"], ascending=False) - # elif order == "ascArrTime": - # results = results.sort_values(by=["ArrTime"], ascending=True) - # elif order == "descArrTime": - # results = results.sort_values(by=["ArrTime"], ascending=False) - if len(results) == 0: - return "There is no flight from {} to {} on {}.".format(origin, destination, departure_date) - return results - - def run_for_annotation(self, - origin: str, - destination: str, - departure_date: str, - ) -> DataFrame: - """Search for flights by origin, destination, and departure date.""" - results = self.data[self.data["OriginCityName"] == extract_before_parenthesis(origin)] - results = results[results["DestCityName"] == extract_before_parenthesis(destination)] - results = results[results["FlightDate"] == departure_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 == "ascDepTime": - # results = results.sort_values(by=["DepTime"], ascending=True) - # elif order == "descDepTime": - # results = results.sort_values(by=["DepTime"], ascending=False) - # elif order == "ascArrTime": - # results = results.sort_values(by=["ArrTime"], ascending=True) - # elif order == "descArrTime": - # results = results.sort_values(by=["ArrTime"], ascending=False) - return results - - def get_city_set(self): - city_set = set() - for unit in self.data['data']: - city_set.add(unit[5]) - city_set.add(unit[6]) \ No newline at end of file diff --git a/tools/googleDistanceMatrix/apis.py b/tools/googleDistanceMatrix/apis.py deleted file mode 100644 index 53bb237..0000000 --- a/tools/googleDistanceMatrix/apis.py +++ /dev/null @@ -1,153 +0,0 @@ -import requests -from annotation.src.utils import extract_before_parenthesis -import os -from requests.exceptions import SSLError -import time -import sys -import pandas as pd -import numpy as np - - -class GoogleDistanceMatrix: - def __init__(self, subscription_key: str="") -> None: - self.gplaces_api_key: str = subscription_key - self.data = pd.read_csv('/home/user/app/database/googleDistanceMatrix/distance.csv') - print("GoogleDistanceMatrix loaded.") - - def run(self, origin, destination, mode='driving'): - origin = extract_before_parenthesis(origin) - destination = extract_before_parenthesis(destination) - info = {"origin": origin, "destination": destination,"cost": None, "duration": None, "distance": None} - response = self.data[(self.data['origin'] == origin) & (self.data['destination'] == destination)] - if len(response) > 0: - if response['duration'].values[0] is None or response['distance'].values[0] is None or response['duration'].values[0] is np.nan or response['distance'].values[0] is np.nan: - return "No valid information." - info["duration"] = response['duration'].values[0] - info["distance"] = response['distance'].values[0] - if 'driving' in mode: - info["cost"] = int(eval(info["distance"].replace("km","").replace(",","")) * 0.05) - elif mode == "taxi": - info["cost"] = int(eval(info["distance"].replace("km","").replace(",",""))) - if 'day' in info["duration"]: - return "No valid information." - return f"{mode}, from {origin} to {destination}, duration: {info['duration']}, distance: {info['distance']}, cost: {info['cost']}" - - return f"{mode}, from {origin} to {destination}, no valid information." - - def run_for_evaluation(self, origin, destination, mode='driving'): - origin = extract_before_parenthesis(origin) - destination = extract_before_parenthesis(destination) - info = {"origin": origin, "destination": destination,"cost": None, "duration": None, "distance": None} - response = self.data[(self.data['origin'] == origin) & (self.data['destination'] == destination)] - if len(response) > 0: - if response['duration'].values[0] is None or response['distance'].values[0] is None or response['duration'].values[0] is np.nan or response['distance'].values[0] is np.nan: - return info - info["duration"] = response['duration'].values[0] - info["distance"] = response['distance'].values[0] - - if 'day' not in info["duration"]: - if 'driving' in mode: - info["cost"] = int(eval(info["distance"].replace("km","").replace(",","")) * 0.05) - elif mode == "taxi": - info["cost"] = int(eval(info["distance"].replace("km","").replace(",",""))) - - return info - - return info - - - def run_online(self, origin, destination, mode="driving"): - # mode in ['driving','taxi','walking', 'distance','transit'] - endpoint = "https://maps.googleapis.com/maps/api/distancematrix/json" - - params = { - "origins": origin, - "destinations": destination, - "mode": mode if mode=="taxi" else "driving", - "key": self.gplaces_api_key - } - - while True: - try: - response = requests.get(endpoint, params=params) - break - except SSLError: - time.sleep(30) - - data = response.json() - info = {"origin": origin, "destination": destination,"cost": None, "duration": None, "distance": None} - if data['status'] == "OK": - element = data['rows'][0]['elements'][0] - if element['status'] == "OK": - info["duration"] = element['duration']['text'] - info["distance"] = element['distance']['text'] - if 'driving' in mode: - info["cost"] = int(eval(info["distance"].replace("km","").replace(",","")) * 0.05) - elif mode == "taxi": - info["cost"] = int(eval(info["distance"].replace("km","").replace(",",""))) - # if 'day' in info["duration"]: - # return "No valid information." - return f"{mode}, from {origin} to {destination}, duration: {info['duration']}, distance: {info['distance']}, cost: {info['cost']}" - - return "No valid information." - - def run_for_annotation(self, origin, destination, mode="driving"): - # mode in ['driving','taxi','walking', 'distance','transit'] - endpoint = "https://maps.googleapis.com/maps/api/distancematrix/json" - - params = { - "origins": extract_before_parenthesis(origin), - "destinations": extract_before_parenthesis(destination), - "mode": mode if mode!="taxi" else "driving", - "key": self.gplaces_api_key - } - - response = requests.get(endpoint, params=params) - data = response.json() - info = {} - if data['status'] == "OK": - element = data['rows'][0]['elements'][0] - if element['status'] == "OK": - info["duration"] = element['duration']['text'] - info["distance"] = element['distance']['text'] - info["cost"] = None - if 'driving' in mode: - info["cost"] = int(eval(info["distance"].replace("km","").replace(",","")) * 0.05) - elif mode == "taxi": - info["cost"] = int(eval(info["distance"].replace("km","").replace(",",""))) - else: - info = {"duration": "N/A", "distance": "N/A", "cost": "N/A", "Hint":"Please check the input."} - return info - - - def run_for_build_database(self, origin, destination): - # mode in ['driving','taxi','walking', 'distance','transit'] - endpoint = "https://maps.googleapis.com/maps/api/distancematrix/json" - - params = { - "origins": extract_before_parenthesis(origin), - "destinations": extract_before_parenthesis(destination), - "mode": "driving", - "key": self.gplaces_api_key - } - - # response = requests.get(endpoint, params=params) - while True: - try: - response = requests.get(endpoint, params=params) - break - except: - # print the error - error = sys.exc_info()[0] - print(error) - time.sleep(30) - - data = response.json() - info = {"origin": extract_before_parenthesis(origin), "destination": extract_before_parenthesis(destination),"cost": None, "duration": None, "distance": None} - if data['status'] == "OK": - element = data['rows'][0]['elements'][0] - if element['status'] == "OK": - info["duration"] = element['duration']['text'] - info["distance"] = element['distance']['text'] - - return info \ No newline at end of file diff --git a/tools/restaurants/__init__.py b/tools/restaurants/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tools/restaurants/__pycache__/__init__.cpython-39.pyc b/tools/restaurants/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index ef048b4..0000000 Binary files a/tools/restaurants/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/tools/restaurants/apis.py b/tools/restaurants/apis.py deleted file mode 100644 index 2351b60..0000000 --- a/tools/restaurants/apis.py +++ /dev/null @@ -1,50 +0,0 @@ -import pandas as pd -from pandas import DataFrame -from typing import Optional -from annotation.src.utils import extract_before_parenthesis - -class Restaurants: - def __init__(self, path="/home/user/app/database/restaurants/clean_restaurant_2022.csv"): - self.path = path - self.data = pd.read_csv(self.path).dropna()[['Name','Average Cost','Cuisines','Aggregate Rating','City']] - print("Restaurants loaded.") - - def load_db(self): - self.data = pd.read_csv(self.path).dropna() - - def run(self, - city: str, - ) -> DataFrame: - """Search for restaurant .""" - results = self.data[self.data["City"] == city] - # results = results[results["date"] == date] - # if price_order == "asc": - # results = results.sort_values(by=["Average Cost"], ascending=True) - # elif price_order == "desc": - # results = results.sort_values(by=["Average Cost"], ascending=False) - - # if rating_order == "asc": - # results = results.sort_values(by=["Aggregate Rating"], ascending=True) - # elif rating_order == "desc": - # results = results.sort_values(by=["Aggregate Rating"], ascending=False) - if len(results) == 0: - return "There is no restaurant in this city." - return results - - def run_for_annotation(self, - city: str, - ) -> DataFrame: - """Search for restaurant .""" - results = self.data[self.data["City"] == extract_before_parenthesis(city)] - # results = results[results["date"] == date] - # if price_order == "asc": - # results = results.sort_values(by=["Average Cost"], ascending=True) - # elif price_order == "desc": - # results = results.sort_values(by=["Average Cost"], ascending=False) - - # if rating_order == "asc": - # results = results.sort_values(by=["Aggregate Rating"], ascending=True) - # elif rating_order == "desc": - # results = results.sort_values(by=["Aggregate Rating"], ascending=False) - - return results \ No newline at end of file