Skip to content

Expose attempt number to python custom grader - #18149

Merged
schenedx merged 4 commits into
openedx:masterfrom
mitodl:pdpinch/expose-attempts
Sep 10, 2018
Merged

Expose attempt number to python custom grader#18149
schenedx merged 4 commits into
openedx:masterfrom
mitodl:pdpinch/expose-attempts

Conversation

@jolyonb

@jolyonb jolyonb commented May 7, 2018

Copy link
Copy Markdown
Contributor

This PR exposes a student's attempt number to a python custom grader, so that the custom grader can implement a "diminishing returns" grading policy. The following OLX code for a problem demonstrates how the attempt number can be accessed by the grader.

<problem>
<script type="text/python" system_path="python_lib">
def gradeit(expect, ans, **kwargs):
    attempt = kwargs["attempt"]
    message = "This is attempt number {}".format(str(attempt))
    return {
        'input_list': [
            { 'ok': True, 'msg': message},
        ]
    }
</script>
<p>Any non-blank answer is correct.</p>
<customresponse cfn="gradeit" expect="(anything)" cfn_extra_args="attempt">
  <textline size="45" correct_answer="(anything)"/>
</customresponse>
</problem>

Special care is taken to pass the correct attempt number through to the grader when performing a regrade.

Mentions: @pdpinch

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @jolyonb! I've created OSPR-2391 to keep track of it in JIRA. JIRA is a place for product owners to prioritize feature reviews by the engineering development teams.

Feel free to add as much of the following information to the ticket:

  • supporting documentation
  • edx-code email threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will still be done via the GitHub pull request interface. As a reminder, our process documentation is here.

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels May 7, 2018
@mduboseedx

Copy link
Copy Markdown
Contributor

jenkins ok to test

@jolyonb

jolyonb commented May 8, 2018

Copy link
Copy Markdown
Contributor Author

jenkins run bokchoy

@mduboseedx

Copy link
Copy Markdown
Contributor

@edx/educator-all Could you take a look at this?

@pdpinch

pdpinch commented Jul 1, 2018

Copy link
Copy Markdown
Contributor

jenkins run all

@pdpinch

pdpinch commented Jul 1, 2018

Copy link
Copy Markdown
Contributor

@jolyonb in writing tests for this, I may have stumbled onto a bug. Should the "attempt" count still be incremented when the student response raises an error (e.g. when there is a codejail exception)?

You can see this manifest in https://build.testeng.edx.org/job/edx-platform-python-unittests-pr/54182/testReport/junit/xmodule.xmodule.tests.test_capa_module/CapaModuleTest/test_submit_problem_error_with_codejail_exception/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be 2, not 1. What's happening is that the student is submitting attempt #2, and the grader needs to know that this is attempt number 2, not attempt number 1.

  • module.attempts points to the number of attempts USED
  • module.lcp.context['attempt'] points to the attempt number that is ABOUT to be used (or was just ATTEMPTED to be used)

@pdpinch

pdpinch commented Jul 3, 2018

Copy link
Copy Markdown
Contributor

@jolyonb tests are passing now, but I'm not convinced I have the correct combination of module.attempts and module.lcp.context['attempt']. There's probably also a couple of cases where I'm unnecessarily testing module.lcp.context['attempt'].

Can you take a look at the changes in test_capa_module.py and let me know if everything is what you expect? Also, I'm open to suggestions on how to make the comments clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one is just first attempt (not still same)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jolyonb Does your comment mean the code comment is confusing?
It's really confusing to me when your PR comment contradicts the code comment you made.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The comment here is confusing; a complete comment would be "Expect that the number of attempts has incremented from 0 to 1, and that the context believes this was attempt 1". On subsequent grades in this function, a regrade is called, which should not increment the attempt number, and hence the context should still think it's attempt 1.

@jolyonb

jolyonb commented Jul 3, 2018

Copy link
Copy Markdown
Contributor Author

@pdpinch This needs a test to show that the variable is being passed into the check function. I believe this should be put in common/lib/capa/capa/tests/test_responsetypes.py, and you can basically copy the function test_function_code_with_extra_args with modifications as described in the details of this PR.

@pdpinch pdpinch changed the title Expose attempt number to python custom grader (WIP) Expose attempt number to python custom grader Aug 3, 2018
@jolyonb

jolyonb commented Aug 3, 2018

Copy link
Copy Markdown
Contributor Author

jenkins run bokchoy

@pdpinch

pdpinch commented Aug 6, 2018

Copy link
Copy Markdown
Contributor

@mduboseedx this is ready again. We added another test.

@mduboseedx

Copy link
Copy Markdown
Contributor

@schenedx I believe this is assigned to your team. Could you or someone else give this a review?

@jolyonb

jolyonb commented Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

Bump...

@mduboseedx

Copy link
Copy Markdown
Contributor

@jolyonb Much like #18158, our Educator team will unable to do any reviews for a few weeks. I'm sorry for the delay, but I'll try to get another group to give this a review.

@pdpinch
pdpinch force-pushed the pdpinch/expose-attempts branch from e7bfb47 to ddd8d41 Compare August 27, 2018 15:50
@pdpinch

pdpinch commented Aug 27, 2018

Copy link
Copy Markdown
Contributor

@mduboseedx this is rebased, is passing tests and I give it a 👍. Can I merge it?

@schenedx schenedx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pdpinch @jolyonb I have a few questions on this PR. Can you guys respond? I am fine with this feature since the code change is super simple.

}

try:
self.lcp.context['attempt'] = self.attempts + 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is just weird to me. Why do we assign the attempt value to the lcp.context before we updated self.attempts counter on line 1221?
Does self.lcp.grade_answers use this key? if it does, why not just move the self.attempts = self.attempts + 1 line up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The whole point of this is to attach the current attempt number to self.lcp.context so that a custom python grader called from self.lcp.grade_answers can access it. Note that if the grader raises an exception (such as unable to parse input etc), the attempt number self.attempts is not incremented. So, on the first attempt, the attempt counter starts at 0, and only increments if a non-exception-raising attempt occurs. However, for the purpose of the grader, that first attempt should be treated as attempt one. Similarly for later attempts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jolyonb I see. Then can you add some comment here to spell out that self.lcp.context['attempt'] is 1 based, but the self.attempts is 0 based? This will help with the person who were as confused as I am.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jolyonb Does your comment mean the code comment is confusing?
It's really confusing to me when your PR comment contradicts the code comment you made.

@edx-status-bot

Copy link
Copy Markdown

Your PR has finished running tests. There were no failures.

@jolyonb

jolyonb commented Aug 30, 2018

Copy link
Copy Markdown
Contributor Author

@schenedx This has been updated with further comments.

@mduboseedx

Copy link
Copy Markdown
Contributor

@schenedx Do you think your comments have been addressed?

@schenedx schenedx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 I'll merge now

@schenedx
schenedx merged commit af3e5ba into openedx:master Sep 10, 2018
@openedx-webhooks

Copy link
Copy Markdown

@jolyonb 🎉 Your pull request was merged!

Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production on Tuesday, September 11, 2018.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR may have caused e2e tests to fail on Stage. E2E tests have failed. https://gocd.tools.edx.org/go/tab/pipeline/history/STAGE_edxapp_M-D

@jolyonb

jolyonb commented Sep 10, 2018

Copy link
Copy Markdown
Contributor Author

I can't seem to access that link on the E2E test fail?

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged open-source-contribution PR author is not from Axim or 2U

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants