-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
answer hints in multiple choice #964
Comments
There are several things that are contributing to your experience. First, by default, AnswerHints only checks answers when they match the type of the correct answer. In your case, since that is 3, it only checks those hints that are numbers, so the first two checks are skipped regardless of the student answer. But again by default, AnswerHints also doesn't check answers when the student answer is marked as correct, so it never checks when the student answer is 3. That is why you never get an answer hint in this case. You would need to use [_]{$mc->cmp->withPostFilter(AnswerHints(
'1.5' => ["You chose 1.5", checkTypes => 0],
'2 ' => ["You chose 2 with a space", checkTypes => 0]
3 => ["You chose 3", checkCorrect => 1]
))} in order to get the answers hints to work. On the other hand, if you used $mc = DropDown(['1.5', '2 ', '3'], 2); so that the correct answer is a string rather than a number, then you only need to do [_]{$mc->cmp->withPostFilter(AnswerHints(
'1.5' => "You chose 1.5",
'2 ' => "You chose 2 with a space",
3 => ["You chose 3", checkCorrect => 1]
))} |
Did that work for you in 2.18? Neither suggestion works for me in 2.18 or develop. (Note there is a comma missing in your first suggestion, but I mean after adding that.) What is the "type" in this situation anyway? Is the |
I could has sworn that I tested it properly, but can't reproduce it today, so obviously did something wrong. So I dug a little deeper and think I have found the real culprit. It is still a type issue, but not the one I thought.
Both the correct and student answers are made into MathObjects, yes. The The problem is actually with the test answers in the pg/macros/answers/answerHints.pl Line 169 in daff8af
turns it into a MathObject. The problem is that it doesn't take the context into account. So line 169 should be replaced by $wrong = main::Compute($wrong) unless Value::isValue($wrong); or more efficiently, by unless (Value::isValue($wrong)) {
$wrong = main::Formula($wrong);
$wrong = $wrong->{tree}->Compute if $wrong->{tree}{canCompute};
} which is the heart of what When I was looking into this, I also noticed that the pg/macros/answers/answerHints.pl Line 174 in daff8af
should have a || !AnswerHints::Compare($correct, $wrong, $ans) The check was supposed to be "if the score is less than 1 or checkCorrect is set, or the test answer doesn't equal the correct answer, then test the student answer", but without the The So I would suggest the following changes might be in order: diff --git a/macros/answers/answerHints.pl b/macros/answers/answerHints.pl
index 2df9a6ab..1082922e 100644
--- a/macros/answers/answerHints.pl
+++ b/macros/answers/answerHints.pl
@@ -144,13 +144,14 @@ sub AnswerHints {
cmp_options => [],
@options,
);
- next if $options{checkTypes} && $correct->type ne $student->type;
next if !$options{processPreview} && $ans->{isPreview};
$wrongList = [$wrongList] unless ref($wrongList) eq 'ARRAY';
foreach my $wrong (@{$wrongList}) {
if (ref($wrong) eq 'CODE') {
- if (($ans->{score} < 1 || $options{checkCorrect})
+ if (
+ (!$options{checkTypes} || $correct->type eq $student->type)
+ && ($ans->{score} < 1 || $options{checkCorrect})
&& ($ans->{ans_message} eq "" || $options{replaceMessage}))
{
# Make the call to run the function inside an eval to trap errors
@@ -166,16 +167,14 @@ sub AnswerHints {
}
}
} else {
- $wrong = Value::makeValue($wrong);
+ unless (Value::isValue($wrong)) {
+ $wrong = main::Formula($wrong);
+ $wrong = $wrong->{tree}->Compute if $wrong->{tree}{canCompute};
+ }
if (
- (
- $ans->{score} < 1
- || $options{checkCorrect}
- || AnswerHints::Compare($correct, $wrong, $ans)
- )
- && ($ans->{ans_message} eq "" || $options{replaceMessage})
+ ($ans->{ans_message} eq "" || $options{replaceMessage})
&& AnswerHints::Compare($wrong, $student, $ans, @{ $options{cmp_options} })
- )
+ )
{
$ans->{ans_message} = $ans->{error_message} = $message;
$ans->{score} = $options{score} if defined $options{score};
@@ -197,9 +196,8 @@ package AnswerHints;
# and returns true if the two values match and false otherwise.
#
sub Compare {
- my $self = shift;
- my $other = shift;
- my $ans = shift;
+ my ($self, $other, $ans) = @_;
+ return 0 unless $self->typeMatch($other); # make sure these can be compared
$ans = bless { %{$ans}, @_ }, ref($ans); # make a copy
$ans->{typeError} = 0;
$ans->{ans_message} = $ans->{error_message} = ""; This removes the I don't think this will have adverse effects on existing problems, since the |
Thanks @dpvc, this all makes sense to me. I have your diff applied in a branch and it works, both for my MWE posted here, and in testing the However there is still something wrong. I mentioned in the OP that the RadioButtons and CheckboxList variants of the MWE also fail, but in a slightly different way. They still fail to show the answer hints, even after this change. Setting Here are MWE for each:
With CheckboxList, I'm not actually sure what I should propose for alternative answers. Are they arrays? Concatenation of several answers? Should they be using the lablels/values, not the option text itself? I think these may be questions for @drgrice1 .
|
For both the RadioButtons and CheckboxList objects, the actual answers used internally are It turns out that RadioButtons has a method to go from a button number to the associated label, but not the other way around. But you could use something like $mc = CheckboxList(['1.5', '2 ',3], [2]); # correct answer is 3
sub answerButton {
my $value = shift;
for my $i (0..$rb->{n}-1) {
return $rb->{values}[$i] if $rb->{orderedChoices}[$i] eq $value;
}
}
BEGIN_PGML
[_]{$mc->cmp->withPostFilter(AnswerHints(
answerButton('1.5') => "You chose 1.5",
answerButton('2 ') => "You chose 2 with a space",
answerButton(3) => "You chose 3"
))}
END_PGML The |
PS, The same function should work for both RadioButtons and CheckboxList. |
Thanks @dpvc. I'll open the PR with your other edits. My testing was that it worked as given (except for the
It sounds right to me to not have the |
The line that needed the |
Don't forget about the Line 276 in daff8af
to be sub address { Scalar::Util::refaddr(shift) } and then change to if ($self->address != $ans->{correct_value}->address) {
$ans->{correct_ans} = $self->string;
$ans->{correct_value} = $self;
$ans->{correct_formula} = Value->Package("Formula")->new($self);
}
if ($other->address != $ans->{student_value}->address) {
$ans->{student_ans} = $other->string;
$ans->{student_value} = $other;
$ans->{student_formula} = Value->Package("Formula")->new($other);
} to get those checks to work properly. |
This is resolved, although we are not entirely sure about answer hints with RadioButtons and CheckboxList. But either that's all OK or new issues can be opened. Closing. |
@Alex-Jordan: You asked about using answer hints with the parserCheckboxList.pl macro. Here is an example of doing so using the new values option: DOCUMENT();
loadMacros(qw(PGstandard.pl PGML.pl answerHints.pl parserCheckboxList.pl));
$mc = CheckboxList([ '1.5', '2 ', 3 ], [2], values => [ '1.5', '2 ', 3 ]); # correct answer is 3
BEGIN_PGML
[_]{
$mc->cmp->withPostFilter(AnswerHints(
'1.5' => 'You chose 1.5',
'2 ' => 'You chose 2 with a space',
3 => 'You chose 3',
List('1.5', 3) => 'You chose 1.5 and 3',
List('1.5', '2 ') => 'You chose 1.5 and 2 with a space', # does not work (and checkTypes => 0 doesn't help)
sub { List('1.5', '2 ') == $_[1] } => 'You chose 1.5 and 2 with a space alt' # this does
))
}
END_PGML
ENDDOCUMENT(); When the |
By the way, if you use the values option with |
Just to clarify, all of that testing was done with #974, and much of it does not work without that pull request. |
fix bugs with answerHints from issue #964
In the MWE below, there a dropdown question. Each answer looks like a number to the student, but one is actually a string because of a space character. It is coded so that each answer should invoke a feedback message from AnswerHints. But only the one answer that is not actually a number gets the feedback message to show. (Same behavior in 2.18 and develop.)
I additionally tried the following, but only tried it in develop:
The text was updated successfully, but these errors were encountered: