Spaces:
Sleeping
Sleeping
Add readable Supabase submission reports
Browse filesFiles changed (4)
14 unmodified lines1516171819202116 unmodified lines38394041424344454614 unmodified lines1. Open the project dashboard and select **SQL Editor**.2. Open `supabase_schema.sql` from this repository and copy its contents into a new SQL query.3. Run the query. It creates the `public.submissions` table, indexes the fields used for search, enables RLS, and removes direct access for `anon` and `authenticated` roles.4. The app uses a server-only Supabase secret key. Never put that key in source code, Google Sheets, or browser code.## 3. Add the project secrets to the Space16 unmodified lines## 4. Verify1. In the Supabase dashboard, open **Table Editor → submissions**.2. Submit one challenge in the app.3. Confirm that a row appears with the student, challenge, score, and a complete `payload` JSON record.4. Submit again and confirm that each run appears as its own row.Supabase failures leave the local JSON record intact and are reported in its `cloud.supabase` status. Git backup uploads are disabled; existing Git history is not deleted by this change. Google Sheets remains an optional summary destination.14 unmodified lines1516171819202116 unmodified lines38394041424344454614 unmodified lines1. Open the project dashboard and select **SQL Editor**.2. Open `supabase_schema.sql` from this repository and copy its contents into a new SQL query.3. Run the query. It creates the `public.submissions` table, adds the `review_report` column, backfills readable reports for existing rows, indexes fields used for search, enables RLS, and removes direct access for `anon` and `authenticated` roles. It is safe to run again; existing reports are not overwritten.4. The app uses a server-only Supabase secret key. Never put that key in source code, Google Sheets, or browser code.## 3. Add the project secrets to the Space16 unmodified lines## 4. Verify1. In the Supabase dashboard, open **Table Editor → submissions**.4. Submit one new challenge in the app.5. Confirm a row appears with the student, challenge, score, readable `review_report`, and complete `payload` JSON record.6. Submit again and confirm each run appears as its own row.Supabase failures leave the local JSON record intact and are reported in its `cloud.supabase` status. Git backup uploads are disabled; existing Git history is not deleted by this change. Google Sheets remains an optional summary destination.
13 unmodified lines1415161718192021222313 unmodified linespassed_tests integer,total_tests integer,submission_outcome text,payload jsonb not null,created_at timestamptz not null default now());create index if not exists submissions_provider_user_id_idxon public.submissions (provider_user_id);create index if not exists submissions_submitted_at_idx13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464713 unmodified linespassed_tests integer,total_tests integer,submission_outcome text,review_report text,payload jsonb not null,created_at timestamptz not null default now());alter table public.submissionsadd column if not exists review_report text;update public.submissionsset review_report = concat_ws(E'\n\n','SUBMISSION REVIEW: ' || submission_id,'Student: ' || coalesce(payload #>> '{student,name}', student_name),'Hugging Face: ' || coalesce(payload #>> '{student,provider_user_id}', '(not provided)'),'Challenge: ' || coalesce(payload #>> '{challenge,challenge_id}', challenge_id, '(not provided)'),'Repository: ' || coalesce(payload #>> '{challenge,repo_url}', repo_url, '(not provided)'),'What was the bug:' || E'\n' || coalesce(payload #>> '{challenge,bug_description}', '(not provided)'),'Challenge summary:' || E'\n' || coalesce(payload #>> '{challenge,challenge_summary}', '(not provided)'),'Buggy code given to the student:' || E'\n' || coalesce(payload #>> '{challenge,buggy_code}', '(not provided)'),'Student changes (diff):' || E'\n' || coalesce(payload #>> '{submission,student_diff}', '(not provided)'),'Expected fix:' || E'\n' || coalesce(payload #>> '{challenge,expected_fixed_code}', '(not provided)'),'Test results:' || E'\n' || coalesce(jsonb_pretty(payload -> 'tests'), '(not provided)'),'Scoring:' || E'\n' || coalesce(jsonb_pretty(payload -> 'scoring'), '(not provided)'),'Chat history:' || E'\n' || coalesce(jsonb_pretty(payload #> '{submission,chat_history}'), '(not provided)'))where review_report is nulland payload is not null;create index if not exists submissions_provider_user_id_idxon public.submissions (provider_user_id);create index if not exists submissions_submitted_at_idx
38 unmodified lines39404142434420 unmodified lines65666768697038 unmodified linesreturn headersdef _submission_row(record: dict[str, Any]) -> dict[str, Any]:student = record.get("student") or {}challenge = record.get("challenge") or {}20 unmodified lines"passed_tests": tests.get("passed_tests"),"total_tests": tests.get("total_tests"),"submission_outcome": scoring.get("submission_outcome") or None,"payload": payload,}38 unmodified lines3940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311420 unmodified lines13513613713813914014138 unmodified linesreturn headersdef _report_value(value: Any) -> str:return str(value).strip() if value not in (None, "") else "(not provided)"def _report_section(title: str, value: Any) -> str:return f"{title}\n{'=' * len(title)}\n{_report_value(value)}"def _build_review_report(record: dict[str, Any]) -> str:student = record.get("student") or {}challenge = record.get("challenge") or {}submission = record.get("submission") or {}tests = record.get("tests") or {}scoring = record.get("scoring") or {}per_test_before = {item.get("num"): item.get("status") for item in tests.get("per_test_before", [])}per_test_after = {item.get("num"): item.get("status") for item in tests.get("per_test_after", [])}test_numbers = sorted(set(per_test_before) | set(per_test_after))lines = [f"SUBMISSION REVIEW: {record.get('submission_id', '(unknown)')}","=" * 72,f"Student: {_report_value(student.get('name'))}",f"Hugging Face: {_report_value(student.get('provider_user_id'))}",f"Submitted: {_report_value(record.get('timestamp'))}",f"Challenge: {_report_value(challenge.get('challenge_id'))}",f"Repository: {_report_value(challenge.get('repo_url'))}",f"Target file: {_report_value(challenge.get('target_file'))}",f"Attempt: {_report_value(submission.get('attempt_number'))}","",_report_section("WHAT WAS THE BUG?", challenge.get("bug_description")),_report_section("CHALLENGE SUMMARY", challenge.get("challenge_summary")),_report_section("BUGGY CODE GIVEN TO THE STUDENT", challenge.get("buggy_code")),_report_section("STUDENT'S CHANGES (DIFF)", submission.get("student_diff")),_report_section("EXPECTED FIX", challenge.get("expected_fixed_code")),"TEST RESULTS (before -> after)","==============================",f"Before: {tests.get('before_passed', 0)}/{tests.get('before_total', 0)} passed",f"After: {tests.get('passed_tests', 0)}/{tests.get('total_tests', 0)} passed",]for number in test_numbers:lines.append(f"Test {number}: {per_test_before.get(number, '-')} -> {per_test_after.get(number, '-')}")lines.extend(["",f"LLM score: {_report_value(scoring.get('llm_score'))}",f"Hint penalty: {_report_value(scoring.get('hint_penalty'))}",f"Final score: {_report_value(scoring.get('total_score'))}",f"Outcome: {_report_value(scoring.get('submission_outcome'))}",_report_section("SCORING EXPLANATION", scoring.get("llm_explanation")),_report_section("FULL TEST OUTPUT", tests.get("test_output")),"CHAT HISTORY","============",])chat_history = submission.get("chat_history") or []if not chat_history:lines.append("No chat history recorded.")else:for index, item in enumerate(chat_history, 1):label = "HINT" if item.get("gave_hint") else "CHAT"lines.extend([f"[{index}] {label}",f"Student: {_report_value(item.get('question'))}",f"Assistant: {_report_value(item.get('response'))}","",])return "\n".join(lines)def _submission_row(record: dict[str, Any]) -> dict[str, Any]:student = record.get("student") or {}challenge = record.get("challenge") or {}20 unmodified lines"passed_tests": tests.get("passed_tests"),"total_tests": tests.get("total_tests"),"submission_outcome": scoring.get("submission_outcome") or None,"review_report": _build_review_report(record),"payload": payload,}
20 unmodified lines2122232425262728293031323334353626 unmodified lines63646566676820 unmodified lines"challenge_id": "boltons:utils","repo_url": "https://github.com/mahmoud/boltons","target_file": "utils.py",},"submission": {"attempt_number": 1,"hints_used": 2,"student_code": "print(1)",},"tests": {"passed_tests": 4, "total_tests": 5},"scoring": {"llm_score": 80,"total_score": 76,"submission_outcome": "partial_fix",},}26 unmodified linesself.assertEqual(headers["apikey"], "sb_secret_test")self.assertNotIn("authorization", headers)self.assertEqual(payload["provider_user_id"], "alice")stored_record = payload["payload"]self.assertEqual(stored_record.pop("cloud")["supabase"]["status"], "success")self.assertEqual(stored_record, self.record)20 unmodified lines21222324252627282930313233343536373839404142434445464748495051525354555626 unmodified lines8384858687888990919293949520 unmodified lines"challenge_id": "boltons:utils","repo_url": "https://github.com/mahmoud/boltons","target_file": "utils.py","bug_description": "The function drops the final item.","challenge_summary": "Repair the iteration behavior.","buggy_code": "def items(): return [1]","expected_fixed_code": "def items(): return [1, 2]",},"submission": {"attempt_number": 1,"hints_used": 2,"student_code": "print(1)","student_diff": "- return [1]\n+ return [1, 2]","chat_history": [{"question": "Why is the last value missing?","response": "Check the loop boundary.","gave_hint": True,}],},"tests": {"before_passed": 1,"before_total": 5,"passed_tests": 4,"total_tests": 5,"test_output": "Test 1: PASS","per_test_before": [{"num": 1, "status": "FAIL"}],"per_test_after": [{"num": 1, "status": "PASS"}],},"scoring": {"llm_score": 80,"total_score": 76,"hint_penalty": 4,"llm_explanation": "The fix restores the final value.","submission_outcome": "partial_fix",},}26 unmodified linesself.assertEqual(headers["apikey"], "sb_secret_test")self.assertNotIn("authorization", headers)self.assertEqual(payload["provider_user_id"], "alice")report = payload["review_report"]self.assertIn("WHAT WAS THE BUG?", report)self.assertIn("The function drops the final item.", report)self.assertIn("STUDENT'S CHANGES (DIFF)", report)self.assertIn("Test 1: FAIL -> PASS", report)self.assertIn("Final score: 76", report)self.assertIn("Check the loop boundary.", report)stored_record = payload["payload"]self.assertEqual(stored_record.pop("cloud")["supabase"]["status"], "success")self.assertEqual(stored_record, self.record)
SUPABASE_SETUP.md+4-4
supabase_schema.sql+24
supabase_submissions_logger.py+71
test_supabase_submissions_logger.py+28-1