General developer forum

Programmatically grading an essay question

 
Picture of Enrique Castro
Programmatically grading an essay question
Core developers

Hi:

I'm working in a quiz report to allow teachers to speed up the grading of essay questions manually.

Many students just tinker with the template answer, add/delete some chars, and then simply save and go for other other questions. The report identifies question attempts with student responses similar to the question's stored template response, and then tries to set the mark, the grade to 0 (zero).

I say tries because all is working but the grade saving. I have ways to set how similar the responses must be, and to get the relevant question usages and questions attempts from quiz. But set grading in the database seems a mistery,

There is a method in question_attemp class

public function manual_grade($comment, $mark, $commentformat = null, $timestamp = null, $userid = null)

question_usage_by_activity class

public function manual_grade($slot, $comment, $mark, $commentformat = null)

But invoking any of them has NO effect  on quiz grades. I do not see any changes in database ( question_attemp or question_attemp_steps) after running any of those methods.

I have tried to add new steps in question_attemp_steps but if also seems not working. In addition, those added steps disappear after a manual regrade of the whole quiz, contrary to properly graded questions (graded through interface).

So, the question is how to save, programmatically, the grade to a question attempt of an essay question? A manual grade but set programmatically, rather than  through the user interface.

Thanks in advance

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Programmatically grading an essay question
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

After doing anything with a question_usage_by_activity class, you need to call the save method to write the change to the database. https://docs.moodle.org/dev/Using_the_question_engine_from_module#Saving_the_usage (This is so that you can make lots of different changes, then have them all written to the database efficiently.)

 
Average of ratings: -
Picture of Enrique Castro
Re: Programmatically grading an essay question
Core developers

OK, thanks a lot Tim.  Now is working.

Sometimes I tend to forget reading the docs and rely on reviewing core code and the doc strings, rather than a proper document. And many times that backfires.

Thanks.

 
Average of ratings: -