Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update exam.question_count calculation #12196

Merged
merged 6 commits into from
May 24, 2024

Conversation

AlexVelezLl
Copy link
Member

Summary

Update the calculation of exam.question_count to take into account the length of the section.questions array instead of the section.question_count since the latter can have a value assigned to it, but the actual value of the section.questions array be empty because it does not has assigned resources.

For both examples below, I created a quiz with 7 questions on the first section and 10 on the second, but in the latter I didnt assinged any resource, so no questions appears on this section.

Before:
Here we have an exam created before these changes:

image
Students see 17 total questions, and "next" button appears, but there are no more questions.

image
Coach reports show x/17 total questions answered.

After:

Here we have an exam created after these changes:

image
Students see right amount of total questions.

image
Coach reports show "all questions answered"

References

Closes #12149

Reviewer guidance

  • Create a quiz with sections without resources. This should not affect the number total questions shown to the students/coaches.

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@AlexVelezLl AlexVelezLl added the TODO: needs review Waiting for review label May 22, 2024
@AlexVelezLl AlexVelezLl requested a review from nucleogenesis May 22, 2024 22:48
@github-actions github-actions bot added APP: Learn Re: Learn App (content, quizzes, lessons, etc.) APP: Coach Re: Coach App (lessons, quizzes, groups, reports, etc.) DEV: frontend SIZE: very small labels May 22, 2024
@@ -278,7 +278,7 @@ export default function useQuizCreation() {
*/
function saveQuiz() {
const totalQuestions = get(allSections).reduce((acc, section) => {
acc += parseInt(section.question_count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nucleogenesis - this value again feels like something we maybe shouldn't even store in the backend, as all it seems to represent is a user intention of how many questions there should be in the section?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point - it can always be derived from the length of questions anyway.

@AlexVelezLl I'll include the removal of saving this in my PR #12200

Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right change for the existing method of saving the question count from the frontend - my only question is whether this is something that needs to happen on the frontend at all?

If the totalQuestions is only set during saving to be set onto the backend (and is otherwise ignored), we could just set this value in the backend by doing a similar operation in the serializer, and then the frontend doesn't need to worry about it at all.

@AlexVelezLl
Copy link
Member Author

Thank you @rtibbles. That makes a lot of sense. I will then move this logic to the serializer.

@nucleogenesis nucleogenesis self-assigned this May 23, 2024
@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... SIZE: small labels May 23, 2024
@@ -137,6 +137,12 @@ def to_internal_value(self, data):
else:
# Otherwise we are just updating the exam, so allow a partial update
self.partial = True

question_sources = data.get("question_sources", [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to update this: https://github.com/learningequality/kolibri/blob/develop/kolibri/core/exams/test/test_exam_api.py#L45 to remove this from the data we send to the backend in tests, and then add a test to assert that the value is properly set on create?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this in #12200 to keep the clean-up separate from the fix here.

@rtibbles rtibbles merged commit b08ed71 into learningequality:develop May 24, 2024
31 checks passed
@AlexVelezLl AlexVelezLl deleted the fix-question-count branch May 24, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Coach Re: Coach App (lessons, quizzes, groups, reports, etc.) APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: backend Python, databases, networking, filesystem... DEV: frontend SIZE: small SIZE: very small TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question/quiz validation error
3 participants