Skip to content

Commit

Permalink
Merge pull request #115 from avantifellows/feat/mark-for-review
Browse files Browse the repository at this point in the history
Adds `marked_for_review` in session answer model
  • Loading branch information
suryabulusu authored Sep 21, 2024
2 parents e0d189d + d9ed4e2 commit fe00455
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class QuestionSetMetric(BaseModel):
num_correct: int
num_wrong: int
num_partially_correct: int
num_marked_for_review: Optional[int] # not there for non-assessment
attempt_rate: float
accuracy_rate: float

Expand All @@ -93,6 +94,7 @@ class SessionMetrics(BaseModel):
total_correct: int
total_wrong: int
total_partially_correct: int
total_marked_for_review: Optional[int] # not there for non-assessment
total_marks: int


Expand Down Expand Up @@ -400,6 +402,7 @@ class SessionAnswer(BaseModel):
answer: answerType = None
visited: bool = False
time_spent: int = None # in seconds
marked_for_review: bool = False
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(default_factory=datetime.utcnow)

Expand All @@ -418,6 +421,7 @@ class UpdateSessionAnswer(BaseModel):
answer: Optional[answerType]
visited: Optional[bool]
time_spent: Optional[int]
marked_for_review: Optional[bool]
updated_at: datetime = Field(default_factory=datetime.utcnow)

class Config:
Expand Down
2 changes: 1 addition & 1 deletion app/routers/session_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def update_session_answer_in_a_session(
session_id - the id of the session
position_index - the position index of the session answer in the session answers array. This corresponds to the position of the question in the quiz
"""
log_message = f"Updating session answer for session: {session_id} at position: {position_index}. The answer is {session_answer.answer}. Visited is {session_answer.visited}. Time spent is {session_answer.time_spent} seconds."
log_message = f"Updating session answer for session: {session_id} at position: {position_index}. The answer is {session_answer.answer}. Visited is {session_answer.visited}. Time spent is {session_answer.time_spent} seconds. Marked for review status is {session_answer.marked_for_review}."
session_answer = remove_optional_unset_args(session_answer)
session_answer = jsonable_encoder(session_answer)

Expand Down
2 changes: 1 addition & 1 deletion app/tests/dummy_data/multiple_question_set_quiz.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"instructions": null,
"image": {
"url": "https://plio-prod-assets.s3.ap-south-1.amazonaws.com/images/afbxudrmbl.png",
"alt_text": "Image"
"alt_text": "Image 1"
},
"options": [
{
Expand Down
18 changes: 18 additions & 0 deletions app/tests/test_session_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ def test_update_session_answer_with_only_visited(self):
# ensure that `answer` is not affected
assert session_answer["answer"] == self.session_answer["answer"]

def test_update_session_answer_with_only_marked_for_review(self):
new_marked_for_review = True
response = self.client.patch(
f"{session_answers.router.prefix}/{self.session_id}/{self.session_answer_position_index}",
json={"marked_for_review": new_marked_for_review},
)
assert response.status_code == 200
response = self.client.get(
f"{session_answers.router.prefix}/{self.session_id}/{self.session_answer_position_index}"
)
session_answer = json.loads(response.content)

# ensure that `marked_for_review` has been updated
assert session_answer["marked_for_review"] == new_marked_for_review

# ensure that `answer` is not affected
assert session_answer["answer"] == self.session_answer["answer"]

def test_update_session_answers_at_specific_positions(self):
# updating all session answers

Expand Down

0 comments on commit fe00455

Please sign in to comment.