WeBWorK Problems

Compound problems with moodle question type

Compound problems with moodle question type

by Angel Gavalda -
Number of replies: 10
Hi all,

I'm using Webwork as a question type within moodle.

I need to do a problem divided in different parts. The students can't read the next part if they have not answered the current one. All the parts are using some random numbers so is needed to keep those numbers in memory.

Reading the webwork documentation I have found out how to do it: using CompoundProblem. I've used it in the main webwork framework and it's working properly but when I use it with the moodle integration I can only see the first part, the submit button doesn't show the next part.

Somebody knows where is the problem or how to fix it in order to use it with Moodle?

Thanks a lot
In reply to Angel Gavalda

Re: Compound problems with moodle question type

by Michael Gage -
Hi Angel,

The "bridge2" connection between moodle and webwork on a question by question basis is still somewhat incomplete so I'm not surprised that there are some features that aren't working The connection between moodle and webwork at the set level (bridge1) has now been used in production in a limited number of sites and is in pretty good shape (although it could still use more documentation) but bridge2 is still in beta testing at best.

My suggestion is that you try to implement the multipart aspect on the Moodle side (this is part of the reason for bridge2 exisiting -- is to take advantage of some of the features in the question type that are not mathematics specific so reproducing them in WeBWorK is extra work). This means that the moodle side would store the seed and just ask successive questions of WeBWorK using that same seed.

Let me know whether you think this would work. The bridge2 interface clearly needs work (and for that matter the Compound/Sequential problem capabilities in WeBWorK also needs work) and I'm interested in working on it, but it is a long term not short term project.

Hope this helps.

Take care,

Mike

In reply to Michael Gage

Re: Compound problems with moodle question type

by Angel Gavalda -
Hi Mike,

Thanks for your prompt reply :-)

I was thinking in using a 'custom' page break in perl to separate the parts then in the moodle side somehow look for this page break and split the question. All of this... theorically. Do you think this is any good?

Thanks again
In reply to Angel Gavalda

Re: Compound problems with moodle question type

by Paul Pearson -
Dear Angel,

The issue probably is the WebWork and Moodle link. However, I'll point out one obvious caveat of compound problems and offer an alternative suggestion (conditional questions).

First the obvious caveat: For some reason, in order to advance from one part to the next in a webwork compound problem you need to submit the correct answer twice. The first time you submit it and get it correct, a new checkbox will appear near the bottom of the page that says "Go on to next part". Select that checkbox and click submit again.

Second, as an alternative to compound problems, you may also want to look into conditional questions. The following example of a conditional question comes from

/Library/Rochester/setMAAtutorial/conditionalquestionexample.pg



##DESCRIPTION
##KEYWORDS('sample')
## Tagged by jjh2b

## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('MAA Tutorial')
## Date('8/30/07')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')

DOCUMENT();
loadMacros(
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);
TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD, $BR,$BR);
$showPartialCorrectAnswers = 1;

$a1 = random(3,25,1);
$b1 = random(2,27,1);
$x1 = random(-11,11,1);
$a2 = $a1+5;

BEGIN_TEXT
If \( f(x) = $a1 x + $b1 \), find \( f'( $x1 ) \).
$BR $BR \{NAMED_ANS_RULE('first_answer',10) \}
$BR
END_TEXT



$ans_eval1 = num_cmp($a1);
NAMED_ANS(first_answer => $ans_eval1);

# Using named answers allows for more control. Any unique label can be
# used for an answer.
# (see http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/managinganswers.html
# for more details on answer evaluator formats and on naming answers
# so that you can refer to them later. Look also at the pod documentation in
# PG.pl and PGbasicmacros.pl which you can also reach at
# http://webwork.math.rochester.edu/docs/techdescription/pglanguage/index.html)

# Check to see that the first answer was answered correctly. If it was then we
# will ask further questions.
$first_Answer = $inputs_ref->{first_answer}; # We need to know what the answer
# was named.
$rh_ans_hash = $ans_eval1->evaluate($first_Answer);

# warn pretty_print($rh_ans_hash); # this is useful technique for finding errors.
# When uncommented it prints out the contents of
# the ans_hash for debugging

# The output of each answer evaluator consists of a single %ans_hash with (at
# least) these entries:
# $ans_hash{score} -- a number between 0 and 1
# $ans_hash{correct_ans} -- The correct answer, as supplied by the instructor
# $ans_hash{student_ans} -- This is the student's answer
# $ans_hash{ans_message} -- Any error message, or hint provided by
# the answer evaluator.
# $ans_hash{type} -- A string indicating the type of answer evaluator.
# -- Some examples:
# 'number_with_units'
# 'function'
# 'frac_number'
# 'arith_number'
# For more details see
# http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/answerhashdataype.html

# If they get the first answer right, then we'll ask a second part to the
# question ...
if (1 == $rh_ans_hash->{score} ) {

# WATCH OUT!!: BEGIN_TEXT and END_TEXT have to be on lines by
# themselves and left justified!!! This means you can't indent
# this section as you might want to. The placement of BEGIN_TEXT
# and END_TEXT is one of the very few formatting requirements in
# the PG language.

BEGIN_TEXT
$PAR Right! Now
try the second part of the problem: $PAR $HR
If \( f(x) = $a2 x + \{$b1+5\} \), find \( f'( x) \).
$BR $BR \{ NAMED_ANS_RULE('SecondAnSwEr',10) \}
$BR
END_TEXT

$ans_eval2 = num_cmp($a2);

NAMED_ANS(SecondAnSwEr => $ans_eval2);

}
ENDDOCUMENT();




In reply to Paul Pearson

Re: Compound problems with moodle question type

by Angel Gavalda -
Hi Paul,

About the compound problem I have clicked submit button several times (with the checkbox selected) but nothing happens.

Thanks for your information about 'conditional questions'. I've tried the example but it doesn't work. It seems moodle doesn't like the 'NAMED_ANS' or 'NAMED_ANS_RULE' fields.

I've written a simple example, but it is always showing the answer as incorrect.

Thanks

DOCUMENT();
loadMacros(
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);
TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD, $BR,$BR);
$showPartialCorrectAnswers = 1;

$a1 = 10;


BEGIN_TEXT
Write $a1
$BR $BR \{NAMED_ANS_RULE('first_answer',10) \}
$BR
END_TEXT

$ans_eval1 = num_cmp($a1);
NAMED_ANS(first_answer => $ans_eval1);


ENDDOCUMENT();
In reply to Angel Gavalda

Re: Compound problems with moodle question type

by Michael Gage -
That sounds like a good idea for now. If it works well we can bake it into the moodle/webwork code so that it is easier to set up. I'm working on a rewrite of the basic underpinnings of webwork (originally written more than 10 years ago) which will take a while to finish -- but it should allow us to customize an output mode specifically for moodle. This should make the bridge2 more robust.

The current version of bridge2 was written under the constraint that nothing was changed on the webwork side so some compromises had to be made. By making some additions to the webwork side I think we can make this connection much stronger.

In reply to Angel Gavalda

Re: Compound problems with moodle question type

by Michael Gage -
That sounds like a good idea for now. If it works well we can bake it into the moodle/webwork code so that it is easier to set up. I'm working on a rewrite of the basic underpinnings of webwork (originally written more than 10 years ago) which will take a while to finish -- but it should allow us to customize an output mode specifically for moodle. This should make the bridge2 more robust.

The current version of bridge2 was written under the constraint that nothing was changed on the webwork side so some compromises had to be made. By making some additions to the webwork side I think we can make this connection much stronger.

In reply to Michael Gage

Re: Compound problems with moodle question type

by Angel Gavalda -
Hi Mike,

I think moodle doesn't refresh the perl code once it has shown it (that's why in compound problems it always shows the first part), I've tested an example to see if the 'score' changes when you submit the correct answer and it's always printing score 0.

Here the example:

$a1 = 10;


BEGIN_TEXT
Write $a1
$BR $BR \{ans_rule(10) \}
$BR
END_TEXT

$ans_eval1 = num_cmp($a1);
$score = $ans_eval1->evaluate()->{score};
BEGIN_TEXT
$score
END_TEXT

ANS($ans_eval1);


I attached the screenshot once I have submitted the correct answer.

Next week I will try the solution about the page break and let you know about it.

Thanks to all,

Angel
Attachment screenshot14.png
In reply to Angel Gavalda

Re: Compound problems with moodle question type

by Michael Gage -
I believe you are correct. I know that Matt Leventi who wrote "bridge2" implemented a lot of caching for speed. I will be attending the annual joint math meetings this next week but in about two weeks, after I have the semester's classes started, I'll have some time to look more closely at this.

I'm glad you are interested in working on it.

--Mike
In reply to Michael Gage

Re: Compound problems with moodle question type

by Kenneth Appel -
Mike, Angel, Paul,
I would appreciate being informed of everything that is being done with bridge 2. We, at University of New Hampshire, are building an adaptive WeBWorK system for middle school. Initially, we had been working with Matt Leventi to use Moodle to provide parts of the adaptive component that are not available in WeBWorK itself. When
Matt left we decided to make sure that we built adequate
problem libraries so that when bridge 2 began to move again we would be ready to take full advantage of it. Now, it seems that you are making it move and we bless you for that and want to do all we can to cooperate as well as take advantage of your progress.
Ken Appel
In reply to Kenneth Appel

Re: Compound problems with moodle question type

by Angel Gavalda -
Hi all,
Before starting typing code I would like to ask you where I can find the documentation regarding the tables of the database and how the 'answer button' works in webwork. Knowing these documents maybe I could figure out why it is not working with moodle and find a better solution to my problem.

Thanks a lot,
Angel