mitodl / mitx-grading-library

The MITx Grading Library, a python grading library for edX
https://edge.edx.org/courses/course-v1:MITx+grading-library+examples/
BSD 3-Clause "New" or "Revised" License
14 stars 9 forks source link

Fixing Unicode #152

Closed jolyonb closed 6 years ago

jolyonb commented 6 years ago

So, it turns out that edX sends us a unicode version of the expect string, not a string version. This fixes the appropriate pieces and makes everything work on edX :-)

jolyonb commented 6 years ago

With this fix, the following code works in edX!!!

<problem>
<script type="loncapa/python">
from mitxgraders import *
</script>

<customresponse cfn="FormulaGrader(variables=['x'])" answer="2*x" >
  <textline math="true" />
</customresponse>

</problem>

Putting primes in variable names is a bit annoying, alas - you need to do XML escaping. However, for simple things, this is beautiful!

jolyonb commented 6 years ago

Time to do some large scale restructuring of the documentation, I guess...

ChristopherChudzicki commented 6 years ago

This is cool!

Re:

Time to do some large scale restructuring of the documentation, I guess...

It probably boils down to personal preference... I think that if I were writing a large number of problems, I would try to use essentially the same customresponse tag for all problems, and have the tag attributes reference python variables $grader and $expect. Something like:

<problem>
<script type="loncapa/python">
from mitxgraders import *
expect = 'x^2'
grader = FormulaGrader(answers=expect, variables=['x'])
</script>

<customresponse cfn="$grader" expect="$expect">
  <textline math="true" />
</customresponse>

</problem>

If you decided to do this, we could even expose grader.config['answers'][0]['expect'] as grader.expect (if it exists and is unique, or expose the single answer with 'ok': True).

jolyonb commented 6 years ago

I'm more thinking about writing a script to translate old problems to use our library, at least for the improved JS preprocessing and the improved error message. Being able to inline things makes that much easier!