Skip to content

Commit 11d87be

Browse files
committed
feat(5-min-viz): add checks to visualization
ensure that the required parameters are set before proceeding with the visualization
1 parent 393de8c commit 11d87be

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

pems_streamlit/src/pems_streamlit/apps/stations/app_stations.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,24 @@ def main():
7575
station_data_button = st.button("Load Station Data", type="primary")
7676

7777
if station_data_button:
78-
df_station_data = load_station_data(station)
79-
filtered_df = df_station_data[
80-
(df_station_data["SAMPLE_TIMESTAMP"].dt.day.isin(days)) & (df_station_data["LANE"].isin(lane))
81-
]
82-
st.dataframe(df_station_data, use_container_width=True)
83-
filtered_df_sorted = filtered_df.sort_values(by="SAMPLE_TIMESTAMP")
84-
plot_5_min_traffic_data(filtered_df_sorted, quantity, lane)
78+
error_messages = []
79+
if len(quantity) == 0 or len(quantity) > 2:
80+
error_messages.append("- Please select one or two quantities to proceed.")
81+
if not lane:
82+
error_messages.append("- Please select at least one lane to proceed.")
83+
if not days:
84+
error_messages.append("- Please select at least one day to proceed.")
85+
if error_messages:
86+
full_error_message = "\n".join(error_messages)
87+
st.error(full_error_message)
88+
else:
89+
df_station_data = load_station_data(station)
90+
filtered_df = df_station_data[
91+
(df_station_data["SAMPLE_TIMESTAMP"].dt.day.isin(days)) & (df_station_data["LANE"].isin(lane))
92+
]
93+
st.dataframe(df_station_data, use_container_width=True)
94+
filtered_df_sorted = filtered_df.sort_values(by="SAMPLE_TIMESTAMP")
95+
plot_5_min_traffic_data(filtered_df_sorted, quantity, lane)
8596

8697

8798
if __name__ == "__main__":

0 commit comments

Comments
 (0)