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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 01 Apr 2003 05:21:48 -0000


This is a MIME encoded message

--albertel1049174508
Content-Type: text/plain

albertel		Tue Apr  1 00:21:48 2003 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - you really start to hate something the forth time you have to implement it
  
  
--albertel1049174508
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20030401002148.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.81 loncom/homework/grades.pm:1.82
--- loncom/homework/grades.pm:1.81	Fri Mar 28 18:44:31 2003
+++ loncom/homework/grades.pm	Tue Apr  1 00:21:48 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.81 2003/03/28 23:44:31 albertel Exp $
+# $Id: grades.pm,v 1.82 2003/04/01 05:21:48 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2819,6 +2819,19 @@
     return $result;
 }
 
+sub scantron_scantab {
+    my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
+    my $result='<select name="scantron_format">'."\n";
+    foreach my $line (<$fh>) {
+	my ($name,$descrip)=split(/:/,$line);
+	if ($name =~ /^\#/) { next; }
+	$result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
+    }
+    $result.='</select>'."\n";
+
+    return $result;
+}
+
 sub scantron_selectphase {
     my ($r) = @_;
     my ($symb,$url)=&get_symb_and_url($r);
@@ -2827,10 +2840,11 @@
     my $default_form_data=&defaultFormData($symb,$url);
     my $grading_menu_button=&show_grading_menu_form($symb,$url);
     my $file_selector=&scantron_uploads();
+    my $format_selector=&scantron_scantab();
     my $result;
     $result.= <<SCANTRONFORM;
-<form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
-  <input type="hidden" name="command" value="scantron_configphase" />
+<form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantro_process">
+  <input type="hidden" name="command" value="scantron_process" />
   $default_form_data
   <table width="100%" border="0">
     <tr>
@@ -2851,6 +2865,11 @@
 		Filename of scoring office file: $file_selector
 	    </td>
           </tr>
+          <tr bgcolor="#ffffe6">
+            <td>
+              Format of data file: $format_selector
+	    </td>
+          </tr>
         </table>
       </td>
     </tr>
@@ -2863,66 +2882,136 @@
     return $result;
 }
 
-sub scantron_configphase {
+sub get_scantron_config {
+    my ($which) = @_;
+    my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
+    my %config;
+    foreach my $line (<$fh>) {
+	my ($name,$descrip)=split(/:/,$line);
+	if ($name ne $which ) { next; }
+	chomp($line);
+	my @config=split(/:/,$line);
+	$config{'name'}=$config[0];
+	$config{'description'}=$config[1];
+	$config{'CODElocation'}=$config[2];
+	$config{'CODEstart'}=$config[3];
+	$config{'CODElength'}=$config[4];
+	$config{'IDstart'}=$config[5];
+	$config{'IDlength'}=$config[6];
+	$config{'Qstart'}=$config[7];
+	$config{'Qlength'}=$config[8];
+	$config{'Qoff'}=$config[9];
+	$config{'Qon'}=$config[10];
+	last;
+    }
+    return %config;
+}
+
+sub username_to_idmap {
+    my ($classlist)= @_;
+    my %idmap;
+    foreach my $student (keys(%$classlist)) {
+	$idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
+	    $student;
+    }
+    return %idmap;
+}
+
+sub scantron_parse_scanline {
+    my ($line,$scantron_config)=@_;
+    my %record;
+    my $questions=substr($line,$$scantron_config{'Qstart'}-1);
+    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'});
+	} else {
+	    #FIXME interpret first N questions
+	}
+    }
+    $record{'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'})='';
+	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 />');
+	}
+	if (length($array[0]) eq $$scantron_config{'Qlength'}) {
+	    $record{"$questnum.answer"}='';
+	} else {
+	    $record{"$questnum.answer"}=$alphabet[length($array[0])];
+	}
+    }
+    $record{'maxquest'}=$questnum;
+    $Apache::lonxml::debug=1;
+    &Apache::lonhomework::showhash(%record);
+    $Apache::lonxml::debug=0;
+    return %record;
+}
+
+sub scantron_add_delay {
+}
+
+sub scantron_find_student {
+}
+
+sub scantron_process_students {
     my ($r) = @_;
     my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
-    my $result;
     my ($symb,$url)=&get_symb_and_url($r);
     if (!$symb) {return '';}
     my $default_form_data=&defaultFormData($symb,$url);
-    my $grading_menu_button=&show_grading_menu_form($symb,$url);
-    my $file_selector;
-    $result.= <<SCANTRONFORM;
+
+    my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
+    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 $result= <<SCANTRONFORM;
 <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
   <input type="hidden" name="command" value="scantron_configphase" />
   $default_form_data
-  <table width="100%" border="0">
-    <tr>
-      <td bgcolor="#777777">
-        <table width="100%" border="0">
-          <tr bgcolor="#e6ffff">
-            <td>
-              &nbsp;<b>Select a format for the data file.</b>
-            </td>
-          </tr>
-          <tr bgcolor="#ffffe6">
-            <td>
-               Format of data file:
-	    </td>
-          </tr>
-          <tr bgcolor="#ffffe6">
-            <td>
-		Filename of scoring office file: $file_selector
-	    </td>
-          </tr>
-        </table>
-      </td>
-    </tr>
-  </table>
-  <input type="submit" value="Submit" />
-</form>
-$grading_menu_button
 SCANTRONFORM
-    #FIXME Needs to present some lines from the file and allow the instructor to specify which columns represent what data, possibly have some nice defaults setup, probably should do a pass through all problems for a student to get an idea of how many questions there are, and homw many lines we'll have,
-    return $result;
-}
+    $r->print($result);
 
-sub scantron_process_students {
+    my @delayqueue;
+
+    foreach my $line (<$scanlines>) {
+	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');
+	}
+	($uname,$udom)=split(/:/,$uname);
+	#FIXME
+	#get iterator for $sequence
+	#foreach question 'submit' the students answer to the server
+	#   through grade target {
+	#   generate data to pass back that includes grade recevied
+	#}
+    }
+    foreach my $delay (@delayqueue) {
+	#FIXME
+	#print out each delayed student with interface to select how
+	#  to repair student provided info
+	#Expected errors include
+	#  1 bad/no stuid/username
+	#  2 invalid bubblings
+	
+    }
     #FIXME
-    #   loop through students, {
-    #      Check if studnet info valid, if not add line to delay queue
-    #      foreach question 'submit' the students answer to the server
-    #             through grade target {
-    #         generate data to pass back that includes grade recevied
-    #      }
-    #   }
-    #   loop through delay queue {
-    #      print out each delayed student with interface to select how
-    #          to repair student provided info
-    #       Expected errors include
-    #           1 bad/no stuid/username
-    #           2 invalid bubblings
-    #   }
     # if delay queue exists 2 submits one to process delayed students one
     #     to ignore delayed students, possibly saving the delay queue for later
 
@@ -3275,8 +3364,8 @@
 	    }
 	} elsif ($command eq 'scantron_selectphase') {
 	    $request->print(&scantron_selectphase($request));
-	} elsif ($command eq 'scantron_configphase') {
-	    $request->print(&scantron_configphase($request));
+	} elsif ($command eq 'scantron_process') {
+	    $request->print(&scantron_process_students($request));
 	} else {
 	    $request->print("Unknown action: $command:");
 	}

--albertel1049174508--