Forum archive 2000-2006

Michal Charemza - Trouble with scores from MultiPart

Michal Charemza - Trouble with scores from MultiPart

by Arnold Pizer -
Number of replies: 0
inactiveTopicTrouble with scores from MultiPart topic started 8/26/2006; 1:39:34 PM
last post 8/30/2006; 3:57:45 AM
userMichal Charemza - Trouble with scores from MultiPart  blueArrow
8/26/2006; 1:39:34 PM (reads: 272, responses: 5)
Hi,

I'm having trouble getting the scores working with a MultiPart question. Below is the code that I think should mark every question out of 6 correct (yes... pointless for the time being).

$mp = MultiPart($pfbypx_correct, $pfbypy_correct, $f_evalatx0y0_correct, $pfbypx_evalatx0y0_correct, $pfbypy_evalatx0y0_correct, $f_approxAtxy_correct)->with( singleResult => 0, checker => sub { my ($correct, $student, $self) = @_; my ($pfbypx_stud, $pfbypy_stud, $f_evalatx0y0_stud, $pfbypx_evalatx0y0_stud, $pfbypy_evalatx0y0_stud, $pfbypy_evalatx0y0_correct, $f_approxAtxy_correct) = @{$student}; @thescores = (1,1,1,1,1,1);

return @thescores; }, );

When running the problem, they all do get marked correct. However an error message appears when marking the questions:

Error in grading this problem the total 36 is larger than 6.

If I set

@thescores = (1,1);

It then returns the error

Error in grading this problem the total 12 is larger than 6.

Thus it seems to be doing something 6 times for every entry in the array.

Does anyone know what I am doing wrong?

Thanks,

Michal Charemza.

<| Post or View Comments |>


userDavide P. Cervone - Re: Trouble with scores from MultiPart  blueArrow
8/26/2006; 2:20:12 PM (reads: 308, responses: 0)
Your checker needs to return a REFERENCE to an array, not an actual array. Try using
  $mp = MultiPart($pfbypx_correct, $pfbypy_correct, $f_evalatx0y0_correct,
$pfbypx_evalatx0y0_correct, $pfbypy_evalatx0y0_correct,
$f_approxAtxy_correct)->with(
singleResult => 0,
checker => sub {
my ($correct, $student, $self) = @_;
my ($pfbypx_stud, $pfbypy_stud, $f_evalatx0y0_stud,
$pfbypx_evalatx0y0_stud, $pfbypy_evalatx0y0_stud,
$pfbypy_evalatx0y0_correct, $f_approxAtxy_correct) = @{$student};
my $scores = [1,1,1,1,1,1];
...
return $scores;
},
);

You access the various scores as $scores->[0], $scores->[1] and so on.

If you really want to use an array rather than an array reference, use

       my @scores = (1,1,1,1,1,1);
...
return ~~@scores;
which will return a reference to the array rather than the array itself. (Note that ~~ is not standard Perl, for which it would be a backslash, but because PG doubles all the backslashes in the file before processing it, you need to use this instead. If you ever put this into a .pl file rather than a .pg file, you'd need to use \@scores not ~~@scores.)

Davide

<| Post or View Comments |>


userMichal Charemza - Re: Trouble with scores from MultiPart  blueArrow
8/29/2006; 6:27:43 AM (reads: 295, responses: 1)
> Your checker needs to return a REFERENCE to an array, not an > actual array.

Thanks Davide, this works now.

<| Post or View Comments |>


userDavide P. Cervone - Re: Trouble with scores from MultiPart  blueArrow
8/29/2006; 6:51:49 AM (reads: 338, responses: 0)
FYI, what I think was happening before is that when you passed the array, it was being interpreted in scalar context, rather than array context, so it produced a scalar value equal to its length (that's how Perl interprets arrays as scalars). So it thought the score for the problem was 6 (the length of your array), and since MultiPart thought this was a single number, it was applied to each of the 6 answers, giving a total of 36.

parserMultiPart.pl could probably be modified to use array context and convert the result to a reference if it gets one.

Davide

<| Post or View Comments |>


userDavide P. Cervone - Re: Trouble with scores from MultiPart  blueArrow
8/29/2006; 8:27:51 AM (reads: 302, responses: 1)
OK, I made the change to parserMultiPart.pl, but it also required a change in pg/lib/Value/AnswerCheckers.pl, so you would need to update both files if you want to return actual arrays rather than array references.

Davide

<| Post or View Comments |>


userMichal Charemza - Re: Trouble with scores from MultiPart  blueArrow
8/30/2006; 3:57:45 AM (reads: 337, responses: 0)
Thank you, this is great,

Michal.

<| Post or View Comments |>