General developer forum

Writing Quizzes in other programming languages

 
Picture of Charlie Daly
Writing Quizzes in other programming languages
 


Hi All,

I have written a number of quizzes that are generated by a program based in their Moodle user ID. This means that each student receives their own version of a problem. I use it in labs and it encourages student discussion as students show their peers how to go about solving the problem rather than just supplying the answer (which they can't do since each answer is different).

It is hard to describe without an example, and so, an example: I teach an algorithms module and as part of that module, students learn about graphs. Here is an example question on depth first search. You will have to log in to see it, but I can give you a gist of the question without logging in...

Each student is asked to indicate the order in which the nodes of a graph will be visited by depth first search. And each student is given a different graph; here is an example graph: http://toodle.computing.dcu.ie/dyngraph/graph/77_7_3_.3.png

The url indicates that this graph is a static image, but actually it is generated on the fly using a computer program. There are four numbers separated by three underscores. The first number, 77, is a seed. Changing this gives you a different graph. The second number is the number of nodes, third number is the maximum number of outgoing nodes and the final number is a number between 0 and 1 which is the probability that one node will be connected to another (subject to the previous number's constraint).

So, I can now pose a general problem on graphs and each student gets a different version of the problem and it hugely encourages discussion in computer labs. These problems are also automatically marked.

Now for my question. To generate these problems I use Python. I also use Python to mark the problems. Unfortunately, since Moodle doesn't use Python, I use the VPL plugon to allow me to write these problems. On the front end, I have to use javascript to decode the Moodle user ID and course ID. This is obviously not good design.

I want to adapt the Moodle Quiz plugin so that I can easily incorporate python code in the description and the solution of the problem. I know that some plugins already exist, but they look as if they provide far more than I need.

I simply want to supply the quiz with the URL of a Python program which will generate the html text of the problem based on a user ID and course ID and also provide a mark for the student response. I just wanted to know if anyone else has done similar work in the past or if anyone has recommendations on how to proceed.

I really am not a PHP person and find it hard to write code in PHP. Also much of the useful open source software (such as the software to draw graphs) already exists in Python.

Thanks for reading this far and for any suggestions,

Charlie

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Writing Quizzes in other programming languages
 
Average of ratings: -
Picture of Charlie Daly
Re: Writing Quizzes in other programming languages
 


Thank you Tim.

Those plugins look very useful.

 
Average of ratings: -
Picture of Charlie Daly
Re: Writing Quizzes in other programming languages
 


OK, I actually hacked the shortanswer plugin and now I can get the userid, courseid and question name. I was hoping to also get the question category.

The question object does have a category field, but at the moment it is just an number, it doesn't have the actual question category. 

Once I have userid, courseid, question category and question name, I can pass that to a url which will return a question specification or an answer as required.

The following is a section of the output when I use print_object with the question object (note that the category value is not the category):

["shownumcorrect"]=>
bool(false)
["id"]=>
string(1) "3"
["category"]=>
string(1) "9"
["contextid"]=>
string(2) "21"

Thanks.
 
Average of ratings: -
Picture of Charlie Daly
Re: Writing Quizzes in other programming languages
 
I discovered the answer and am documenting it here in case someone else needs it. It seems that the category id is stored in the category field. You can get the category using:


        $cat_id = $this->category;

        $query = $DB->get_record_sql('select name from mdl_question_categories where id="' . $cat_id . '"');

        print($query->name);


 
Average of ratings: -
Picture of Marcus Green
Re: Writing Quizzes in other programming languages
Core developersParticularly helpful MoodlersPlugin developersTesters

Thanks for posting Charlie, that should work but you should consider something like

$DB->get_record('question_categories',['id'=>$cat_id)  

Then it will work if someone has a prefix other than mdl.

See 

https://docs.moodle.org/dev/Data_manipulation_API#Main_info

I suspect most people most of the time leave the default mdl_ but  it is nice to cover unusual situations.




 
Average of ratings: -
Picture of Charlie Daly
Re: Writing Quizzes in other programming languages
 

Thanks Marcus,

It's good to see an elegant approach.

 
Average of ratings: Useful (1)