Skip to content
Snippets Groups Projects
Commit b884f4f2 authored by yazSpaz's avatar yazSpaz
Browse files

test review works for newly created tests

parent 1774873f
Branches
No related tags found
No related merge requests found
......@@ -101,9 +101,12 @@ VALUES
-- Insert data into test_attempt table
INSERT INTO test_questions (test_id, question_id, question_type)
VALUES
-- FOR TEST 1
(1, 1, "MCQ"), (1, 2, "MCQ"), (1, 1, "FIB"),
-- FOR BASIC SQL TEST
(3, 3, "MCQ"), (3, 4, "MCQ"), (3, 5, "MCQ"), (3, 6, "MCQ"), (3, 7, "MCQ"), (3, 8, "MCQ"), (3, 9, "MCQ"), (3, 10, "MCQ"), (3, 11, "MCQ"), (3, 12, "MCQ"),
(3, 2, "FIB"), (3, 3, "FIB"), (3, 4, "FIB"), (3, 5, "FIB"), (3, 6, "FIB");
-- Insert data into test_attempt table
INSERT INTO test_attempt (student_id, test_id, score, time_taken)
VALUES
......
......@@ -2,7 +2,7 @@ from flask import Blueprint, render_template, jsonify, request, redirect, url_fo
from flask_login import login_user, login_required, logout_user, current_user
from app.models import db , TestResult, QuestionAnswer, Feedback, students ,teachers ,FIB, MCQ, TestORM, ModuleORM, TestQuestion
from werkzeug.security import check_password_hash, generate_password_hash
from sqlalchemy import text
from sqlalchemy import text, bindparam
from sqlalchemy.orm import joinedload
from app.models import *
from datetime import date, datetime
......@@ -190,9 +190,66 @@ def getTestDetails():
print("NO TEST ID GIVEN!")
return jsonify({"error": "Test ID is required"}), 400
# Get all test questions for this test_id
stmt = text("""
SELECT question_id, question_type
FROM test_questions
WHERE test_id = :test_id
""")
result = db.session.execute(stmt, {"test_id": test_id}).fetchall()
# Split question IDs by type
mcq_ids = [row[0] for row in result if row[1] == 'MCQ']
fib_ids = [row[0] for row in result if row[1] == 'FIB']
mcq_questions = []
fib_questions = []
if mcq_ids:
mcq_stmt = text("""
SELECT id, question, option_A, option_B, option_C, option_D, answer, difficulty, learning_obj
FROM MCQ
WHERE id IN :mcq_ids
""").bindparams(bindparam("mcq_ids", expanding=True))
mcq_results = db.session.execute(mcq_stmt, {"mcq_ids": mcq_ids}).fetchall()
mcq_questions = [
{
"id": row[0],
"question": row[1],
"options": [row[2], row[3], row[4], row[5]],
"answer": row[6],
"difficulty": ("Difficulty." + str(row[7])) if row[7] else None,
"learning_obj": ("LearningObjective." + str(row[8])) if row[8] else None,
}
for row in mcq_results
]
if fib_ids:
fib_stmt = text("""
SELECT id, question, answer, difficulty, learning_obj
FROM FIB
WHERE id IN :fib_ids
""").bindparams(bindparam("fib_ids", expanding=True))
fib_results = db.session.execute(fib_stmt, {"fib_ids": fib_ids}).fetchall()
fib_questions = [
{
"id": row[0],
"question": row[1],
"answer": row[2],
"difficulty": ("Difficulty." + str(row[3])) if row[3] else None,
"learning_obj": ("LearningObjective." + str(row[4])) if row[4] else None,
}
for row in fib_results
]
#print(mcq_questions)
# Get questions
mcq_questions = TestDAO.getMCQQuestionsByTest(test_id, db)
fib_questions = TestDAO.getFIBQuestionsByTest(test_id, db)
#mcq_questions = TestDAO.getMCQQuestionsByTest(test_id, db)
#fib_questions = TestDAO.getFIBQuestionsByTest(test_id, db)
# Get students and attempts
students = TestDAO.getStudentsByTest(test_id, db)
......@@ -213,6 +270,7 @@ def getTestDetails():
'students': students,
'test_attempts': filtered_attempts
})
@routes_bp.route('/getStudentQuestions', methods=['POST'])
def getStudentQuestions():
data = request.get_json()
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment