Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,38 +4,44 @@ import hopsworks
|
|
| 4 |
import math
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
df = pd.read_csv(path)
|
| 10 |
-
wanted_df = df[['airport', 'flight_number', 'ontime', 'delayed']].copy()
|
| 11 |
-
return wanted_df
|
| 12 |
-
|
| 13 |
-
def access_online_dataframe():
|
| 14 |
-
# Get data from online source
|
| 15 |
-
hopsworks_api_key = os.environ['HOPSWORKS_API_KEY']
|
| 16 |
-
project = hopsworks.login(api_key_value = hopsworks_api_key)
|
| 17 |
-
dataset_api = project.get_dataset_api()
|
| 18 |
-
today_path = dataset_api.download("Resources/today_timetable_prediction/today_timetable_prediction.csv", overwrite=True)
|
| 19 |
-
tomorrow_path = dataset_api.download("Resources/tomorrow_timetable_prediction/tomorrow_timetable_prediction.csv", overwrite=True)
|
| 20 |
-
today_df = download_data(today_path)
|
| 21 |
-
tomorrow_df = download_data(tomorrow_path)
|
| 22 |
-
return today_df, tomorrow_df
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def get_possible_destinations():
|
| 26 |
-
today_df, tomorrow_df =
|
| 27 |
-
total_df = pd.DataFrame({'airport': pd.concat([today_df['airport'], tomorrow_df['airport']]).drop_duplicates().reset_index(drop=True)})
|
| 28 |
total_dest = (total_df['airport']).tolist()
|
| 29 |
return total_dest
|
| 30 |
|
| 31 |
|
| 32 |
def get_specific_flights(day, max_delay, departure_hour, ampm, weather, destinations, yes):
|
| 33 |
-
|
| 34 |
-
df = pd.DataFrame()
|
| 35 |
-
if(day == 'today'):
|
| 36 |
-
df = today_df
|
| 37 |
-
else:
|
| 38 |
-
df = tomorrow_df
|
| 39 |
|
| 40 |
# Remove unwanted destinations
|
| 41 |
destinations = [dest for dest in destinations if dest not in ["That's a reason why I travel alone...", "I prefer not to say"]]
|
|
@@ -61,14 +67,7 @@ def get_specific_flights(day, max_delay, departure_hour, ampm, weather, destinat
|
|
| 61 |
return filtered_df
|
| 62 |
|
| 63 |
def full_day_departure(day):
|
| 64 |
-
|
| 65 |
-
df = pd.DataFrame()
|
| 66 |
-
if(day == 'today'):
|
| 67 |
-
df = today_df
|
| 68 |
-
else:
|
| 69 |
-
df = tomorrow_df
|
| 70 |
-
|
| 71 |
-
return df
|
| 72 |
|
| 73 |
|
| 74 |
|
|
|
|
| 4 |
import math
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
hopsworks_today_path = "Resources/today_timetable_prediction/today_timetable_prediction.csv"
|
| 8 |
+
hopsworks_tomorrow_path = "Resources/tomorrow_timetable_prediction/tomorrow_timetable_prediction.csv"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
+
def get_dataframe(online_dataframe_path):
|
| 12 |
+
# Connect to Hopsworks File System
|
| 13 |
+
project = hopsworks.login(api_key_value = os.environ['HOPSWORKS_API_KEY'])
|
| 14 |
+
dataset_api = project.get_dataset_api()
|
| 15 |
+
|
| 16 |
+
# Download online dataframe and get path
|
| 17 |
+
dataframe_path = os.path.abspath(dataset_api.download(online_dataframe_path, overwrite = True))
|
| 18 |
+
|
| 19 |
+
# Read dataframe from local path, drop duplicates, return
|
| 20 |
+
dataframe = pd.read_csv(dataframe_path)
|
| 21 |
+
dataframe.drop_duplicates(inplace=True)
|
| 22 |
+
return dataframe
|
| 23 |
+
|
| 24 |
+
def get_tomorrow_dataframe():
|
| 25 |
+
return get_dataframe(hopsworks_today_path)
|
| 26 |
+
|
| 27 |
+
def get_today_dataframe():
|
| 28 |
+
return get_dataframe(hopsworks_tomorrow_path)
|
| 29 |
+
|
| 30 |
+
def get_dataframe_of(day):
|
| 31 |
+
if (day == 'today'):
|
| 32 |
+
return get_today_dataframe()
|
| 33 |
+
elif (day == 'tomorrow'):
|
| 34 |
+
return get_tomorrow_dataframe()
|
| 35 |
+
|
| 36 |
def get_possible_destinations():
|
| 37 |
+
today_df, tomorrow_df = get_today_dataframe(), get_tomorrow_dataframe()
|
| 38 |
+
total_df = pd.DataFrame({'airport': pd.concat([today_df['airport'], tomorrow_df['airport']]).drop_duplicates().reset_index(drop=True).sort_values()})
|
| 39 |
total_dest = (total_df['airport']).tolist()
|
| 40 |
return total_dest
|
| 41 |
|
| 42 |
|
| 43 |
def get_specific_flights(day, max_delay, departure_hour, ampm, weather, destinations, yes):
|
| 44 |
+
df = get_dataframe_of(day)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Remove unwanted destinations
|
| 47 |
destinations = [dest for dest in destinations if dest not in ["That's a reason why I travel alone...", "I prefer not to say"]]
|
|
|
|
| 67 |
return filtered_df
|
| 68 |
|
| 69 |
def full_day_departure(day):
|
| 70 |
+
return get_dataframe_of(day)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
|