## Quiz

I have been given over 100 .csv files, containing thousands of student quiz results from an old install of Moodle.  I have been asked to import these quiz results into a new install of Moodle.

The old Moodle database is not accessible.  My client has a hostile relationship with their former webhost.

I have written a script that queries the database and parses these files into statements like:

"$idstudent got$idquestion (1)right on $idquiz" "$idstudent got $idquestion (0)wrong on$idquiz"

I've done a lot of reading.  It seems that what goes on in the database when a student answers a quiz question is actually quite complex.  Somewhat dauntingly so.  Can anyone help me formulate some queries that will actually translate the above variables into something that can be gracefully written to the database?

I should probably clarify that what I have in the .csv is just a "1" when the question was answered correctly and a "0" when it was not.

The student's grade on this quiz is also their grade on the course.  I need to also ensure that that is being written to the proper field.

I've been playing with some queries, but I'm scared to actually execute them in a real database.  Please help?  Thanks much.

Average of ratings: -

Hi,

Please try at the Quiz forum.

Average of ratings: -

Your deduction is correct. You don't have enough data to reconstruct the quiz attempts.

Would it be good enough to just get the final grade for each quiz into the gradebook? You can add extra columns to the gradebook without creating a Moodle quiz, and then import and export grades in a range of formats including CSV and XML.

Average of ratings: -

>Would it be good enough to just get the final grade for each quiz into the gradebook?

I'm told no.  I don't need to reconstruct the wrong answers.  Just the right ones.  The wrong answers can just default to something random.

Average of ratings: -

Well, wrong answers you can probably leave as blank.

So, you need to write a script that reads your CSV file, and builds quiz attempts.

The code in the quiz that builds quiz attempts is split between startattempt.php and processattempt.php, so you need to copy bits of that.

question/type/multichoice/tests/walkthrough_test.php is also worth a look for how you can simulate a student submitting responses to a multiple-choice question. (You will need to unpick what the helper functions are doing.)

Average of ratings: -