Spaces:
Build error
Build error
pjgerrits commited on
Commit ·
51064c1
1
Parent(s): afca6e0
update refresh
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import psycopg2
|
|
| 5 |
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
|
| 8 |
-
@st.
|
| 9 |
def connect_to_db():
|
| 10 |
return psycopg2.connect(
|
| 11 |
dbname="glprui_jloddr",
|
|
@@ -62,12 +62,17 @@ def create_map(points, center=None, zoom=10):
|
|
| 62 |
).add_to(m)
|
| 63 |
return m
|
| 64 |
|
|
|
|
| 65 |
if 'points' not in st.session_state:
|
| 66 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
| 67 |
if 'survey' not in st.session_state:
|
| 68 |
st.session_state['survey'] = False
|
| 69 |
if 'point_type' not in st.session_state:
|
| 70 |
st.session_state['point_type'] = 'start'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Custom CSS for colored buttons
|
| 73 |
st.markdown(
|
|
@@ -81,8 +86,9 @@ st.markdown(
|
|
| 81 |
""",
|
| 82 |
unsafe_allow_html=True,
|
| 83 |
)
|
|
|
|
| 84 |
st.sidebar.image("static/UoG_keyline.png")
|
| 85 |
-
st.sidebar.title("Step 1 - Add
|
| 86 |
|
| 87 |
# Custom buttons for selecting point type
|
| 88 |
col1, col2, col3 = st.sidebar.columns(3)
|
|
@@ -107,13 +113,7 @@ st.sidebar.write(f"Selected Point Type: {st.session_state['point_type'].capitali
|
|
| 107 |
# Reset button
|
| 108 |
if st.sidebar.button("Reset Markers", key="reset-button"):
|
| 109 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
| 110 |
-
st.
|
| 111 |
-
|
| 112 |
-
# Initialize session state for map center and zoom level if not already done
|
| 113 |
-
if 'map_center' not in st.session_state:
|
| 114 |
-
st.session_state['map_center'] = [51.5074, -0.1278]
|
| 115 |
-
if 'map_zoom' not in st.session_state:
|
| 116 |
-
st.session_state['map_zoom'] = 10
|
| 117 |
|
| 118 |
map_placeholder = st.empty()
|
| 119 |
|
|
@@ -136,11 +136,10 @@ if new_coords:
|
|
| 136 |
st_folium(folium_map, width="100%", height=800)
|
| 137 |
|
| 138 |
if all(st.session_state['points'].values()) and not st.session_state['survey']:
|
| 139 |
-
if st.sidebar.button("Proceed to Survey"):
|
| 140 |
st.session_state['survey'] = True
|
| 141 |
else:
|
| 142 |
st.sidebar.warning("Please add start, lost, and end points to proceed.")
|
| 143 |
-
|
| 144 |
st.sidebar.title("Step 2 - Survey Questions")
|
| 145 |
|
| 146 |
if st.session_state['survey']:
|
|
@@ -156,7 +155,7 @@ if st.session_state['survey']:
|
|
| 156 |
submit_data(age, gender, transport, multi_transport, time_of_day, day_of_week, description, st.session_state['points'])
|
| 157 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
| 158 |
st.session_state['survey'] = False
|
| 159 |
-
st.
|
| 160 |
|
| 161 |
# st.sidebar.write("Current Points:")
|
| 162 |
# st.sidebar.json(st.session_state['points'])
|
|
|
|
| 5 |
|
| 6 |
st.set_page_config(layout="wide")
|
| 7 |
|
| 8 |
+
@st.cache_resource
|
| 9 |
def connect_to_db():
|
| 10 |
return psycopg2.connect(
|
| 11 |
dbname="glprui_jloddr",
|
|
|
|
| 62 |
).add_to(m)
|
| 63 |
return m
|
| 64 |
|
| 65 |
+
# Initialize session state for points if not already done
|
| 66 |
if 'points' not in st.session_state:
|
| 67 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
| 68 |
if 'survey' not in st.session_state:
|
| 69 |
st.session_state['survey'] = False
|
| 70 |
if 'point_type' not in st.session_state:
|
| 71 |
st.session_state['point_type'] = 'start'
|
| 72 |
+
if 'map_center' not in st.session_state:
|
| 73 |
+
st.session_state['map_center'] = [51.5074, -0.1278]
|
| 74 |
+
if 'map_zoom' not in st.session_state:
|
| 75 |
+
st.session_state['map_zoom'] = 10
|
| 76 |
|
| 77 |
# Custom CSS for colored buttons
|
| 78 |
st.markdown(
|
|
|
|
| 86 |
""",
|
| 87 |
unsafe_allow_html=True,
|
| 88 |
)
|
| 89 |
+
|
| 90 |
st.sidebar.image("static/UoG_keyline.png")
|
| 91 |
+
st.sidebar.title("Step 1 - Add Markers")
|
| 92 |
|
| 93 |
# Custom buttons for selecting point type
|
| 94 |
col1, col2, col3 = st.sidebar.columns(3)
|
|
|
|
| 113 |
# Reset button
|
| 114 |
if st.sidebar.button("Reset Markers", key="reset-button"):
|
| 115 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
| 116 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
map_placeholder = st.empty()
|
| 119 |
|
|
|
|
| 136 |
st_folium(folium_map, width="100%", height=800)
|
| 137 |
|
| 138 |
if all(st.session_state['points'].values()) and not st.session_state['survey']:
|
| 139 |
+
if st.sidebar.button("Proceed to Survey :question:"):
|
| 140 |
st.session_state['survey'] = True
|
| 141 |
else:
|
| 142 |
st.sidebar.warning("Please add start, lost, and end points to proceed.")
|
|
|
|
| 143 |
st.sidebar.title("Step 2 - Survey Questions")
|
| 144 |
|
| 145 |
if st.session_state['survey']:
|
|
|
|
| 155 |
submit_data(age, gender, transport, multi_transport, time_of_day, day_of_week, description, st.session_state['points'])
|
| 156 |
st.session_state['points'] = {'start': None, 'lost': None, 'end': None}
|
| 157 |
st.session_state['survey'] = False
|
| 158 |
+
st.rerun()
|
| 159 |
|
| 160 |
# st.sidebar.write("Current Points:")
|
| 161 |
# st.sidebar.json(st.session_state['points'])
|