Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Team6CMT313_Assessment2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wen-Hsuan Hu
Team6CMT313_Assessment2
Commits
b884f4f2
Commit
b884f4f2
authored
5 months ago
by
yazSpaz
Browse files
Options
Downloads
Patches
Plain Diff
test review works for newly created tests
parent
1774873f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/SQLs/init.sql
+3
-0
3 additions, 0 deletions
app/SQLs/init.sql
app/routes.py
+61
-3
61 additions, 3 deletions
app/routes.py
app/your_database_name.db
+0
-0
0 additions, 0 deletions
app/your_database_name.db
with
64 additions
and
3 deletions
app/SQLs/init.sql
+
3
−
0
View file @
b884f4f2
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
app/routes.py
+
61
−
3
View file @
b884f4f2
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
app/your_database_name.db
+
0
−
0
View file @
b884f4f2
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment