-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
182 lines (168 loc) · 6.33 KB
/
Copy pathapp.py
File metadata and controls
182 lines (168 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import streamlit as st
from datetime import date
from streamlit_js_eval import streamlit_js_eval # For geolocation
from src.data_acquisition import get_solunar_data
from src.data_processing import process_solunar_data
from src.solunar_calculations import calculate_major_minor_times
from src.recommendation_engine import generate_recommendations
import folium
from streamlit_folium import st_folium
st.set_page_config(page_title="SolunarBass", page_icon="🎣")
st.title("🎣 SolunarBass")
st.subheader("Optimal Bass Fishing Times Based on Solunar Theory")
# Initialize session state variables
if 'use_current_location' not in st.session_state:
st.session_state.use_current_location = False
if 'latitude' not in st.session_state:
st.session_state.latitude = 38.8951
if 'longitude' not in st.session_state:
st.session_state.longitude = -77.0364
if 'loc' not in st.session_state:
st.session_state.loc = None
if 'data_fetched' not in st.session_state:
st.session_state.data_fetched = False
if 'solunar_data' not in st.session_state:
st.session_state.solunar_data = None
if 'recommendations' not in st.session_state:
st.session_state.recommendations = None
# Sidebar Inputs
st.sidebar.header("Input Parameters")
# Checkbox to use current location
use_current_location = st.sidebar.checkbox(
"Use my current location",
value=st.session_state.use_current_location
)
st.session_state.use_current_location = use_current_location
# Button to fetch data
fetch_data = st.sidebar.button("Get Fishing Times")
if st.session_state.use_current_location:
# Get the user's location using JavaScript
if st.session_state.loc is None:
loc = streamlit_js_eval(
js_expressions="""
new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
(position) => {
resolve({
latitude: position.coords.latitude,
longitude: position.coords.longitude
});
},
(error) => {
resolve(null);
}
);
});
""",
key="get_location",
)
if loc:
if 'latitude' in loc and 'longitude' in loc:
st.session_state.latitude = loc["latitude"]
st.session_state.longitude = loc["longitude"]
st.session_state.loc = loc
st.sidebar.success(
f"Location acquired: "
f"({st.session_state.latitude:.6f}, "
f"{st.session_state.longitude:.6f})"
)
else:
st.sidebar.error(
"Unable to retrieve location. "
"Please allow location access."
)
else:
st.sidebar.warning(
"Waiting for location... "
"Make sure to allow location access."
)
else:
# Manual input
st.session_state.latitude = st.sidebar.number_input(
"Latitude", value=st.session_state.latitude, format="%.6f"
)
st.session_state.longitude = st.sidebar.number_input(
"Longitude", value=st.session_state.longitude, format="%.6f"
)
selected_date = st.sidebar.date_input("Date", value=date.today())
if fetch_data:
with st.spinner('Fetching data...'):
raw_data = get_solunar_data(
st.session_state.latitude,
st.session_state.longitude,
selected_date
)
if raw_data is None:
st.error("Failed to retrieve data. Please try again later.")
else:
# Convert date to string
date_str = selected_date.strftime('%Y-%m-%d')
st.session_state.solunar_data = process_solunar_data(
raw_data, date_str
)
major_times, minor_times = calculate_major_minor_times(
st.session_state.solunar_data
)
st.session_state.recommendations = generate_recommendations(
major_times, minor_times
)
st.session_state.data_fetched = True
# Display Results if Data Has Been Fetched
if st.session_state.data_fetched and st.session_state.solunar_data:
st.success("Recommendations Generated!")
# Display Recommendations
st.header("Recommended Fishing Times")
if st.session_state.recommendations:
for rec in st.session_state.recommendations:
start_time = rec['start'].strftime('%I:%M %p')
end_time = rec['end'].strftime('%I:%M %p')
st.write(f"**{rec['type']} Period:** {start_time} - {end_time}")
else:
st.warning(
"No major or minor times could be calculated. "
"This may be due to missing moonrise/moonset data."
)
# Display Additional Information
st.header("Additional Information")
st.write(
f"**Location:** {st.session_state.latitude:.6f}, "
f"{st.session_state.longitude:.6f}"
)
sunrise_str = st.session_state.solunar_data['sunrise'].strftime('%I:%M %p')
st.write(f"**Sunrise:** {sunrise_str}")
sunset_str = st.session_state.solunar_data['sunset'].strftime('%I:%M %p')
st.write(f"**Sunset:** {sunset_str}")
moon_phase = st.session_state.solunar_data['moon_phase']
st.write(f"**Moon Phase:** {moon_phase}")
# Display Map
st.header("Map")
m = folium.Map(
location=[st.session_state.latitude, st.session_state.longitude],
zoom_start=12
)
folium.Marker(
[st.session_state.latitude, st.session_state.longitude],
tooltip="Your Location"
).add_to(m)
st_folium(m, width=700, height=500)
else:
st.info("Please enter parameters and click 'Get Fishing Times'")
# Footer with social links
st.markdown("---")
st.markdown(
"""
<div style="text-align: center;">
<p>
<a href="https://bassfinity.com"
target="_blank">Bassfinity.com</a> |
<a href="https://www.twitter.com/bassfinity"
target="_blank">Twitter</a> |
<a href="https://www.tiktok.com/@bassfinity_og"
target="_blank">TikTok</a> |
<a href="https://www.instagram.com/bassfinity_com"
target="_blank">Instagram</a>
</p>
</div>
""",
unsafe_allow_html=True
)