diff --git a/src/dev_streamlit.py b/src/dev_streamlit.py index e2779d3..675ebf7 100644 --- a/src/dev_streamlit.py +++ b/src/dev_streamlit.py @@ -58,6 +58,12 @@ # User input location location = st.text_input("Surf Spot", placeholder="Enter surf spot!") +graph_type = st.radio( + "Choose graph type", + ["Height/Period :ocean:", "Direction :world_map:"], + index=None, +) + # Checks if location has been entered. # If True, gathers surf report and displays map if location: @@ -72,8 +78,8 @@ # Writes the GPT response if gpt_response is not None: st.write(gpt_response) - + # Displays the line graph st.write("# Surf Conditions") - df = sl_help.graph_data(report_dict) + df = sl_help.graph_data(report_dict, graph_type) st.line_chart(df.rename(columns={"date": "index"}).set_index("index")) diff --git a/src/streamlit_helper.py b/src/streamlit_helper.py index 2695165..c0e12ea 100644 --- a/src/streamlit_helper.py +++ b/src/streamlit_helper.py @@ -57,7 +57,7 @@ def map_data(lat, long): return m -def graph_data(report_dict): +def graph_data(report_dict, graph_type="Height/Period :ocean:"): """ Gathers the forecasted dates, heights, period and stores them in a pandas dataframe. Will be used to display the line chart @@ -71,11 +71,23 @@ def graph_data(report_dict): forecasted_periods = [ forecast["period"] for forecast in report_dict["Forecast"] ] + forecasted_directions = [ + forecast["direction"] for forecast in report_dict["Forecast"] + ] # table - df = pd.DataFrame({ - "date": forecasted_dates, - "heights": forecasted_heights, - "periods": forecasted_periods, - }) + if graph_type == "Height/Period :ocean:" or graph_type == None: + df = pd.DataFrame({ + "date": forecasted_dates, + "heights": forecasted_heights, + "periods": forecasted_periods, + }) + else: + df = pd.DataFrame({ + "date": forecasted_dates, + "directions": forecasted_directions + }) return df + + +