Spaces:
Build error
Build error
elli-teu
commited on
Commit
·
39a6a86
1
Parent(s):
2bd6eac
Added inout from user
Browse files
app.py
CHANGED
|
@@ -74,21 +74,31 @@ def get_buses():
|
|
| 74 |
short_bus_list = list(pd.unique(bus_df["route_short_name"]))
|
| 75 |
return bus_df, bus_list, short_bus_list
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
#
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Streamlit UI
|
| 94 |
def main():
|
|
@@ -152,38 +162,45 @@ def main():
|
|
| 152 |
)
|
| 153 |
st.write("### Selected Bus")
|
| 154 |
st.write(f"{search}: {bus}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
-
trips = buses_df[buses_df["route_long_name"]==bus]
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
5: 'FULL'}
|
| 170 |
-
#Steg 2, fixa sa date ersätts av stop genom att mappa location till stop
|
| 171 |
plot_df = st.session_state.data[st.session_state.data["trip_id"]==trip_ids[0]]
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
)
|
| 186 |
-
st.altair_chart(chart, use_container_width=True)
|
| 187 |
|
| 188 |
|
| 189 |
|
|
@@ -194,7 +211,8 @@ def main():
|
|
| 194 |
|
| 195 |
# Display data and graphs
|
| 196 |
if st.session_state.data is not None:
|
| 197 |
-
plot_graphs(st.session_state.data)
|
|
|
|
| 198 |
|
| 199 |
main()
|
| 200 |
|
|
|
|
| 74 |
short_bus_list = list(pd.unique(bus_df["route_short_name"]))
|
| 75 |
return bus_df, bus_list, short_bus_list
|
| 76 |
|
| 77 |
+
def plot_graph(plot_df):
|
| 78 |
+
#Nu vill vi plotta!
|
| 79 |
+
categories = {0 : 'EMPTY',
|
| 80 |
+
1: 'MANY_SEATS_AVAILABLE',
|
| 81 |
+
2:'FEW_SEATS_AVAILABLE',
|
| 82 |
+
3:'STANDING_ROOM_ONLY',
|
| 83 |
+
4:'CRUSHED_STANDING_ROOM_ONLY',
|
| 84 |
+
5: 'FULL'}
|
| 85 |
+
#Steg 2, fixa sa date ersätts av stop genom att mappa location till stop
|
| 86 |
+
|
| 87 |
+
plot_df = plot_df[["datetime", "vehicle_occupancystatus"]]
|
| 88 |
+
st.write(plot_df.head())
|
| 89 |
+
st.write(plot_df.tail())
|
| 90 |
+
#plot_df = plot_df.set_index("datetime")
|
| 91 |
+
plot_df["Y_category"] = plot_df["vehicle_occupancystatus"].map(categories)
|
| 92 |
+
#st.line_chart(plot_df)
|
| 93 |
+
# Create the Altair chart
|
| 94 |
+
chart = alt.Chart(plot_df).mark_line(point=True).encode(
|
| 95 |
+
x=alt.X('datetime:T', title="Datetime"), # Use column name as string
|
| 96 |
+
y=alt.Y('Y_category:N', title="Vehicle Occupancy Status (Categories)"), # Treat Y as categorical
|
| 97 |
+
tooltip=['datetime', 'Y_category'] # Add tooltips for interactivity
|
| 98 |
+
).properties(
|
| 99 |
+
title="Vehicle Occupancy Status Over Time"
|
| 100 |
+
)
|
| 101 |
+
st.altair_chart(chart, use_container_width=True)
|
| 102 |
|
| 103 |
# Streamlit UI
|
| 104 |
def main():
|
|
|
|
| 162 |
)
|
| 163 |
st.write("### Selected Bus")
|
| 164 |
st.write(f"{search}: {bus}")
|
| 165 |
+
|
| 166 |
+
today = datetime.now()
|
| 167 |
+
tomorrow = today + timedelta(days=1)
|
| 168 |
+
today = today.date()
|
| 169 |
+
tomorrow = tomorrow.date()
|
| 170 |
+
|
| 171 |
+
date_options = {
|
| 172 |
+
today.strftime("%d %B %Y") : today,
|
| 173 |
+
tomorrow.strftime("%d %B %Y") : tomorrow
|
| 174 |
+
}
|
| 175 |
|
| 176 |
+
day_choice = st.sidebar.radio("Select the day:", options=list(date_options.keys()))
|
|
|
|
| 177 |
|
| 178 |
+
# Add time input widgets in the sidebar
|
| 179 |
+
start_time = st.sidebar.time_input("Select a start time", value=None)
|
| 180 |
+
end_time = st.sidebar.time_input("Select an end time", value=None)
|
| 181 |
|
| 182 |
+
#Plocka alla aktuella trip_ids från buses
|
| 183 |
+
trips = buses_df[buses_df["route_long_name"]==bus]
|
| 184 |
+
bus_trips = st.session_state.data[st.session_state.data["route_long_name"]==bus]
|
| 185 |
+
bus_trips["datetime"] = pd.to_datetime(bus_trips["datetime"])
|
| 186 |
+
bus_trips["datetime"] = bus_trips["datetime"].dt.tz_convert(None)
|
| 187 |
+
|
| 188 |
+
#TODO remove
|
| 189 |
+
trip_ids = list(trips["trip_id"])
|
|
|
|
|
|
|
| 190 |
plot_df = st.session_state.data[st.session_state.data["trip_id"]==trip_ids[0]]
|
| 191 |
+
|
| 192 |
+
print(f"start time {type(start_time)}")
|
| 193 |
+
print(f"end time {type(end_time)}")
|
| 194 |
+
print(f"day {type(day_choice)}")
|
| 195 |
+
|
| 196 |
+
if start_time != None and end_time != None:
|
| 197 |
+
#TODO hur filtrera på tid?
|
| 198 |
+
st.write(f"Displaying buses between {start_time.strftime('%H:%M')} and {end_time.strftime('%H:%M')} the {day_choice}")
|
| 199 |
+
selected_trips = bus_trips[(bus_trips["datetime"] >= datetime.combine(date_options[day_choice], start_time)) & (bus_trips["datetime"] <= datetime.combine(date_options[day_choice], end_time))]
|
| 200 |
+
trip_ids = list(pd.unique(selected_trips["trip_id"]))
|
| 201 |
+
st.write(f"Length {len(trip_ids)}")
|
| 202 |
+
for id in trip_ids:
|
| 203 |
+
plot_graph(st.session_state.data[st.session_state.data["trip_id"]==id])
|
|
|
|
|
|
|
| 204 |
|
| 205 |
|
| 206 |
|
|
|
|
| 211 |
|
| 212 |
# Display data and graphs
|
| 213 |
if st.session_state.data is not None:
|
| 214 |
+
#plot_graphs(st.session_state.data)
|
| 215 |
+
st.write("Hi")
|
| 216 |
|
| 217 |
main()
|
| 218 |
|