Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +37 -10
src/streamlit_app.py
CHANGED
@@ -211,8 +211,7 @@ def add_example_topic(topic_id, topic_title, topic_description, comments_list):
|
|
211 |
elif comment_text in anti_tech_comments:
|
212 |
vote_type = 'disagree'
|
213 |
else:
|
214 |
-
|
215 |
-
vote_type = random.choice(['neutral'] * 2 + [None] * 3) # More likely neutral or skip
|
216 |
|
217 |
if vote_type:
|
218 |
# Generate UUID for vote ID and append to list
|
@@ -232,8 +231,7 @@ def add_example_topic(topic_id, topic_title, topic_description, comments_list):
|
|
232 |
elif comment_text in anti_tech_comments:
|
233 |
vote_type = 'agree'
|
234 |
else:
|
235 |
-
|
236 |
-
vote_type = random.choice(['neutral'] * 2 + [None] * 3) # More likely neutral or skip
|
237 |
|
238 |
if vote_type:
|
239 |
# Generate UUID for vote ID and append to list
|
@@ -247,7 +245,7 @@ def add_example_topic(topic_id, topic_title, topic_description, comments_list):
|
|
247 |
if not comment_id: continue
|
248 |
|
249 |
# Mostly neutral, some random agree/disagree, many skipped
|
250 |
-
vote_type = random.choice(['neutral'] *
|
251 |
|
252 |
if vote_type:
|
253 |
# Generate UUID for vote ID and append to list
|
@@ -305,6 +303,21 @@ def add_dummy_topic():
|
|
305 |
"Another set of orders. Understood, sir!",
|
306 |
"Excellent... with this, I will have even greater control over the galaxy... cackles maniacally"
|
307 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
add_example_topic(example_topic_id, example_topic_title, example_topic_description, example_comments)
|
309 |
|
310 |
|
@@ -804,7 +817,7 @@ def get_random_unvoted_comment(user_id, topic_id):
|
|
804 |
FROM comments c
|
805 |
WHERE c.topic_id = ?
|
806 |
AND NOT EXISTS (
|
807 |
-
SELECT
|
808 |
WHERE v.comment_id = c.id AND v.user_id = ?
|
809 |
)
|
810 |
ORDER BY RANDOM()
|
@@ -1037,13 +1050,27 @@ def view_topic_page():
|
|
1037 |
progress_exists = False
|
1038 |
try:
|
1039 |
local_con = duckdb.connect(database=DB_PATH, read_only=True)
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1043 |
WHERE user_id = ? AND topic_id = ?
|
1044 |
LIMIT 1
|
1045 |
""", [user_id, topic_id]).fetchone()
|
1046 |
-
|
|
|
|
|
1047 |
except Exception as e:
|
1048 |
# Log error but don't stop the app. Assume no progress on error.
|
1049 |
st.error(f"Error checking user progress for greeting: {e}")
|
|
|
211 |
elif comment_text in anti_tech_comments:
|
212 |
vote_type = 'disagree'
|
213 |
else:
|
214 |
+
vote_type = 'neutral'
|
|
|
215 |
|
216 |
if vote_type:
|
217 |
# Generate UUID for vote ID and append to list
|
|
|
231 |
elif comment_text in anti_tech_comments:
|
232 |
vote_type = 'agree'
|
233 |
else:
|
234 |
+
vote_type = 'neutral'
|
|
|
235 |
|
236 |
if vote_type:
|
237 |
# Generate UUID for vote ID and append to list
|
|
|
245 |
if not comment_id: continue
|
246 |
|
247 |
# Mostly neutral, some random agree/disagree, many skipped
|
248 |
+
vote_type = random.choice(['neutral'] * 8 + ['agree', 'disagree'])
|
249 |
|
250 |
if vote_type:
|
251 |
# Generate UUID for vote ID and append to list
|
|
|
303 |
"Another set of orders. Understood, sir!",
|
304 |
"Excellent... with this, I will have even greater control over the galaxy... cackles maniacally"
|
305 |
]
|
306 |
+
local_con = None
|
307 |
+
try:
|
308 |
+
local_con = duckdb.connect(database=DB_PATH, read_only=True)
|
309 |
+
# Check if the example topic already exists
|
310 |
+
result = local_con.execute("SELECT * FROM topics WHERE id = ?", [example_topic_id]).fetchone()
|
311 |
+
if result:
|
312 |
+
print(f"INFO: Topic '{example_topic_id}' already exists. Skipping dummy data insertion.")
|
313 |
+
return # Skip adding dummy data if topic exists
|
314 |
+
except Exception as e:
|
315 |
+
# Log error but continue, assuming topic doesn't exist if check fails
|
316 |
+
print(f"WARNING: Error checking for existing topic '{example_topic_id}': {e}")
|
317 |
+
# Don't return, proceed with adding data in case of check error
|
318 |
+
finally:
|
319 |
+
if local_con:
|
320 |
+
local_con.close()
|
321 |
add_example_topic(example_topic_id, example_topic_title, example_topic_description, example_comments)
|
322 |
|
323 |
|
|
|
817 |
FROM comments c
|
818 |
WHERE c.topic_id = ?
|
819 |
AND NOT EXISTS (
|
820 |
+
SELECT * FROM votes v
|
821 |
WHERE v.comment_id = c.id AND v.user_id = ?
|
822 |
)
|
823 |
ORDER BY RANDOM()
|
|
|
1050 |
progress_exists = False
|
1051 |
try:
|
1052 |
local_con = duckdb.connect(database=DB_PATH, read_only=True)
|
1053 |
+
|
1054 |
+
# Check if the user has voted on any comment in this topic
|
1055 |
+
# This requires joining votes with comments to filter by topic_id
|
1056 |
+
voted_result = local_con.execute("""
|
1057 |
+
SELECT 1
|
1058 |
+
FROM votes v
|
1059 |
+
JOIN comments c ON v.comment_id = c.id
|
1060 |
+
WHERE v.user_id = ? AND c.topic_id = ?
|
1061 |
+
LIMIT 1
|
1062 |
+
""", [user_id, topic_id]).fetchone()
|
1063 |
+
|
1064 |
+
# Check if the user has submitted any comment in this topic
|
1065 |
+
commented_result = local_con.execute("""
|
1066 |
+
SELECT 1
|
1067 |
+
FROM comments
|
1068 |
WHERE user_id = ? AND topic_id = ?
|
1069 |
LIMIT 1
|
1070 |
""", [user_id, topic_id]).fetchone()
|
1071 |
+
|
1072 |
+
# Progress exists if the user has either voted or commented in this topic
|
1073 |
+
progress_exists = voted_result is not None or commented_result is not None
|
1074 |
except Exception as e:
|
1075 |
# Log error but don't stop the app. Assume no progress on error.
|
1076 |
st.error(f"Error checking user progress for greeting: {e}")
|