Spaces:
Build error
Build error
elli-teu commited on
Commit ·
effa819
1
Parent(s): 618cd91
Added the possibility to search for a bus and started ploting
Browse filesFiles changed (3)
- __pycache__/api.cpython-39.pycAdded
- api.pyAdded+3
- app.py+61-1
123import os
os.environ["HOPSWORKS_API_KEY"] = "vjR4XXGkTzrmVZOS.5faua2qELLblTMrj9OXO6QpvXsQP1nu0EZfqWsQwUu8YgOz3NFpCAJTYTp6QNKQG"6 unmodified lines78910111249 unmodified lines62636465666740 unmodified lines1081091101111121131141151161171186 unmodified linesimport seaborn as snsfrom datetime import datetime, timedelta# ConstantsDATA_DIR = "data"TIMESTAMP_FILE = "last_download_time.txt"49 unmodified linesexcept Exception as e:st.warning(f"Error reading timestamp: {e}")return False# Plot graphsdef plot_graphs(data):40 unmodified linesproject = st.session_state.hopsworks_projectdata = fetch_data_from_feature_group(project, "predictions", 1)print(data.head())filepath = save_data_locally(data, "data.csv")st.session_state.data = datast.success(f"Data fetched and saved locally at {filepath}")# Display data and graphsif st.session_state.data is not None:plot_graphs(st.session_state.data)6 unmodified lines789101112131449 unmodified lines646566676869707172737475767740 unmodified lines1181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771786 unmodified linesimport seaborn as snsfrom datetime import datetime, timedeltaimport api# ConstantsDATA_DIR = "data"TIMESTAMP_FILE = "last_download_time.txt"49 unmodified linesexcept Exception as e:st.warning(f"Error reading timestamp: {e}")return Falsedef get_buses():bus_df = st.session_state.data[["trip_id", "route_long_name", "route_short_name"]]bus_df = bus_df.drop_duplicates()bus_list = bus_df[["route_long_name", "route_short_name"]]bus_list = bus_list.drop_duplicates()short_bus_list = list(pd.unique(bus_df["route_short_name"]))return bus_df, bus_list, short_bus_list# Plot graphsdef plot_graphs(data):40 unmodified linesproject = st.session_state.hopsworks_projectdata = fetch_data_from_feature_group(project, "predictions", 1)#print(data.head())filepath = save_data_locally(data, "data.csv")st.session_state.data = datast.success(f"Data fetched and saved locally at {filepath}")buses_df, bus_list, short_bus = get_buses()# Sidebar section for searching busesst.sidebar.title("Search for your desired bus")# Create a multiselect dropdown in the sidebarsearch = st.sidebar.selectbox("Search for your bus number:",options=short_bus,help="Select one bus to view details.")# Display the resultsif search:route = bus_list[bus_list["route_short_name"]==search]long_names = list(pd.unique(route["route_long_name"]))if len(long_names)==1:bus = long_names[0]st.write("### Selected Bus")st.write(f"{search}: {bus}")else:bus = st.sidebar.selectbox("Pick bus route:",options=long_names,help="Select one bus to view details.")st.write("### Selected Bus")st.write(f"{search}: {bus}")#Plocka alla akruella trip_ids från busestrips = buses_df[buses_df["route_long_name"]==bus]trip_ids = list(trips["trip_id"])st.write(trip_ids[0])#Nu vill vi plotta!#Steg 2, fixa sa date ersätts av stop genom att mappa location till stopplot_df = st.session_state.data[st.session_state.data["trip_id"]==trip_ids[0]]plot_df = plot_df[["datetime", "vehicle_occupancystatus"]]plot_df = plot_df.set_index("datetime")st.line_chart(plot_df)else:st.write("No buses selected. Please search in the sidebar.")# Display data and graphsif st.session_state.data is not None:plot_graphs(st.session_state.data)
__pycache__/api.cpython-39.pycAdded
api.pyAdded+3
app.py+61-1