Skip to content

Commit

Permalink
Revert "Merge branch 'feat/omr-mode-update' of https://github.com/ava…
Browse files Browse the repository at this point in the history
…ntifellows/quiz-backend into feat/has-quiz-end"

This reverts commit cd86e54, reversing
changes made to dde2824.
  • Loading branch information
suryabulusu committed Oct 21, 2024
1 parent cd86e54 commit 94023fe
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 87 deletions.
1 change: 0 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ class Session(BaseModel):
created_at: datetime = Field(default_factory=datetime.utcnow)
events: List[Event] = []
has_quiz_ended: bool = False
omr_mode: bool = False
metrics: Optional[SessionMetrics] = None # gets updated when quiz ends

class Config:
Expand Down
12 changes: 6 additions & 6 deletions app/routers/quizzes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, status, HTTPException, Query
from fastapi import APIRouter, status, HTTPException
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from database import client
Expand Down Expand Up @@ -139,8 +139,8 @@ async def create_quiz(quiz: Quiz):


@router.get("/{quiz_id}", response_model=GetQuizResponse)
async def get_quiz(quiz_id: str, omr_mode: bool = Query(False)):
logger.info(f"Starting to get quiz: {quiz_id} with omr_mode={omr_mode}")
async def get_quiz(quiz_id: str):
logger.info(f"Starting to get quiz: {quiz_id}")
quiz_collection = client.quiz.quizzes

if (quiz := quiz_collection.find_one({"_id": quiz_id})) is None:
Expand All @@ -151,19 +151,19 @@ async def get_quiz(quiz_id: str, omr_mode: bool = Query(False)):

update_quiz_for_backwards_compatibility(quiz_collection, quiz_id, quiz)

if omr_mode is False and (
if (
"metadata" not in quiz
or quiz["metadata"] is None
or "quiz_type" not in quiz["metadata"]
or quiz["metadata"]["quiz_type"] != QuizType.omr.value
):
logger.warning(
f"omr_mode is False and Quiz {quiz_id} does not have metadata or is not an OMR quiz, skipping option count calculation"
f"Quiz {quiz_id} does not have metadata or is not an OMR quiz, skipping option count calculation"
)

else:
logger.info(
f"Quiz has to be rendered in OMR Mode, calculating options count for quiz: {quiz_id}"
f"Quiz is an OMR type, calculating options count for quiz: {quiz_id}"
)
question_set_ids = [
question_set["_id"] for question_set in quiz["question_sets"]
Expand Down
20 changes: 3 additions & 17 deletions app/routers/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,6 @@ async def create_session(session: Session):
logger.info(
f"No meaningful event has occurred in last_session. Returning this session which has id {last_session['_id']}"
)
# copy the omr mode value if changed (changes when toggled in UI)
if last_session["omr_mode"] != session.omr_mode:
last_session["omr_mode"] = session.omr_mode
logger.info("Updating omr_mode value in last_session")
update_result = client.quiz.sessions.update_one(
{"_id": last_session["_id"]}, {"$set": last_session}
)
if not update_result.acknowledged:
logger.error("Failed to update last session's omr_mode value")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Failed to update last session's omr_mode value",
)

return JSONResponse(
status_code=status.HTTP_201_CREATED, content=last_session
)
Expand All @@ -126,7 +112,7 @@ async def create_session(session: Session):
# so, we HAVE to distinguish between current_session and last_session by creating
# a new session for current_session
logger.info(
f"Some meaningful event has occurred in last_session, creating new session for user: {session.user_id} and quiz: {session.quiz_id} with {session.omr_mode} as omr_mode"
f"Some meaningful event has occurred in last_session, creating new session for user: {session.user_id} and quiz: {session.quiz_id}"
)
current_session["is_first"] = False
current_session["events"] = last_session.get("events", [])
Expand Down Expand Up @@ -154,11 +140,11 @@ async def create_session(session: Session):
result = client.quiz.sessions.insert_one(current_session)
if result.acknowledged:
logger.info(
f"Created new session with id {result.inserted_id} for user: {session.user_id} and quiz: {session.quiz_id} with {session.omr_mode} as omr_mode"
f"Created new session with id {result.inserted_id} for user: {session.user_id} and quiz: {session.quiz_id}"
)
else:
logger.error(
f"Failed to insert new session for user: {session.user_id} and quiz: {session.quiz_id} and omr_mode: {session.omr_mode}"
f"Failed to insert new session for user: {session.user_id} and quiz: {session.quiz_id}"
)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
Expand Down
37 changes: 0 additions & 37 deletions app/scripts/update_session_for_omr_quizzes.py

This file was deleted.

11 changes: 0 additions & 11 deletions app/tests/test_quizzes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ def test_get_quiz_if_id_valid(self):
== self.short_homework_quiz_questions_length
)

def test_get_quiz_if_id_valid_and_omr_mode_in_params(self):
response = self.client.get(
f"{quizzes.router.prefix}/{self.multi_qset_quiz_id}",
params={"omr_mode": True},
)
assert response.status_code == 200
response = response.json()
assert self.multi_qset_quiz_lengths == [
len(response["question_sets"][i]["questions"]) for i in range(2)
]

def test_get_quiz_returns_error_if_id_invalid(self):
response = self.client.get(f"{quizzes.router.prefix}/00")
assert response.status_code == 404
Expand Down
16 changes: 1 addition & 15 deletions app/tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_gets_session_with_valid_id(self):
)
assert response.status_code == 200
session = response.json()
for key in ["quiz_id", "user_id", "omr_mode"]:
for key in ["quiz_id", "user_id"]:
assert session[key] == self.homework_session[key]

def test_get_session_returns_error_if_id_invalid(self):
Expand Down Expand Up @@ -79,20 +79,6 @@ def test_create_session_with_previous_session_and_no_event(self):

assert len(response["events"]) == 0
assert response["is_first"] is True
assert response["omr_mode"] is False

def test_create_session_with_previous_session_and_change_in_omr_mode(self):
# second session with no start-quiz event in first session
# but with a different omr_mode value
response = self.client.post(
sessions.router.prefix + "/",
json={"quiz_id": self.timed_quiz["_id"], "user_id": 1, "omr_mode": True},
).json()

assert len(response["events"]) == 0
assert response["is_first"] is True
assert response["omr_mode"] is True
# despite change in omr_mode, since no event has occurred, same session is returned

def test_create_session_with_previous_session_and_start_event(self):
session_updates = {"event": EventType.start_quiz.value}
Expand Down

0 comments on commit 94023fe

Please sign in to comment.