--- loncom/homework/default_homework.lcpm 2014/06/25 16:50:51 1.169 +++ loncom/homework/default_homework.lcpm 2017/02/07 21:24:29 1.173 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run() # -# $Id: default_homework.lcpm,v 1.169 2014/06/25 16:50:51 raeburn Exp $ +# $Id: default_homework.lcpm,v 1.173 2017/02/07 21:24:29 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -309,10 +309,13 @@ sub caparesponse_check_list { #for numerical problems split off the unit my $part1; my $part2; + my $match_algebra = qr{^(.*[^\s])\s+([^\s]+)$}; + # FIXME: with the above regexp, algebra with spaces will not be evaluated correctly + my $match_numerical_units = qr{^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$}; if ($allowalgebra) { - ($part1,$part2)=($responses->[0][-1]=~ /^(.*[^\s])\s+([^\s]+)$/); + ($part1,$part2) = ($responses->[0][-1] =~ /$match_algebra/); } else { - ($part1,$part2)=($responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/); + ($part1,$part2) = ($responses->[0][-1] =~ /$match_numerical_units/); } if (defined($part1) && defined($part2)) { $responses->[0][-1]=$part1; @@ -327,6 +330,27 @@ sub caparesponse_check_list { } } } + if (scalar(@$responses) > 0 && defined $answerunit) { + # there are several response values, units should be the same for all + $part2 =~ s/^\s+|\s+$//g; + for (my $i=1; $i[$i][-1]; + my ($part1i, $part2i); + if ($allowalgebra) { + ($part1i, $part2i) = ($element =~ /$match_algebra/); + } else { + ($part1i, $part2i) = ($element =~ /$match_numerical_units/); + } + $part2i =~ s/^\s+|\s+$//g; + if (!defined $part2i) { + return 'NO_UNIT'; + } elsif ($part2i ne $part2) { + return ('UNIT_FAIL', "$part2 $part2i"); + } else { + $responses->[$i][-1] = $part1i; + } + } + } } } $unit=~s/\s//; @@ -902,11 +926,19 @@ sub chemparse { my $formula = ''; foreach my $token (@tokens) { if ($token eq '->' ) { - $formula .= '\ensuremath{\rightarrow} '; + if ($external::target eq 'web') { + $formula .= '→ '; + } else { + $formula .= '\ensuremath{\rightarrow} '; + } next; } if ($token eq '<-' ) { - $formula .= '\ensuremath{\leftarrow} '; + if ($external::target eq 'web') { + $formula .= '← '; + } else { + $formula .= '\ensuremath{\leftarrow} '; + } next; } if ($token eq '<=>') { @@ -1228,11 +1260,11 @@ sub sec { } sub submission { - my ($partid,$responseid,$subnumber,$encode,$cleanupnum)=@_; + my ($partid,$responseid,$subnumber,$encode,$cleanupnum,$mapalias)=@_; my $sub=''; if ($subnumber) { $sub=$subnumber.':'; } my $output = - &EXT('user.resource.'.$sub.'resource.'.$partid.'.'.$responseid.'.submission'); + &EXT('user.resource.'.$sub.'resource.'.$partid.'.'.$responseid.'.submission',$mapalias); if (ref($output) eq 'ARRAY') { my @items = @{$output}; if ($encode) { @@ -1458,3 +1490,8 @@ sub proper_path { } } +sub input_id { + my ($part_id, $response_id, $textline_id) = @_; + return 'HWVAL_'.$part_id.'_'.$response_id.'_'.$textline_id; +} +