--- loncom/homework/grades.pm 2003/03/28 23:44:31 1.81 +++ loncom/homework/grades.pm 2003/04/01 05:21:48 1.82 @@ -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 @@ sub scantron_uploads { return $result; } +sub scantron_scantab { + my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab'); + my $result=''."\n"; + + return $result; +} + sub scantron_selectphase { my ($r) = @_; my ($symb,$url)=&get_symb_and_url($r); @@ -2827,10 +2840,11 @@ sub scantron_selectphase { 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.= < - +
+ $default_form_data @@ -2851,6 +2865,11 @@ sub scantron_selectphase { Filename of scoring office file: $file_selector + + +
+ Format of data file: $format_selector +
@@ -2863,66 +2882,136 @@ SCANTRONFORM 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("
Wha!!! ".scalar(@array). + '-'.$questions.'-'.$currentquest.'-'.$questnum. + '-'.length($questions). + '-'.$line.'-'.length($line).'-'. + '-'.$data.'-'.length($data).'-'. + '
'); + } + 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.= <new($Apache::lonnet::perlvar{'lonScansDir'}."/$ENV{'form.scantron_selectfile'}"); + my $classlist=&Apache::loncoursedata::get_classlist(); + my %idmap=&username_to_idmap($classlist); + my $result= < $default_form_data - - - - -
- - - - - - - - - - -
-  Select a format for the data file. -
- Format of data file: -
- Filename of scoring office file: $file_selector -
-
- - -$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 @@ sub handler { } } 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:"); }