[LON-CAPA-cvs] cvs: loncom /homework grades.pm radiobuttonresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 04 Apr 2003 23:35:17 -0000


albertel		Fri Apr  4 18:35:17 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm radiobuttonresponse.pm 
  Log:
  - actually submitting scantron results now, I have gottne 1 question for one studnet marked incorrect
  
  - radiobutton now understands a scantron submission,
  - radiobuton increments the counter in end_foild group, that way it can be used to acquire the scantron submissions
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.82 loncom/homework/grades.pm:1.83
--- loncom/homework/grades.pm:1.82	Tue Apr  1 00:21:48 2003
+++ loncom/homework/grades.pm	Fri Apr  4 18:35:17 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.82 2003/04/01 05:21:48 albertel Exp $
+# $Id: grades.pm,v 1.83 2003/04/04 23:35:17 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2924,47 +2924,56 @@
     my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
     if ($$scantron_config{'CODElocation'} ne 0) {
 	if ($$scantron_config{'CODElocation'} < 0) {
-	    $record{'CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
-				   $$scantron_config{'CODElength'});
+	    $record{'scantron.CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
+					    $$scantron_config{'CODElength'});
 	} else {
 	    #FIXME interpret first N questions
 	}
     }
-    $record{'ID'}=substr($data,$$scantron_config{'IDstart'}-1,
-			 $$scantron_config{'IDlength'});
+    $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
+				  $$scantron_config{'IDlength'});
     my @alphabet=('A'..'Z');
     my $questnum=0;
     while ($questions) {
 	$questnum++;
 	my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
 	substr($questions,0,$$scantron_config{'Qlength'})='';
+	if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
 	my (@array)=split(/$$scantron_config{'Qon'}/,$currentquest);
 	if (scalar(@array) gt 2) {
 	    #FIXME do something intelligent with double bubbles
-	    Apache->request->print("<br ><b>Wha!!!</b> ".scalar(@array).
-				   '-'.$questions.'-'.$currentquest.'-'.$questnum.
-				   '-'.length($questions).
-				   '-'.$line.'-'.length($line).'-'.
-				   '-'.$data.'-'.length($data).'-'.
-				   '<br />');
+	    Apache->request->print("<br ><b>Wha!!!</b> <pre>".scalar(@array).
+				   '-'.$currentquest.'-'.$questnum.'</pre><br />');
 	}
 	if (length($array[0]) eq $$scantron_config{'Qlength'}) {
-	    $record{"$questnum.answer"}='';
+	    $record{"scantron.$questnum.answer"}='';
 	} else {
-	    $record{"$questnum.answer"}=$alphabet[length($array[0])];
+	    $record{"scantron.$questnum.answer"}=$alphabet[length($array[0])];
 	}
     }
-    $record{'maxquest'}=$questnum;
-    $Apache::lonxml::debug=1;
-    &Apache::lonhomework::showhash(%record);
-    $Apache::lonxml::debug=0;
-    return %record;
+    $record{'scantron.maxquest'}=$questnum;
+    return \%record;
 }
 
 sub scantron_add_delay {
 }
 
 sub scantron_find_student {
+    my ($scantron_record,$idmap)=@_;
+    my $scanID=$$scantron_record{'scantron.ID'};
+    foreach my $id (keys(%$idmap)) {
+	Apache->request->print('<pre>checking studnet -'.$id.'- againt -'.$scanID.'- </pre>');
+	if (lc($id) eq lc($scanID)) { Apache->request->print('success');return $$idmap{$id}; }
+    }
+    return undef;
+}
+
+sub scantron_filter {
+    my ($curres)=@_;
+    if (ref($curres) && $curres->is_problem() && !$curres->randomout) {
+	return 1;
+    }
+    return 0;
 }
 
 sub scantron_process_students {
@@ -2978,6 +2987,10 @@
     my $scanlines=Apache::File->new($Apache::lonnet::perlvar{'lonScansDir'}."/$ENV{'form.scantron_selectfile'}");
     my $classlist=&Apache::loncoursedata::get_classlist();
     my %idmap=&username_to_idmap($classlist);
+    my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1);
+    my $map=$navmap->getResourceByUrl($sequence);
+    my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
+    $r->print("geto ".scalar(@resources)."<br />");
     my $result= <<SCANTRONFORM;
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
   <input type="hidden" name="command" value="scantron_configphase" />
@@ -2988,13 +3001,37 @@
     my @delayqueue;
 
     foreach my $line (<$scanlines>) {
+	chomp($line);
 	my $scan_record=&scantron_parse_scanline($line,\%scantron_config);
 	my ($uname,$udom);
 	if ($uname=&scantron_find_student($scan_record,\%idmap)) {
 	    &scantron_add_delay(\@delayqueue,$line,
 				'Unable to find a student that matches');
 	}
+	$r->print('<pre>doing studnet'.$uname.'</pre>');
 	($uname,$udom)=split(/:/,$uname);
+	&Apache::lonnet::delenv('form\.counter$'); #') stupid emacs
+	&Apache::lonnet::appenv(%$scan_record);
+    $Apache::lonxml::debug=1;
+    &Apache::lonhomework::showhash(%ENV);
+    $Apache::lonxml::debug=0;
+	
+	foreach my $resource (@resources) {
+	    my $result=&Apache::lonnet::ssi($resource->src(),
+				 ('submitted'     =>'scantron',
+				  'grade_target'  =>'grade',
+				  'grade_username'=>$uname,
+				  'grade_domain'  =>$udom,
+				  'grade_courseid'=>$ENV{'request.course.id'},
+				  'grade_symb'    =>$resource->symb()));
+	    $r->print('<pre>'.
+		      $resource->symb().'-'.
+		      $resource->src().'-'.'</pre>result is'.$result);
+	    last;
+	}
+	&Apache::lonnet::delenv('form\.counter$'); #') stupid emacs
+	&Apache::lonnet::delenv('scantron\.');
+	last;
 	#FIXME
 	#get iterator for $sequence
 	#foreach question 'submit' the students answer to the server
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.64 loncom/homework/radiobuttonresponse.pm:1.65
--- loncom/homework/radiobuttonresponse.pm:1.64	Wed Apr  2 10:09:00 2003
+++ loncom/homework/radiobuttonresponse.pm	Fri Apr  4 18:35:17 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.64 2003/04/02 15:09:00 sakharuk Exp $
+# $Id: radiobuttonresponse.pm,v 1.65 2003/04/04 23:35:17 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -87,7 +87,6 @@
   &Apache::response::setrandomnumber();
   if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
       $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
-      &Apache::lonxml::increment_counter();
   }
   return $result;
 }
@@ -112,7 +111,17 @@
   #keep the random numbers the same must always call this
   my ($answer,@whichfoils)=&whichfoils($max,$randomize);
   if (!defined($ENV{'form.submitted'})) { return; }
-  my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
+  my $response;
+  if ($ENV{'form.submitted'} eq 'scantron') {
+      my %let_to_num=('A'=>0,'B'=>1,'C'=>2,'D'=>3,'E'=>4,'F'=>5,'G'=>6,
+		      'H'=>7,'I'=>8,'J'=>9,'K'=>10,'L'=>11,'M'=>12,'N'=>13,
+		      'O'=>14,'P'=>15,'Q'=>16,'R'=>17,'S'=>18,'T'=>19,'U'=>20,
+		      'V'=>21,'W'=>22,'X'=>23,'Y'=>24,'Z'=>25);
+      $response = $ENV{'scantron.'.$Apache::lonxml::counter.'.answer'};
+      $response = $let_to_num{$response};
+  } else {
+      $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
+  }
   if ( $response !~ /[0-9]+/) { return; }
   my $part=$Apache::inputtags::part;
   my $id = $Apache::inputtags::response['-1'];
@@ -159,6 +168,9 @@
 	&grade_response($max,$randomize);
       }
     }
+  }
+  if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
+      &Apache::lonxml::increment_counter();
   }
   return $result;
 }