Diff for /loncom/homework/matchresponse.pm between versions 1.29 and 1.38

version 1.29, 2003/10/27 20:04:34 version 1.38, 2004/03/15 22:09:52
Line 30  package Apache::matchresponse; Line 30  package Apache::matchresponse;
 use strict;  use strict;
 use HTML::Entities();  use HTML::Entities();
 use Math::Random();  use Math::Random();
 use Apache::optionresponse;  use Apache::optionresponse();
   use Apache::lonlocal;
   
 BEGIN {  BEGIN {
     &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));      &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));
Line 46  sub start_matchresponse { Line 47  sub start_matchresponse {
     push (@Apache::lonxml::namespace,'matchresponse');      push (@Apache::lonxml::namespace,'matchresponse');
     my $id = &Apache::response::start_response($parstack,$safeeval);      my $id = &Apache::response::start_response($parstack,$safeeval);
     %Apache::hint::match=();      %Apache::hint::match=();
       undef(%Apache::response::foilnames);
     if ($target eq 'meta') {      if ($target eq 'meta') {
  $result=&Apache::response::meta_package_write('matchresponse');   $result=&Apache::response::meta_package_write('matchresponse');
     } elsif ($target eq 'edit' ) {      } elsif ($target eq 'edit' ) {
Line 80  sub end_matchresponse { Line 82  sub end_matchresponse {
     pop @Apache::lonxml::namespace;      pop @Apache::lonxml::namespace;
     &Apache::lonxml::deregister('Apache::matchresponse',      &Apache::lonxml::deregister('Apache::matchresponse',
  ('foilgroup','foil','conceptgroup'));   ('foilgroup','foil','conceptgroup'));
       undef(%Apache::response::foilnames);
     return $result;      return $result;
 }  }
   
Line 123  sub end_itemgroup { Line 126  sub end_itemgroup {
  @names=&Apache::response::whichorder($#names+1,$randomize,0,   @names=&Apache::response::whichorder($#names+1,$randomize,0,
  \%Apache::response::itemgroup);   \%Apache::response::itemgroup);
     }      }
       if ($target eq 'analyze') {
    my $partid="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
    push (@{ $Apache::lonhomework::analyze{"$partid.items"} }, @names);
       }
     my %letter_name_map;      my %letter_name_map;
     my %name_letter_map;      my %name_letter_map;
     my @alphabet=('A'..'Z');      my @alphabet=('A'..'Z');
Line 163  sub end_itemgroup { Line 170  sub end_itemgroup {
 sub start_item {  sub start_item {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result='';      my $result='';
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  &Apache::lonxml::startredirection;   &Apache::lonxml::startredirection;
     } elsif ($target eq 'edit') {      } elsif ($target eq 'edit') {
  my $randomize=&Apache::lonxml::get_param('randomize',$parstack,   my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
Line 189  sub end_item { Line 196  sub end_item {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $text ='';      my $text ='';
     my $result = '';      my $result = '';
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  $text=&Apache::lonxml::endredirection;   $text=&Apache::lonxml::endredirection;
     }      }
     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||      if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  $target eq 'edit' || $target eq 'tex') {   $target eq 'edit' || $target eq 'tex' || $target eq 'analyze') {
  my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);   my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  my $location=&Apache::lonxml::get_param('location',$parstack,   my $location=&Apache::lonxml::get_param('location',$parstack,
  $safeeval);   $safeeval);
Line 302  sub grade_response { Line 309  sub grade_response {
     if (!defined($ENV{'form.submitted'})) { return; }      if (!defined($ENV{'form.submitted'})) { return; }
     my %responsehash;      my %responsehash;
     my %grade;      my %grade;
     my ($temp,$right,$wrong,$ignored)=(0,0,0,0);      my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
     my %letter_name_map;      my %letter_name_map;
     if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {      if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
  %letter_name_map=   %letter_name_map=
     %{ $Apache::response::itemgroup{'letter_name_map'} };      %{ $Apache::response::itemgroup{'letter_name_map'} };
     }      }
       my @items;
     foreach my $name (@whichfoils) {      foreach my $name (@whichfoils) {
  my $response = &Apache::response::getresponse($temp);   my $response = &Apache::response::getresponse($temp,'letter');
    push(@items,$response);
  my $responsename = $letter_name_map{$response};   my $responsename = $letter_name_map{$response};
  $responsehash{$name}=$responsename;  
  my $value=$Apache::response::foilgroup{$name.'.value'};   my $value=$Apache::response::foilgroup{$name.'.value'};
  if ( $response =~ /[^\s]/) {   if ( $response =~ /[^\s]/) {
     &Apache::lonxml::debug("submitted a $response for $value<br />\n");      $responsehash{$name}=$responsename;
       &Apache::lonxml::debug("submitted a $response($responsename) for $value<br />\n");
     if ($value eq $responsename) {      if ($value eq $responsename) {
  $grade{$name}='1'; $right++;   $grade{$name}='1'; $right++;
     } else {      } else {
Line 328  sub grade_response { Line 337  sub grade_response {
     my $part=$Apache::inputtags::part;      my $part=$Apache::inputtags::part;
     my $id = $Apache::inputtags::response['-1'];      my $id = $Apache::inputtags::response['-1'];
     my $responsestr=&Apache::lonnet::hash2str(%responsehash);      my $responsestr=&Apache::lonnet::hash2str(%responsehash);
       my $itemstr    =&Apache::lonnet::array2str(@items);
     my $gradestr   =&Apache::lonnet::hash2str(%grade);      my $gradestr   =&Apache::lonnet::hash2str(%grade);
     my %previous =&Apache::response::check_for_previous($responsestr,      my %previous=&Apache::response::check_for_previous($responsestr,$part,$id);
  $part,$id);  
     &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored ");      &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored ");
     my $ad;  
     if ($wrong==0 && $ignored==0) {  
  $ad='EXACT_ANS';  
     } elsif ($wrong==0 && $right==0) {  
  #nothing submitted  
     } else {  
  if ($ignored==0) {  
     $ad='INCORRECT';  
  } else {  
     $ad='MISSING_ANSWER';  
  }  
     }  
     $Apache::lonhomework::results{"resource.$part.$id.submission"}=      $Apache::lonhomework::results{"resource.$part.$id.submission"}=
  $responsestr;   $responsestr;
       $Apache::lonhomework::results{"resource.$part.$id.submissionitems"}=
    $itemstr;
     $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=      $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=
  $gradestr;   $gradestr;
     $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;      if (!$Apache::lonhomework::scantronmode) {
     &Apache::response::handle_previous(\%previous,$ad);   my $ad;
    if ($wrong==0 && $ignored==0) {
       $ad='EXACT_ANS';
    } elsif ($wrong==0 && $right==0) {
       #nothing submitted
    } else {
       if ($ignored==0) {
    $ad='INCORRECT';
       } else {
    $ad='MISSING_ANSWER';
       }
    }
    $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
    &Apache::response::handle_previous(\%previous,$ad);
       } else {
    my $ad;
    if ($wrong==0 && $right==0) {
       #nothing submitted
    } else {
       $ad='ASSIGNED_SCORE';
       $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
    $ad;
       $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
    $right/(scalar(@whichfoils));
       $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
    scalar(@whichfoils);
    }
       }
 }  }
   
 sub itemdisplay {  sub itemdisplay {
Line 396  sub displayfoils { Line 422  sub displayfoils {
  }   }
     } else {      } else {
  my $i = 0;   my $i = 0;
  my $temp=0;   my $temp=1;
  my $id=$Apache::inputtags::response[-1];   my $id=$Apache::inputtags::response[-1];
  my $part=$Apache::inputtags::part;   my $part=$Apache::inputtags::part;
  my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};   my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
Line 457  sub displayfoils { Line 483  sub displayfoils {
     } elsif ($result=&itemdisplay('bottom')) {      } elsif ($result=&itemdisplay('bottom')) {
  $result=$question.$result;   $result=$question.$result;
     } elsif ($result=&itemdisplay('right')) {      } elsif ($result=&itemdisplay('right')) {
  $result='<table><tr><td>'.$question.'</td><td>'.$result.   if ($target ne 'tex') {
     '</td></tr></table>';      $result='<table><tr><td>'.$question.'</td><td>'.$result.
    '</td></tr></table>';
    } else {
       $result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}\end{tabular}';
    }
     } elsif ($result=&itemdisplay('left')) {      } elsif ($result=&itemdisplay('left')) {
  $result='<table><tr><td>'.$result.'</td><td>'.$question.   if ($target ne 'tex') {
     '</td></tr></table>';      $result='<table><tr><td>'.$result.'</td><td>'.$question.
    '</td></tr></table>';
    } else {
       $result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}\end{tabular}';
    }
     }      }
     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';}      if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';}
     return $result;      return $result;
Line 561  sub end_foil { Line 595  sub end_foil {
  my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);   my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
  if ($value ne 'unused') {   if ($value ne 'unused') {
     my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);      my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
     my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);  
     &Apache::lonxml::debug("Got a name of :$name:");      &Apache::lonxml::debug("Got a name of :$name:");
     if (!$name) { $name=$Apache::lonxml::curdepth; }      if (!$name) { $name=$Apache::lonxml::curdepth; }
     &Apache::lonxml::debug("Using a name of :$name:");      &Apache::lonxml::debug("Using a name of :$name:");
       if (defined($Apache::response::foilnames{$name})) {
    &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
       }
       $Apache::response::foilnames{$name}++;
       my $location =&Apache::lonxml::get_param('location',$parstack,
        $safeeval);
     if ( $Apache::matchresponse::conceptgroup      if ( $Apache::matchresponse::conceptgroup
  && !&Apache::response::showallfoils() ) {   && !&Apache::response::showallfoils() ) {
  push @{ $Apache::response::conceptgroup{'names'} }, $name;   push @{ $Apache::response::conceptgroup{'names'} }, $name;

Removed from v.1.29  
changed lines
  Added in v.1.38


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>