Skip to content

Commit

Permalink
src/cli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansurf committed Jun 3, 2024
1 parent 5e38800 commit f1defec
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 53 deletions.
124 changes: 74 additions & 50 deletions src/dev_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

import numpy as np
import pandas as pd
import sys
from pathlib import Path
import streamlit as st
import pydeck as pdk

sys.path.append(str(Path(__file__).parent.parent))

from src import api, cli

# NOTE: This file is for testing purposes. Do not use it in production.

# Page Configuration ###
title = "Sample Dashboard"
title = "cli-surf"
st.set_page_config(
page_title=title,
page_icon="🌈",
page_icon="🌊",
layout="wide",
)
st.title(title)
Expand All @@ -30,7 +37,7 @@
)

# progress bar
st.write("Starting a long computation...")
# st.write("Loading...")

latest_iteration = st.empty()
bar = st.progress(0)
Expand All @@ -40,68 +47,85 @@
bar.progress(i + 1)
time.sleep(0.01)

st.write("...and now we're done!")
# st.write("...and now we're done!")

# Map
st.title("My first app")
# st.title("Surf Spot")

map_data = pd.DataFrame(
np.random.randn(500, 2) / [50, 50] + [35.7, 139.67], columns=["lat", "lon"]
)
st.map(map_data)
st.caption("Enter a surf spot to see the map and forecast!")

# User input location
location = st.text_input("Surf Spot", placeholder="Enter surf spot!")

# Checks if location has been entered.
# If True, gathers surf report and displays map
if location:
location = "location=" + location
surf_report = cli.run(args=["placeholder",f"{location}"])
lat, long = surf_report["Lat"], surf_report["Long"]
map_data = pd.DataFrame(
np.random.randn(500, 2) / [50, 50] + [lat, long], columns=["lat", "lon"]
)
st.map(map_data)
forecasted_dates = [forecast['date'] for forecast in surf_report['Forecast']]
forecasted_heights = [forecast['height'] for forecast in surf_report['Forecast']]
forecasted_periods = [forecast['period'] for forecast in surf_report['Forecast']]




st.write("# Surf Conditions")

# Checks if location has been inputted. Loads map if True
if location:
# table
df = pd.DataFrame({

'date': forecasted_dates,
'heights': forecasted_heights,
'periods': forecasted_periods
})

# test by markdown
st.write("# title")
df

# note
st.caption("note")
st.line_chart(df.rename(columns={'date':'index'}).set_index('index'))

# images
st.image("https://ul.h3z.jp/tbfgZLSX.webp")

# table
df = pd.DataFrame({
"first column": [1, 2, 3, 4],
"second column": [10, 20, 30, 40],
})
st.write(df)

# chart
st.line_chart(df)

# input text
name = st.text_input("name")
# DEFAULTS
# # input text
# name = st.text_input("name")

# integer input
age = st.number_input("age", step=1)
# # integer input
# age = st.number_input("age", step=1)

st.write(f"name: {name}")
st.write(f"age: {age}")
# st.write(f"name: {name}")
# st.write(f"age: {age}")

# button
if st.button("Push"):
st.write("Pushed")
# # button
# if st.button("Push"):
# st.write("Pushed")

# pulldown
select = st.selectbox("Fruits", options=["apple", "banana", "strawberry"])
st.write(select)
# # pulldown
# select = st.selectbox("Fruits", options=["apple", "banana", "strawberry"])
# st.write(select)

# pulldown multiple
multi_select = st.multiselect("Color", options=["red", "blue", "yellow"])
st.write(multi_select)
# # pulldown multiple
# multi_select = st.multiselect("Color", options=["red", "blue", "yellow"])
# st.write(multi_select)

# checkbox
if st.checkbox("Show dataframe"):
chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
st.line_chart(chart_data)
# # checkbox
# if st.checkbox("Show dataframe"):
# chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
# st.line_chart(chart_data)

# radio button
radio = st.radio("Select", ["cat", "dog"])
st.write(f"radio: {radio}")
# # radio button
# radio = st.radio("Select", ["cat", "dog"])
# st.write(f"radio: {radio}")

# file upload
uploaded_file = st.file_uploader("Upload", type=["csv"])
if uploaded_file:
dataframe = pd.read_csv(uploaded_file)
st.write(dataframe)
# # file upload
# uploaded_file = st.file_uploader("Upload", type=["csv"])
# if uploaded_file:
# dataframe = pd.read_csv(uploaded_file)
# st.write(dataframe)
6 changes: 3 additions & 3 deletions src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ def forecast_to_json(data, decimal):
for i in range(len(dates)):
forecast = {
"date": str(dates[i].date()),
"surf height": round(float(surf_height[i]), decimal),
"swell direction": round(float(swell_direction[i]), decimal),
"swell period": round(float(swell_period[i]), decimal),
"height": round(float(surf_height[i]), decimal),
"direction": round(float(swell_direction[i]), decimal),
"period": round(float(swell_period[i]), decimal),
}
forecasts.append(forecast)

Expand Down

0 comments on commit f1defec

Please sign in to comment.