Spaces:
Sleeping
Sleeping
Download scripts/inspect_current_data.py from baljot07/studiq-backend: direct link, hf CLI and curl.
- Browser
- Download file 5.24 kB
-
https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/scripts/inspect_current_data.py
- Command line
-
hf download hf://spaces/baljot07/studiq-backend/scripts/inspect_current_data.py
-
curl -L -o inspect_current_data.py https://huggingface.co/spaces/baljot07/studiq-backend/resolve/main/scripts/inspect_current_data.py
5.24 kB
| import asyncio | |
| import os | |
| import json | |
| from dotenv import load_dotenv | |
| import asyncpg | |
| load_dotenv(".env") | |
| db_url = os.getenv("DATABASE_URL") | |
| async def main(): | |
| conn = await asyncpg.connect(db_url) | |
| print("=================== 1. ALL TABLES IN SUPABASE ===================") | |
| tables = await conn.fetch(""" | |
| SELECT table_name | |
| FROM information_schema.tables | |
| WHERE table_schema = 'public' | |
| ORDER BY table_name; | |
| """) | |
| for t in tables: | |
| tname = t["table_name"] | |
| cnt = await conn.fetchval(f'SELECT COUNT(*) FROM "{tname}"') | |
| print(f" • {tname:<25} : {cnt} rows") | |
| print("\n=================== 2. USER PROFILE DATA ===================") | |
| users = await conn.fetch('SELECT * FROM "users"') | |
| for u in users: | |
| u_dict = dict(u) | |
| print(f" ID: {u_dict.get('id')}") | |
| print(f" Name: {u_dict.get('name')}") | |
| print(f" Email: {u_dict.get('email')}") | |
| print(f" Course: {u_dict.get('course')}") | |
| print(f" Semester: {u_dict.get('semester')}") | |
| print(f" University: {u_dict.get('university_name')}") | |
| print(f" Onboarding Complete: {u_dict.get('onboarding_complete')}") | |
| print(f" Has Syllabus: {u_dict.get('has_syllabus')}") | |
| print(f" Gamification: Level {u_dict.get('level')}, XP {u_dict.get('xp_total')}, Coins {u_dict.get('coins')}, Streak {u_dict.get('streak_days')}") | |
| print(f" Tokens Consumed: {u_dict.get('tokens_consumed')}") | |
| print(f" Total Messages: {u_dict.get('total_messages_sent')}") | |
| print(f"\n Preferences:\n{json.dumps(u_dict.get('preferences'), indent=4) if u_dict.get('preferences') else 'None'}") | |
| print(f"\n User Facts (Memory/Persona):\n{u_dict.get('user_facts')}") | |
| print("\n=================== 3. CONVERSATIONS (7) ===================") | |
| convs = await conn.fetch('SELECT id, title, is_pinned, created_at, updated_at FROM "conversations" ORDER BY created_at ASC') | |
| for c in convs: | |
| created_str = c['created_at'].strftime('%Y-%m-%d %H:%M') | |
| print(f" • {created_str} | Title: \"{c['title']}\" (ID: {c['id']})") | |
| print("\n=================== 4. DAILY MEMORIES (2) ===================") | |
| mems = await conn.fetch('SELECT * FROM "daily_memories"') | |
| for m in mems: | |
| m_dict = dict(m) | |
| print(f" • Date: {m_dict.get('date')}") | |
| print(f" Summary:\n{m_dict.get('summary')}\n") | |
| print("\n=================== 5. STUDY PLANS (1) ===================") | |
| plans = await conn.fetch('SELECT id, active, starts_at, ends_at, plan_data FROM "study_plans"') | |
| for p in plans: | |
| m_dict = dict(p) | |
| pd = m_dict.get("plan_data") | |
| print(f" • Plan ID: {m_dict.get('id')} | Active: {m_dict.get('active')} | {m_dict.get('starts_at')} to {m_dict.get('ends_at')}") | |
| if isinstance(pd, str): | |
| pd = json.loads(pd) | |
| if isinstance(pd, dict): | |
| print(f" Duration Days: {pd.get('duration_days')}") | |
| print(f" Days count: {len(pd.get('days', []))}") | |
| for day in pd.get('days', []): | |
| print(f" - Day {day.get('day_number')} ({day.get('date')}): {day.get('focus_area')}") | |
| print("\n=================== 6. STUDY NOTES (24) ===================") | |
| notes = await conn.fetch('SELECT id, topic_name, subject_name, bookmarked, created_at, content FROM "study_notes" ORDER BY created_at DESC') | |
| for n in notes: | |
| content_preview = n['content'].replace('\n', ' ')[:90] | |
| print(f" • [{n['created_at'].strftime('%Y-%m-%d %H:%M')}] Subject: {n['subject_name']} | Topic: {n['topic_name']}") | |
| print(f" Preview: {content_preview}...") | |
| print("\n=================== 7. USER PROGRESS (103 topics) ===================") | |
| prog_stats = await conn.fetch(""" | |
| SELECT status, COUNT(*) as count | |
| FROM user_progress | |
| GROUP BY status | |
| """) | |
| for ps in prog_stats: | |
| print(f" • Status \"{ps['status']}\": {ps['count']} topics") | |
| non_zero = await conn.fetch("SELECT * FROM user_progress WHERE status != 'not_started'") | |
| print(f" Topics with active progress: {len(non_zero)}") | |
| for nz in non_zero: | |
| d = dict(nz) | |
| print(f" - Topic ID: {d.get('topic_id')} | Status: {d.get('status')} | Mastery: {d.get('mastery_score')} | Review: {d.get('next_review_date')}") | |
| print("\n=================== 8. CHAT MESSAGES SUMMARY (54) ===================") | |
| msg_count = await conn.fetchval('SELECT COUNT(*) FROM "messages"') | |
| user_msg_count = await conn.fetchval("SELECT COUNT(*) FROM \"messages\" WHERE role = 'user'") | |
| ai_msg_count = await conn.fetchval("SELECT COUNT(*) FROM \"messages\" WHERE role = 'assistant'") | |
| print(f" Total Messages: {msg_count} (User: {user_msg_count}, AI: {ai_msg_count})") | |
| last_5 = await conn.fetch('SELECT role, content, created_at FROM "messages" ORDER BY created_at DESC LIMIT 5') | |
| print("\n Latest 5 Messages:") | |
| for m in reversed(last_5): | |
| preview = m['content'].replace('\n', ' ')[:100] | |
| print(f" [{m['role'].upper()}] ({m['created_at'].strftime('%Y-%m-%d %H:%M')}): {preview}...") | |
| await conn.close() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |