Spaces:
Sleeping
Sleeping
File size: 9,479 Bytes
eac70a0 |
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
import streamlit as st
from supabase import create_client, Client
import os
from datetime import datetime, date
import json
def init_supabase():
"""Initialize Supabase client"""
try:
url = st.secrets.get("SUPABASE_URL")
key = st.secrets.get("SUPABASE_KEY")
except:
url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_KEY")
if not url or not key:
st.error("Supabase credentials not found.")
return None
return create_client(url, key)
def test_instructor_notes():
"""Test instructor notes functionality"""
st.title("π§ͺ Instructor Notes Test")
supabase = init_supabase()
if not supabase:
st.error("Failed to initialize Supabase client")
return
try:
# Test 1: Check if instructor_notes table exists
st.subheader("π Testing Database Structure")
try:
response = supabase.table('instructor_notes').select('*').limit(1).execute()
st.success("β
instructor_notes table exists and is accessible")
except Exception as e:
st.error(f"β instructor_notes table error: {str(e)}")
return
# Test 2: Get all users to find instructor and students
st.subheader("π₯ Available Users")
try:
users_response = supabase.table('users').select('*').execute()
if users_response.data:
st.success(f"Found {len(users_response.data)} users:")
# Create a table to display users
user_data = []
instructor_user = None
student_users = []
for user in users_response.data:
user_data.append({
'ID': user.get('id'),
'Username': user.get('username'),
'Full Name': user.get('full_name'),
'Role': user.get('role'),
'Email': user.get('email')
})
if user.get('role') == 'instructor':
instructor_user = user
elif user.get('role') == 'student':
student_users.append(user)
st.dataframe(user_data, use_container_width=True)
if not instructor_user:
st.error("No instructor user found")
return
if not student_users:
st.error("No student users found")
return
st.info(f"Using instructor: {instructor_user.get('username')} (ID: {instructor_user.get('id')})")
st.info(f"Found {len(student_users)} students")
else:
st.error("No users found in database")
return
except Exception as e:
st.error(f"β Error fetching users: {str(e)}")
return
# Test 3: Try to insert a test instructor note
st.subheader("π€ Testing Instructor Notes Insert")
# Create sample attendance data
attendance_data = {
"students": [
{
"student_id": student_users[0]['id'],
"username": student_users[0]['username'],
"full_name": student_users[0]['full_name'],
"present": True,
"late": False,
"notes": "Participated well in today's debate"
}
],
"total_present": 1,
"total_absent": 0
}
# Create sample writing skills notes
writing_skills_notes = {
"students": [
{
"student_id": student_users[0]['id'],
"username": student_users[0]['username'],
"full_name": student_users[0]['full_name'],
"notes": "Shows improvement in case construction. Good use of evidence, needs more variety. Strong affirmative case, negative needs work."
}
]
}
# Create sample debate skills notes
debate_skills_notes = {
"students": [
{
"student_id": student_users[0]['id'],
"username": student_users[0]['username'],
"full_name": student_users[0]['full_name'],
"notes": "Clear articulation, good pace. Good eye contact, needs more confidence. Strong cross-examination, needs work on rebuttals."
}
]
}
# Create sample parent communication notes
parent_communication_notes = {
"students": [
{
"student_id": student_users[0]['id'],
"username": student_users[0]['username'],
"full_name": student_users[0]['full_name'],
"notes": "May need extra help with research. Excellent speaking skills. Consider joining debate club."
}
]
}
# Create sample upcoming events notes
upcoming_events_notes = {
"tournaments": [
{
"name": "Regional Debate Championship",
"date": "2024-02-15",
"location": "City Hall",
"notes": "All students encouraged to participate"
}
],
"important_dates": [
{
"event": "Parent-Teacher Conference",
"date": "2024-01-30",
"notes": "Discuss student progress"
}
]
}
test_data = {
'instructor_id': instructor_user.get('id'),
'class_date': str(date.today()),
'attendance_data': attendance_data,
'writing_skills_notes': writing_skills_notes,
'debate_skills_notes': debate_skills_notes,
'parent_communication_notes': parent_communication_notes,
'upcoming_events_notes': upcoming_events_notes,
'general_notes': 'Test general notes for today\'s class session.'
}
st.write("**Attempting to insert test instructor note:**")
st.json(test_data)
try:
insert_response = supabase.table('instructor_notes').insert(test_data).execute()
st.write(f"**Insert Response:** {insert_response}")
st.write(f"**Response Data:** {insert_response.data}")
st.write(f"**Response Count:** {insert_response.count}")
if insert_response.data:
st.success("β
Test instructor note inserted successfully!")
else:
st.error("β No data returned from insert")
except Exception as e:
st.error(f"β Insert failed: {str(e)}")
# Test 4: Try to retrieve the test instructor note
st.subheader("π₯ Testing Instructor Notes Retrieval")
try:
retrieve_response = supabase.table('instructor_notes').select('*').eq('instructor_id', instructor_user.get('id')).order('class_date', desc=True).limit(1).execute()
st.write(f"**Retrieve Response:** {retrieve_response}")
st.write(f"**Retrieve Data:** {retrieve_response.data}")
st.write(f"**Retrieve Count:** {retrieve_response.count}")
if retrieve_response.data:
st.success("β
Test instructor note retrieved successfully!")
st.json(retrieve_response.data[0])
else:
st.warning("β οΈ No instructor note found (insert may have failed)")
except Exception as e:
st.error(f"β Retrieve failed: {str(e)}")
# Test 5: Test getting all notes for instructor
st.subheader("π All Instructor Notes")
try:
all_notes_response = supabase.table('instructor_notes').select('*').eq('instructor_id', instructor_user.get('id')).order('class_date', desc=True).execute()
if all_notes_response.data:
st.success(f"β
Found {len(all_notes_response.data)} instructor notes:")
for i, note in enumerate(all_notes_response.data):
with st.expander(f"Note {i+1}: {note['class_date']}", expanded=False):
st.write(f"**Class Date:** {note['class_date']}")
st.write(f"**Created:** {note['created_at']}")
st.write(f"**Attendance:** {note['attendance_data']['total_present']} present, {note['attendance_data']['total_absent']} absent")
if note['general_notes']:
st.write(f"**General Notes:** {note['general_notes']}")
else:
st.info("βΉοΈ No instructor notes found")
except Exception as e:
st.error(f"β Error fetching all notes: {str(e)}")
except Exception as e:
st.error(f"β Test failed: {str(e)}")
if __name__ == "__main__":
test_instructor_notes() |