Spaces:
Sleeping
Sleeping
pjgerrits
commited on
Commit
·
c96a726
1
Parent(s):
a0c5560
cache error catching
Browse files
app.py
CHANGED
@@ -8,13 +8,8 @@ import os
|
|
8 |
# Set the page layout
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
11 |
-
|
12 |
-
# def connect_to_db():
|
13 |
-
# return psycopg2.connect(**st.secrets["postgres"])
|
14 |
-
|
15 |
-
|
16 |
# Function to connect to the database
|
17 |
-
@st.cache_resource
|
18 |
def connect_to_db():
|
19 |
try:
|
20 |
conn = psycopg2.connect(
|
@@ -34,7 +29,7 @@ def connect_to_db():
|
|
34 |
|
35 |
# Perform query.
|
36 |
# Uses st.cache_data to only rerun when the query changes or after 10 min.
|
37 |
-
@st.cache_data(ttl=600)
|
38 |
# Function to fetch previously saved data points
|
39 |
def fetch_saved_data():
|
40 |
conn = connect_to_db()
|
@@ -50,7 +45,7 @@ def fetch_saved_data():
|
|
50 |
# Perform query.
|
51 |
# Uses st.cache_data to only rerun when the query changes or after 10 min.
|
52 |
# Function to save data to the database
|
53 |
-
@st.cache_data(ttl=600)
|
54 |
def save_data(lat, lon, description, rating):
|
55 |
conn = connect_to_db()
|
56 |
if conn:
|
@@ -59,7 +54,7 @@ def save_data(lat, lon, description, rating):
|
|
59 |
(lat, lon, lon, lat, description, rating))
|
60 |
conn.commit()
|
61 |
cursor.close()
|
62 |
-
|
63 |
st.sidebar.success("Data recorded successfully!")
|
64 |
else:
|
65 |
st.sidebar.error("Failed to save data.")
|
@@ -90,11 +85,11 @@ except:
|
|
90 |
coords = [0,0]
|
91 |
|
92 |
# Data Entry Form in the sidebar
|
93 |
-
st.sidebar.write("
|
94 |
-
description = st.sidebar.text_area("
|
95 |
-
rating = st.sidebar.selectbox('Certainty (1-5)', ['1', '2', '3', '4', '5'])
|
96 |
|
97 |
-
#
|
98 |
clicked_lat = coords[1] # Default value, should ideally be updated on map click
|
99 |
clicked_lon = coords[0] # Default value, should ideally be updated on map click
|
100 |
|
|
|
8 |
# Set the page layout
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
# Function to connect to the database
|
12 |
+
# @st.cache_resource
|
13 |
def connect_to_db():
|
14 |
try:
|
15 |
conn = psycopg2.connect(
|
|
|
29 |
|
30 |
# Perform query.
|
31 |
# Uses st.cache_data to only rerun when the query changes or after 10 min.
|
32 |
+
# @st.cache_data(ttl=600)
|
33 |
# Function to fetch previously saved data points
|
34 |
def fetch_saved_data():
|
35 |
conn = connect_to_db()
|
|
|
45 |
# Perform query.
|
46 |
# Uses st.cache_data to only rerun when the query changes or after 10 min.
|
47 |
# Function to save data to the database
|
48 |
+
# @st.cache_data(ttl=600)
|
49 |
def save_data(lat, lon, description, rating):
|
50 |
conn = connect_to_db()
|
51 |
if conn:
|
|
|
54 |
(lat, lon, lon, lat, description, rating))
|
55 |
conn.commit()
|
56 |
cursor.close()
|
57 |
+
conn.close()
|
58 |
st.sidebar.success("Data recorded successfully!")
|
59 |
else:
|
60 |
st.sidebar.error("Failed to save data.")
|
|
|
85 |
coords = [0,0]
|
86 |
|
87 |
# Data Entry Form in the sidebar
|
88 |
+
st.sidebar.write("Select a location on the map using the location button, then fill out the form.")
|
89 |
+
description = st.sidebar.text_area("Please describe the location in a few words:")
|
90 |
+
rating = st.sidebar.selectbox('Certainty (low(1)-High(5)', ['1', '2', '3', '4', '5'])
|
91 |
|
92 |
+
# Clicked coordinates
|
93 |
clicked_lat = coords[1] # Default value, should ideally be updated on map click
|
94 |
clicked_lon = coords[0] # Default value, should ideally be updated on map click
|
95 |
|