per student generated data and question states/attempts

per student generated data and question states/attempts

by Leif Johnson -
Number of replies: 14
Hi,

I'm working on a question type (inside of moodle 1.8) that has generated data for each student-attempt. At this point, the data includes images and Rdata files (saved files from "R"). My question is:

What's the best way to go about storing them?

I'd like them to be properly linked to the question-attempts so they get deleted at appropriate times. I could encode them and store them in the answer field in the question_states table, but that seems abusive. I also wonder about the speed of getting the images out of the table for display to students.

I could also store them on disk, but how would I make sure they get deleted properly?

thanks,
leif
Average of ratings: -
In reply to Leif Johnson

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Per student-attempt files was only introduced in Moodle 1.9, as part of the work Adrianne Boyd did over last summer on the file upload question type.
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Leif Johnson -
Per student-attempt files was only introduced in Moodle 1.9, as part of the work Adrianne Boyd did over last summer on the file upload question type.

So there's a nice solution in 1.9, but not 1.8?

Is there a better (better in a way that will be more accepted in moodle) for 1.8 than abusing the 'answer' field in question_states?

My other thought is to put them on disk, labeled in such a way that the filename will describe the student-attempt. Then make a tool that will delete files that no longer have an associated student-attempt. It's crude, but not ridiculous.

leif
In reply to Leif Johnson

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Or find the bits of code that were added to Moodle 1.9 to enable this, and manually apply those patches to your Moodle 1.8. Since the tracker now shows you what code was changed in order to fix each bug/feature request, it may not be that hard. It wasn't very much code.
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Leif Johnson -
Since the tracker now shows you what code was changed in order to fix each bug/feature request

That's a nice feature! Unfortunately, the 1.8 part comes from aiming for the university moodle server, which is on 1.8 and out of my control. I don't think I could convince them to do something like that. So I probably need a 1.8 standard solution.
In reply to Leif Johnson

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think you cannot implement this entirely within a question type, it needs some support form core code. I think you should at least find and analyse what the changes were. Here you go: http://tracker.moodle.org/browse/MDL-10198?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

It seems to be one new file question/file.php, and one new function in mod/quiz/lib.php. Since it is just adding stuff, it won't break any existing funcitonality.
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Leif Johnson -
Thanks for the link. I'm going to see how accepting they are of such a patch.

If the answer is "no way", I was thinking that I could do it by abusing the file storage a little. The question would have it's own directory to put stuff in (in an organized manner). Then it would have a tool that would need to be run periodically to clean up files that no longer have an attempt to be associated with. No where near as clean as the new functionality in moodle, but passable.

leif
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Leif Johnson -
hi again,

As far as I can tell, this functionality doesn't delete the files when the attempt is deleted. Is this correct?

I just download moodle-1.9 latest today to double check and I found that it stores the files in:
$CFG->dataroot.'/questionattempt/attemptid/questionid/filename.ext'

So I checked the source and found that there were no other meaningful references to 'questionattempt'.
leif@indurain:~/Desktop/moodle$ find . -name "*php" | xargs grep -n questionattempt
./lang/en_utf8/quiz.php:154:$string['deletingquestionattempts'] = 'Deleting question attempts';
./question/file.php:2: // This script fetches files from the dataroot/questionattempt directory
./question/file.php:28: $pathname = $CFG->dataroot.'/questionattempt'.$relativepath;

leif
In reply to Leif Johnson

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Question types that use per-attempt files, must clean up after themselves by using the function delete_states. For example:

http://cvs.moodle.org/contrib/plugins/question/type/fileresponse/questiontype.php?view=markup

However, that seems to rely on quiz_file_area_name, which I can't find. Oops.
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Leif Johnson -
I see. I think my understanding of how this works was a little wrong.

Would this function (quiz_file_area_name) would go in:
mod/quiz/lib.php
?

I thought that the qtype->delete_states function could be called at other times than when the attempt was deleted, I.e. at intermediary points to clear out old states. Looking at the code in Moodle-1.8.3 and Moodle-1.9-latest shows that it is only called when the attempt is deleted.

Maybe it'd be clearer if the function was called something like 'delete_attempt_and_states' or something like that. Maybe I should have paid more attention to that originally.

leif
In reply to Leif Johnson

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Just deleting states without deleting the corresponding attempts would be a mistake. It would leave broken attempts in your database. qtype->delete_states is really an inner working of the question engine - a way for the question engine to communicate with the question types to let them do type-specific cleanup.

Why are you calling it?

quiz_file_area_name should probably be renamed question_file_area_name, and should probably be in questionlib.php. Anyway, this function must have existed once, I'll have to try to find it somewhere in CVS history.
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Doh! of course, that is not a core function, it is part of the same plugin: http://cvs.moodle.org/contrib/plugins/question/type/fileresponse/locallib.php?view=markup. Mystery solved.
In reply to Tim Hunt

Re: per student generated data and question states/attempts

by Leif Johnson -
I'm not calling qtype->delete_states, I'm implementing it for my question type. I just had the wrong understanding of when it could be called.
In reply to Leif Johnson

Re: per student generated data and question states/attempts

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Ah, fine, that makes sense.