Spaces:
Sleeping
Sleeping
elli-teu
commited on
Commit
·
effa819
1
Parent(s):
618cd91
Added the possibility to search for a bus and started ploting
Browse files- __pycache__/api.cpython-39.pyc +0 -0
- api.py +3 -0
- app.py +61 -1
__pycache__/api.cpython-39.pyc
ADDED
Binary file (297 Bytes). View file
|
|
api.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
os.environ["HOPSWORKS_API_KEY"] = "vjR4XXGkTzrmVZOS.5faua2qELLblTMrj9OXO6QpvXsQP1nu0EZfqWsQwUu8YgOz3NFpCAJTYTp6QNKQG"
|
app.py
CHANGED
@@ -7,6 +7,8 @@ import matplotlib.pyplot as plt
|
|
7 |
import seaborn as sns
|
8 |
from datetime import datetime, timedelta
|
9 |
|
|
|
|
|
10 |
# Constants
|
11 |
DATA_DIR = "data"
|
12 |
TIMESTAMP_FILE = "last_download_time.txt"
|
@@ -62,6 +64,14 @@ def is_local_data_valid():
|
|
62 |
except Exception as e:
|
63 |
st.warning(f"Error reading timestamp: {e}")
|
64 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# Plot graphs
|
67 |
def plot_graphs(data):
|
@@ -108,11 +118,61 @@ def main():
|
|
108 |
|
109 |
project = st.session_state.hopsworks_project
|
110 |
data = fetch_data_from_feature_group(project, "predictions", 1)
|
111 |
-
print(data.head())
|
112 |
filepath = save_data_locally(data, "data.csv")
|
113 |
st.session_state.data = data
|
114 |
st.success(f"Data fetched and saved locally at {filepath}")
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
# Display data and graphs
|
117 |
if st.session_state.data is not None:
|
118 |
plot_graphs(st.session_state.data)
|
|
|
7 |
import seaborn as sns
|
8 |
from datetime import datetime, timedelta
|
9 |
|
10 |
+
import api
|
11 |
+
|
12 |
# Constants
|
13 |
DATA_DIR = "data"
|
14 |
TIMESTAMP_FILE = "last_download_time.txt"
|
|
|
64 |
except Exception as e:
|
65 |
st.warning(f"Error reading timestamp: {e}")
|
66 |
return False
|
67 |
+
|
68 |
+
def get_buses():
|
69 |
+
bus_df = st.session_state.data[["trip_id", "route_long_name", "route_short_name"]]
|
70 |
+
bus_df = bus_df.drop_duplicates()
|
71 |
+
bus_list = bus_df[["route_long_name", "route_short_name"]]
|
72 |
+
bus_list = bus_list.drop_duplicates()
|
73 |
+
short_bus_list = list(pd.unique(bus_df["route_short_name"]))
|
74 |
+
return bus_df, bus_list, short_bus_list
|
75 |
|
76 |
# Plot graphs
|
77 |
def plot_graphs(data):
|
|
|
118 |
|
119 |
project = st.session_state.hopsworks_project
|
120 |
data = fetch_data_from_feature_group(project, "predictions", 1)
|
121 |
+
#print(data.head())
|
122 |
filepath = save_data_locally(data, "data.csv")
|
123 |
st.session_state.data = data
|
124 |
st.success(f"Data fetched and saved locally at {filepath}")
|
125 |
|
126 |
+
buses_df, bus_list, short_bus = get_buses()
|
127 |
+
|
128 |
+
# Sidebar section for searching buses
|
129 |
+
st.sidebar.title("Search for your desired bus")
|
130 |
+
|
131 |
+
# Create a multiselect dropdown in the sidebar
|
132 |
+
search = st.sidebar.selectbox(
|
133 |
+
"Search for your bus number:",
|
134 |
+
options=short_bus,
|
135 |
+
help="Select one bus to view details."
|
136 |
+
)
|
137 |
+
|
138 |
+
# Display the results
|
139 |
+
if search:
|
140 |
+
route = bus_list[bus_list["route_short_name"]==search]
|
141 |
+
long_names = list(pd.unique(route["route_long_name"]))
|
142 |
+
if len(long_names)==1:
|
143 |
+
bus = long_names[0]
|
144 |
+
st.write("### Selected Bus")
|
145 |
+
st.write(f"{search}: {bus}")
|
146 |
+
else:
|
147 |
+
bus = st.sidebar.selectbox(
|
148 |
+
"Pick bus route:",
|
149 |
+
options=long_names,
|
150 |
+
help="Select one bus to view details."
|
151 |
+
)
|
152 |
+
st.write("### Selected Bus")
|
153 |
+
st.write(f"{search}: {bus}")
|
154 |
+
|
155 |
+
#Plocka alla akruella trip_ids från buses
|
156 |
+
trips = buses_df[buses_df["route_long_name"]==bus]
|
157 |
+
|
158 |
+
trip_ids = list(trips["trip_id"])
|
159 |
+
|
160 |
+
st.write(trip_ids[0])
|
161 |
+
|
162 |
+
#Nu vill vi plotta!
|
163 |
+
#Steg 2, fixa sa date ersätts av stop genom att mappa location till stop
|
164 |
+
plot_df = st.session_state.data[st.session_state.data["trip_id"]==trip_ids[0]]
|
165 |
+
plot_df = plot_df[["datetime", "vehicle_occupancystatus"]]
|
166 |
+
plot_df = plot_df.set_index("datetime")
|
167 |
+
st.line_chart(plot_df)
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
+
else:
|
172 |
+
st.write("No buses selected. Please search in the sidebar.")
|
173 |
+
|
174 |
+
|
175 |
+
|
176 |
# Display data and graphs
|
177 |
if st.session_state.data is not None:
|
178 |
plot_graphs(st.session_state.data)
|