How to get the number of questions attempted by a student in moodle quiz

How to get the number of questions attempted by a student in moodle quiz

על ידי Dharani Kumar M בתאריך
מספר תגובות: 5

Hi,

I want to get the number of questions attempted by a student in a moodle quiz. Lets assume that a quiz contains 20 questions and the student answers only 10 questions, I need to get the count as 10 since the number of questions for which the student has answered is 10.

Thanks,

Dharani Kumar

ממוצע דרוגים: -
בתגובה ל: Dharani Kumar M

Re: How to get the number of questions attempted by a student in moodle quiz

על ידי Tim Hunt בתאריך
תמונה של Core developers תמונה של Documentation writers תמונה של Particularly helpful Moodlers תמונה של Peer reviewers תמונה של Plugin developers

Are you trying to do this using the Moodle interface, or by writing PHP code?

בתגובה ל: Tim Hunt

Re: How to get the number of questions attempted by a student in moodle quiz

על ידי Dharani Kumar M בתאריך

Hi Tim,

I am trying to do this by writing PHP code. My intention is to calculate the accuracy of the quiz where the accuracy is nothing but no.of correct answers given by the student divided by the number of questions attempted by the student.

Is there any way to get this result directly by moodle interface?

 

Thanks,

Dharani Kumar

בתגובה ל: Dharani Kumar M

Re: How to get the number of questions attempted by a student in moodle quiz

על ידי Tim Hunt בתאריך
תמונה של Core developers תמונה של Documentation writers תמונה של Particularly helpful Moodlers תמונה של Peer reviewers תמונה של Plugin developers

Well, you can see which questions have been answered in the quiz reports, but you cannot easily get the number through the UI.

You can get this in PHP or SQL code. It is easier for me to explain in terms of SQL code. Start from this query: http://docs.moodle.org/dev/Overview_of_the_Moodle_question_engine#Detailed_data_about_an_attempt. You don't need it all, so you will be able to simplify once everything is working. You need to look at qas.state, and count the number of questions in each state.

In PHP code, it looks roughly like this. Assuming you have a $quba object: (See http://docs.moodle.org/dev/Using_the_question_engine_from_module if you need help with what that means)

 

$answered = 0;

foreach ($quba->get_attempt_iterator() as $qa) {

if ($qa->get_state()->is_graded()) {

$answered += 1;

}

}

בתגובה ל: Tim Hunt

Re: How to get the number of questions attempted by a student in moodle quiz

על ידי Dharani Kumar M בתאריך

Thanks for the help Tim. Intially I got the quba object by using question_engine::load_questions_usage_by_activity($qa->uniqueid) and used your code . I could see the number of questions attempted by the user now.

בתגובה ל: Dharani Kumar M

Re: How to get the number of questions attempted by a student in moodle quiz

על ידי Rajakumar Jillella בתאריך

Hi,

I'm also having same issue.

i'm bit confusion on this. Please explain me how to do and in which file we have to write the PHP code for this.?


Thanks in Advance.